17 void Print(
const char* fmt, ...);
23 : items(l.items), extent(l.extent)
26 array =
new(__FILE__,__LINE__) PTR[extent];
28 array =
new PTR[extent];
31 for (
int i = 0; i < extent; i++)
32 array[i] = l.array[i];
50 for (
int i = 0; i < extent; i++)
66 Print(
"Bounds error in List(%08x) T=%s index=%d min=0\n", (
int)
this, T::TYPENAME(), index);
70 else if (index >= items) {
71 Print(
"Bounds error in List(%08x) T=%s index=%d max=%d\n", (
int)
this, T::TYPENAME(), index, items-1);
75 return (index >= 0 && index < items);
86 if (!array || !extent)
106 if (!array || !extent)
125 if (newsize > extent) {
126 extent = 16 * (newsize/16 + 1);
129 T** v =
new(__FILE__,__LINE__) PTR[extent];
131 T** v =
new PTR[extent];
134 for (i = 0; i < items; i++)
137 for (; i < extent; i++)
151 if (items+1 > extent) resize(items+1);
152 array[items++] = (T*)item;
159 if (&list !=
this && list.items > 0) {
160 int need = items + list.items;
161 if (need > extent) resize(need);
163 for (
int i = 0; i < list.items; i++)
164 array[items++] = list.array[i];
173 if (item && index >= 0 && index <= items) {
174 if (items+1 > extent) resize(items+1);
177 for (
int i = items; i > index; i--)
178 array[i] = array[i-1];
180 array[index] = (T*)item;
192 for (i = 0; i < items; i++) {
193 if (*item < *array[i])
206 if (items == 0 || val == 0)
209 for (
int i = 0; i < items; i++) {
210 if (array[i] == val) {
211 return removeIndex(i);
226 T* tmp = array[index];
230 for (
int i = index; i < items-1; i++)
231 array[i] = array[i+1];
246 if (index(val) != -1)
261 for (
int i = 0; i < items; i++) {
262 if (array[i] && ((*array[i])==(*val)))
276 for (
int i = 0; i < items; i++) {
277 if (array[i] && ((*array[i])==(*val)))
291 for (
int i = 0; i < items; i++) {
292 if (array[i] && ((*array[i])==(*val)))
305 if (i >= 0 && i < items && j >= 0 && j < items && i != j) {
324 else if (lo == hi-1) {
325 if (*a[hi] < *a[lo]) {
338 while ((*a[lo] <= *pivot) && lo < hi) lo++;
339 while ((*pivot <= *a[hi]) && lo < hi) hi--;
360 qsort(array, 0, items-1);
369 for (
int s = 0; s < 5; s++) {
370 for (
int i = 0; i < items; i++) {
371 int j = (rand()>>4) % items;
382 if (list && step >= 0 && step < list->items)
383 return list->array[step];
393 if (list && step >= 0 && step < list->items)
394 return list->removeIndex(step--);
404 if (list && step >= -1 && step < list->items-1)
405 return list->array[++step];
413 if (list && step > 0 && step < list->items)
414 return list->array[--step];