14 #ifndef RESIZEARRAYRAW_H
15 #define RESIZEARRAYRAW_H
21 #define ResizeArrayGrowthFactor 1.5
22 #define ResizeArrayMinSize 8
38 unsigned char *varray;
46 void resizeRaw(
int size) {
47 if (size <= allocSize)
return;
55 size = (int)(allocSize*ResizeArrayGrowthFactor);
67 unsigned char *tmpv =
new unsigned char[size*
sizeof(Elem)+63];
81 Elem *tmpa = (Elem *)(tmpv+63 - (((
long)(tmpv+63))&(63L)));
82 if (arraySize) CmiMemcpy((
void *)tmpa, (
void *)array,
sizeof(Elem)*arraySize);
84 if (allocSize)
delete[] varray;
96 inline int size(
void)
const {
return arraySize; }
97 inline Elem &operator[](
int index)
const {
return array[index]; }
101 inline int bufSize(
void)
const {
return allocSize; }
106 array((Elem *)0), varray((unsigned char *)0), arraySize(0), allocSize(0) { }
109 ResizeArrayRaw( Elem * *
const array,
int arraySize,
int allocSize) {
110 if (allocSize < arraySize) allocSize = arraySize;
111 this->allocSize = allocSize;
112 this->arraySize = arraySize;
113 varray = (
unsigned char *)*array;
114 this->array = (Elem *)*array;
123 resizeRaw(rar.size());
125 CmiMemcpy((
void*)array, (
void*)rar.array,
sizeof(Elem)*rar.size());
126 arraySize = rar.size();
132 void resize(
int size) {
135 if (size < arraySize) {
136 for (i=size; i<arraySize; i++) {
139 }
else if (size > arraySize) {
141 for (i=arraySize; i<size; i++) {
142 new ((
void *)&array[i]) Elem;
150 for (
int i=0; i < arraySize; i++) {
165 inline void del(
int index,
int number) {
168 for (
int i=index; i < index+number; i++) {
173 memmove((
void *)(array+index),
174 (
void *)(array+index+number),
175 (arraySize-number-index)*
sizeof(Elem));
186 inline void ins(
const Elem &e,
int index) {
188 if (index < arraySize) {
189 resizeRaw(arraySize+1);
191 memmove((
void *)(array+index+1),
192 (
void *)(array+index),
193 (arraySize-index)*
sizeof(Elem));
200 new((
void *)&array[index]) Elem;
204 if (index > arraySize) {
205 for (Elem *tmp = array+arraySize; tmp < array+index; tmp++) {
206 new ((
void *)tmp) Elem;
214 inline int find(
const Elem &e)
const {
215 for (
int i=0; i<arraySize; i++) {
216 if (array[i] == e)
return i;
#define ResizeArrayMinSize
#define ResizeArrayGrowthFactor