4 #define VECTOR_DEFCAP 8
6 template<typename type>
9 Vector(uint _capacity = VECTOR_DEFCAP) :
12 array((type *) ourmalloc(sizeof(type) * _capacity)) {
15 Vector(uint _capacity, type *_array) :
18 array((type *) ourmalloc(sizeof(type) * _capacity)) {
19 memcpy(array, _array, capacity * sizeof(type));
22 Vector(Vector<type> *v) :
24 capacity(v->capacity),
25 array((type *) ourmalloc(sizeof(type) * v->capacity)) {
26 memcpy(array, v->array, capacity * sizeof(type));
34 for (uint i=0; i<fldsize; i++) {
36 for (i++; i<fldsize; i++) {
37 array[i - 1] = array[i];
45 void removeIndex(uint i) {
46 for (i++; i<fldsize; i++) {
47 array[i - 1] = array[i];
53 return array[fldsize - 1];
56 void setSize(uint _size) {
57 if (_size <= fldsize) {
60 } else if (_size > capacity) {
61 array = (type *)ourrealloc(array, _size * sizeof(type));
64 bzero(&array[fldsize], (_size - fldsize) * sizeof(type));
68 void addAll(Vector<type> *v) {
69 int oldsize = fldsize;
70 setSize(fldsize + v->fldsize);
71 memcpy(&array[fldsize], v->array, v->fldsize * sizeof(type));
75 if (fldsize >= capacity) {
76 uint newcap = capacity << 1;
77 array = (type *)ourrealloc(array, newcap * sizeof(type));
80 array[fldsize++] = item;
91 type get(uint index) const {
95 type setExpand(uint index, type item) {
96 type retval = (type) 0;
100 retval = array[index];
105 void set(uint index, type item) {
113 bool isEmpty() const {