2 (c) 1995--2003 Han-Wen Nienhuys
4 Distributed under GNU GPL
18 functions with loops don't inline
21 template<class T> INLINE void
22 arrcpy (T*dest, T const* src, int count)
24 for (int i_shadows_local=0; i_shadows_local < count ; i_shadows_local++)
28 urg: wierd egcs-1.1.2-12c (stock LinuxPPC R5) bug on ppc
30 fixed in egcs-1.1.2-12f
31 ftp://dev.linuxppc.org/users/fsirl/R5/RPMS/ppc/
41 template<class T> INLINE void
42 Array<T>::insert (T k, int j)
44 assert (j >=0 && j<= size_);
46 for (int i=size_-1; i > j; i--)
47 array_[i] = array_[i-1];
51 template<class T> INLINE void
52 Array<T>::sort (int (*compare) (T const&,T const&), int lower, int upper)
61 swap (lower, (lower+upper)/2);
63 for (int i= lower +1; i <= upper; i++)
64 if (compare (array_[i], array_[lower]) < 0)
67 sort (compare, lower, last-1);
68 sort (compare, last+1, upper);
71 template<class T> INLINE void
75 for (int i =0,j = size_-1; i < h; i++,j--)
79 template<class T> INLINE
83 assert (max_ >= size_ && size_ >=0);
84 if (max_) assert (array_);
87 template<class T> INLINE
89 Array<T>::remove_array ()
98 template<class T> INLINE
100 Array<T>::slice (int lower, int upper) const
102 assert (lower >= 0 && lower <=upper&& upper <= size_);
106 arrcpy (r.array_, array_ + lower, s);
113 binary_search_bounds (Array<T> const &table,
114 T const &key, int (*compare) (T const&, T const &),
124 cmp = (*lo + *hi) / 2;
126 result = (*compare) (key, table[cmp]);
133 while (*hi - *lo > 1);
138 lookup with binsearch, return array index.
142 binary_search (Array<T> const &table,
143 T const &key, int (*compare) (T const&, T const &),
151 binary_search_bounds (table, key, compare, &lo, &hi);
153 if (! (*compare) (key, table[lo]))
158 return -1; /* not found */