2 (c) 1995--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 Distributed under GNU GPL
8 #include "std-vector.hh"
17 functions with loops don't inline
20 template<class T> INLINE void
21 arrcpy (T *dest, T const *src, vsize count)
23 for (vsize i_shadows_local = 0; i_shadows_local < count; i_shadows_local++)
27 urg: wierd egcs-1.1.2-12c (stock LinuxPPC R5) bug on ppc
29 fixed in egcs-1.1.2-12f
30 ftp://dev.linuxppc.org/users/fsirl/R5/RPMS/ppc/
40 template<typename T> INLINE void
41 vector_sort (Array<T> &v, int (*compare) (T const &, T const &),
42 vsize lower=-1, vsize upper=-1)
47 upper = v.size () - 1;
51 v.swap (lower, (lower + upper) / 2);
53 for (vsize i = lower +1; i <= upper; i++)
54 if (compare (v.array_[i], v.array_[lower]) < 0)
57 vector_sort (v, compare, lower, last - 1);
58 vector_sort (v, compare, last + 1, upper);
61 template<class T> INLINE void
65 for (vsize i = 0, j = size_ - 1; i < h; i++, j--)
69 template<class T> INLINE
74 assert (max_ >= size_ && size_ >= 0);
76 assert (max_ >= size_);
82 template<class T> INLINE
84 Array<T>::remove_array ()
93 template<class T> INLINE
94 Array<T>::Array (const_iterator b, const_iterator e)
99 arrcpy (array_, b, n);
104 binary_search_bounds (Array<T> const &table,
105 T const &key, int (*compare) (T const &, T const &),
115 cmp = (*lo + *hi) / 2;
117 result = (*compare) (key, table[cmp]);
124 while (*hi - *lo > 1);
128 lookup with binsearch, return array index.
132 binary_search (Array<T> const &table,
133 T const &key, int (*compare) (T const &, T const &),
140 binary_search_bounds (table, key, compare, &lo, &hi);
142 if (! (*compare) (key, table[lo]))