- T&
- top (vsize i)
- {
- return (*this)[this->size () - i - 1];
- }
- };
-
-#if 0
- template<typename T>
- vsize
- // binary_search (std::vector<T> const &v,
- binary_search (vector<T> const &v,
- T const &key, int (*compare) (T const &, T const &),
- vsize b=0, vsize e=VPOS)
- {
- //(void) compare;
- typename vector<T>::const_iterator i = find (v.iter (b), v.iter (e), key);
- if (i != v.end ())
- return i - v.begin ();
- return VPOS;
- }
-#else // c&p from array.icc; cannot easily use stl_algo:find b.o. compare func.
- template<class T>
- void
- binary_search_bounds (vector<T> const &table,
- T const &key, int (*compare) (T const &, T const &),
- vsize *lo,
- vsize *hi)
- {
- int cmp;
- int result;
-
- /* binary search */
- do
- {
- cmp = (*lo + *hi) / 2;
-
- result = (*compare) (key, table[cmp]);
-
- if (result < 0)
- *hi = cmp;
- else
- *lo = cmp;
- }
- while (*hi - *lo > 1);
- }