template<typename type, class allocator>
int FX::QMemArray< type, allocator >::bsearch ( const type &  val  )  const [inline]

Performs a binary search to find an item (needs a numerically sorted array), returning -1 if not found.

Definition at line 201 of file qmemarray.h.

00202     {   // God damn std::binary_search doesn't return the position :(
00203         int lbound=0, ubound=(int)size()-1, c;
00204         while(lbound<=ubound)
00205         {
00206             c=(lbound+ubound)/2;
00207             const type &cval=at(c);
00208             if(val==cval)
00209                 return c;
00210             else if(val<cval)
00211                 ubound=c-1;
00212             else
00213                 lbound=c+1;
00214         }
00215         return -1;
00216     }


(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:37:41 2009 for TnFOX by doxygen v1.4.7