#ifndef _COMMON_BINSRCH_TPP_ #define _COMMON_BINSRCH_TPP_ template WORD BinarySearch::searchItem(const T &desiredItem,T &foundItem) { LONG itemIndex; return searchItem(desiredItem,foundItem,itemIndex); } template WORD BinarySearch::searchItem(const T &desiredItem,Block &foundItems) { LONG foundIndex; LONG startIndex; LONG endIndex; T foundItem; foundItems.remove(); if(!searchItem(desiredItem,foundItem,foundIndex))return FALSE; startIndex=endIndex=foundIndex; for(;startIndex>=0&&foundItem==mSortedVector[startIndex];startIndex--); startIndex++; for(;endIndex WORD BinarySearch::searchItem(const T &desiredItem,T &foundItem,LONG &foundIndex) { LONG lowerBound; LONG upperBound; LONG itemIndex; WORD returnCode(FALSE); if(!itemCount())return FALSE; lowerBound=0L; upperBound=mItemCount-1L; while(TRUE) { itemIndex=(lowerBound+upperBound)/2L; if(desiredItem>mSortedVector[itemIndex])lowerBound=itemIndex+1L; else upperBound=itemIndex-1; if(mSortedVector[itemIndex]==desiredItem) { foundItem=mSortedVector[itemIndex]; foundIndex=itemIndex; returnCode=TRUE; break; } if(lowerBound>upperBound)break; } return returnCode; } #endif