17 inline void swap(
int offset,
int i,
int j) {
18 char tmp[
sizeof(Elem)];
19 register Elem *r = (this->
rep.array+offset);
20 memcpy(tmp, (
char *)&r[i],
sizeof(Elem));
21 memcpy((
char *)&(r[i]), (
char *)&(r[j]),
sizeof(Elem));
22 memcpy((
char *)&r[j], tmp,
sizeof(Elem));
26 inline void siftup(
int offset,
unsigned int i,
unsigned int size) {
27 char tmp[
sizeof(Elem)];
28 register unsigned int j;
29 register Elem *r = (this->
rep.array+offset);
31 while ((j = 2*i+1) <
size) {
37 memcpy(tmp, (
char *)&r[i],
sizeof(Elem));
38 memcpy((
char *)&(r[i]), (
char *)&(r[j]),
sizeof(Elem));
39 memcpy((
char *)&r[j], tmp,
sizeof(Elem));
82 void sort(
int bot,
int top) {
84 if (top > this->
rep.size()) top = this->
rep.size();
88 for ( index =
size/2-1; index > 0; index-- )
89 siftup(bot, index,
size);
92 for ( index =
size; index > 1; index-- ) {
93 siftup(bot, 0, index);
94 swap(bot, 0, index-1);
98 inline void uniq(
void);
109 int top = this->
size();
110 if (this->
size() == 0)
return (-1);
111 while (top - bot > 1) {
112 if ( this->
rep.array[test = (bot+top)/2] < elem )
122 template <
class Elem>
127 while (++oldIndex < this->size()) {
128 if ( ! ( this->rep.array[oldIndex] == this->rep.array[newIndex] ) ) {
129 if (++newIndex != oldIndex)
130 memcpy((
void *)&(this->rep.array[newIndex]),
131 (
void *)&(this->rep.array[oldIndex]),
134 this->rep.array[oldIndex].~Elem();
137 this->rep.arraySize = ++newIndex;
ResizeArrayRaw< Elem > rep
SortableResizeArray(SortableResizeArray< Elem > &ra)
SortableResizeArray< Elem > & operator=(SortableResizeArray< Elem > &sa)
~SortableResizeArray(void)
SortableResizeArray(const SortableResizeArray< Elem > *ra)
SortableResizeArray(const ResizeArray< Elem > *ra)
void sort(int bot, int top)
int bsearch(const Elem &elem) const
SortableResizeArray(Elem **const r, int numElem, int maxElem)
SortableResizeArray(int size)
SortableResizeArray(void)
SortableResizeArray(ResizeArray< Elem > &ra)