5 #define VECTOR_DEFCAP 8
7 template<typename type>
10 Vector(uint _capacity = VECTOR_DEFCAP) :
13 array((type *) ourmalloc(sizeof(type) * _capacity)) {
16 Vector(uint _capacity, type *_array) :
19 array((type *) ourmalloc(sizeof(type) * _capacity)) {
20 memcpy(array, _array, capacity * sizeof(type));
23 Vector(Vector<type> *v) :
25 capacity(v->capacity),
26 array((type *) ourmalloc(sizeof(type) * v->capacity)) {
27 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 push(type item) {
50 if (size >= capacity) {
51 uint newcap = capacity << 1;
52 array = (type *)ourrealloc(array, newcap * sizeof(type));
58 type get(uint index) const {
62 void setExpand(uint index, type item) {
68 void set(uint index, type item) {
72 void insertAt(uint index, type item) {
74 for (uint i = size - 1; i > index; i--) {
80 void removeAt(uint index) {
81 for (uint i = index; (i + 1) < size; i++) {
87 inline uint getSize() const {