sparse or decompose
[satune.git] / src / Collections / cppvector.h
index e9164df61bdbe6426fb53093fd0016bae922e82f..b4822ef4a588175410b9d395ad6aefd2f033139d 100644 (file)
@@ -20,11 +20,17 @@ public:
                memcpy(array, _array, capacity * sizeof(type));
        }
 
+       Vector(Vector<type> *v) :
+               size(v->size),
+               capacity(v->capacity),
+               array((type *) ourmalloc(sizeof(type) * v->capacity)) {
+               memcpy(array, v->array, capacity * sizeof(type));
+       }
        void pop() {
                size--;
        }
 
-       type last() {
+       type last() const {
                return array[size - 1];
        }
 
@@ -49,7 +55,7 @@ public:
                array[size++] = item;
        }
 
-       type get(uint index) {
+       type get(uint index) const {
                return array[index];
        }
 
@@ -63,7 +69,22 @@ public:
                array[index] = item;
        }
 
-       uint getSize() {
+       void insertAt(uint index, type item) {
+               setSize(size + 1);
+               for (uint i = size - 1; i > index; i--) {
+                       set(i, get(i - 1));
+               }
+               array[index] = item;
+       }
+
+       void removeAt(uint index) {
+               for (uint i = index; (i + 1) < size; i++) {
+                       set(i, get(i + 1));
+               }
+               setSize(size - 1);
+       }
+
+       inline uint getSize() const {
                return size;
        }