5 #ifndef __IRR_ARRAY_H_INCLUDED__
6 #define __IRR_ARRAY_H_INCLUDED__
21 template <
class T,
typename TAlloc = irrAllocator<T> >
29 : data(0), allocated(0), used(0),
38 : data(0), allocated(0), used(0),
67 data = allocator.allocate(new_size);
71 s32 end = used < new_size ? used : new_size;
73 for (
s32 i=0; i<end; ++i)
76 allocator.construct(&data[i], old_data[i]);
80 for (
u32 j=0; j<used; ++j)
81 allocator.destruct(&old_data[j]);
86 allocator.deallocate(old_data);
96 strategy = newStrategy;
130 if (used + 1 > allocated)
142 newAlloc = used + 1 + (allocated < 500 ?
143 (allocated < 5 ? 5 : used) : used >> 2);
154 for (
u32 i=used; i>index; --i)
157 allocator.destruct(&data[i]);
158 allocator.construct(&data[i], data[i-1]);
162 allocator.destruct(&data[index]);
163 allocator.construct(&data[index], e);
171 allocator.construct(&data[used], data[used-1]);
174 for (
u32 i=used-1; i>index; --i)
179 data[index] = element;
184 allocator.construct(&data[index], element);
196 if (free_when_destroyed)
198 for (
u32 i=0; i<used; ++i)
199 allocator.destruct(&data[i]);
201 allocator.deallocate(data);
225 is_sorted = _is_sorted;
226 free_when_destroyed=_free_when_destroyed;
240 free_when_destroyed = f;
250 if (allocated < usedNow)
262 strategy = other.strategy;
268 if (other.allocated == 0)
271 data = allocator.allocate(other.allocated);
274 free_when_destroyed =
true;
275 is_sorted = other.is_sorted;
276 allocated = other.allocated;
278 for (
u32 i=0; i<other.used; ++i)
279 allocator.construct(&data[i], other.data[i]);
288 if (used != other.used)
291 for (
u32 i=0; i<other.used; ++i)
292 if (data[i] != other[i])
301 return !(*
this==other);
387 if (!is_sorted && used>1)
439 if (element < data[m])
444 }
while((element < data[m] || data[m] < element) && left<=right);
451 if (!(element < data[m]) && !(data[m] < element))
477 while ( index > 0 && !(element < data[index - 1]) && !(data[index - 1] < element) )
482 while ( last < (
s32) used - 1 && !(element < data[last + 1]) && !(data[last + 1] < element) )
499 for (
u32 i=0; i<used; ++i)
500 if (element == data[i])
515 for (
s32 i=used-1; i>=0; --i)
516 if (data[i] == element)
531 for (
u32 i=index+1; i<used; ++i)
533 allocator.destruct(&data[i-1]);
534 allocator.construct(&data[i-1], data[i]);
537 allocator.destruct(&data[used-1]);
550 if (index>=used || count<1)
552 if (index+count>used)
556 for (i=index; i<index+count; ++i)
557 allocator.destruct(&data[i]);
559 for (i=index+count; i<used; ++i)
561 if (i-count >= index+count)
562 allocator.destruct(&data[i-count]);
564 allocator.construct(&data[i-count], data[i]);
567 allocator.destruct(&data[i]);
577 is_sorted = _is_sorted;
592 strategy = other.strategy;
593 other.strategy = helper_strategy;
594 bool helper_free_when_destroyed(free_when_destroyed);
595 free_when_destroyed = other.free_when_destroyed;
596 other.free_when_destroyed = helper_free_when_destroyed;
597 bool helper_is_sorted(is_sorted);
598 is_sorted = other.is_sorted;
599 other.is_sorted = helper_is_sorted;
609 bool free_when_destroyed:1;