5 #define VectorDef(name, type, defcap) \
6 struct Vector ## name { \
11 typedef struct Vector ## name Vector ## name; \
12 Vector ## name * allocVector ## name(uint capacity); \
13 Vector ## name * allocDefVector ## name(); \
14 Vector ## name * allocVectorArray ## name(uint capacity, type * array); \
15 void pushVector ## name(Vector ## name *vector, type item); \
16 type getVector ## name(Vector ## name *vector, uint index); \
17 void setVector ## name(Vector ## name *vector, uint index, type item); \
18 uint getSizeVector ##name(Vector ##name *vector); \
19 void deleteVector ##name(Vector ##name *vector); \
20 void clearVector ##name(Vector ## name *vector);
22 #define VectorImpl(name, type, defcap) \
23 Vector ## name * allocDefVector ## name() { \
24 return allocVector ## name(defcap); \
26 Vector ## name * allocVector ## name(uint capacity) { \
27 Vector ## name * tmp = (Vector ## name *) ourmalloc(sizeof(type)); \
29 tmp->capacity = capacity; \
30 tmp->array = (type *) ourcalloc(1, sizeof(type) * capacity); \
33 Vector ## name * allocVectorArray ## name(uint capacity, type * array) { \
34 Vector ## name * tmp = allocVector ## name(capacity); \
35 memcpy(tmp->array, array, capacity * sizeof(type)); \
38 void pushVector ## name(Vector ## name *vector, type item) { \
39 if (vector->size >= vector->capacity) { \
40 uint newcap=vector->capacity * 2; \
41 vector->array=(type *)ourrealloc(vector->array, newcap); \
43 vector->array[vector->size++] = item; \
45 type getVector ## name(Vector ## name * vector, uint index) { \
46 return vector->array[index]; \
48 void setVector ## name(Vector ## name * vector, uint index, type item) { \
49 vector->array[index]=item; \
51 uint getSizeVector ## name(Vector ## name *vector) { \
52 return vector->size; \
54 void deleteVector ##name(Vector ##name *vector) { \
55 ourfree(vector->array); \
58 void clearVector ##name(Vector ## name *vector) { \