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 return array[fldsize - 1];
37 void setSize(uint _size) {
38 if (_size <= fldsize) {
41 } else if (_size > capacity) {
42 array = (type *)ourrealloc(array, _size * sizeof(type));
45 bzero(&array[fldsize], (_size - fldsize) * sizeof(type));
49 void addAll(Vector<type> *v) {
50 int oldsize = fldsize;
51 setSize(fldsize + v->fldsize);
52 memcpy(&array[fldsize], v->array, v->fldsize * sizeof(type));
56 if (fldsize >= capacity) {
57 uint newcap = capacity << 1;
58 array = (type *)ourrealloc(array, newcap * sizeof(type));
61 array[fldsize++] = item;
64 type get(uint index) const {
68 void setExpand(uint index, type item) {
74 void set(uint index, type item) {
82 bool isEmpty() const {