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