Ref counting
[iotcloud.git] / version2 / src / C / vector.h
index 00ff96281c3d8f965db3c32f72bfebca504973b9..5ca954be06926f5eecc61b4fef1a0e147f5b8baa 100644 (file)
@@ -30,6 +30,26 @@ public:
                fldsize--;
        }
 
+       bool remove(type t) {
+               for (uint i = 0; i < fldsize; i++) {
+                       if (array[i] == t) {
+                               for (i++; i < fldsize; i++) {
+                                       array[i - 1] = array[i];
+                               }
+                               fldsize--;
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       void removeIndex(uint i) {
+               for (i++; i < fldsize; i++) {
+                       array[i - 1] = array[i];
+               }
+               fldsize--;
+       }
+
        type last() const {
                return array[fldsize - 1];
        }
@@ -52,6 +72,12 @@ public:
                memcpy(&array[fldsize], v->array, v->fldsize * sizeof(type));
        }
 
+       void removeAll(Vector<type> *v) {
+               uint vsize = v->size();
+               for (uint i = 0; i < vsize; i++)
+                       remove(v->get(i));
+       }
+
        void add(type item) {
                if (fldsize >= capacity) {
                        uint newcap = capacity << 1;
@@ -61,14 +87,26 @@ public:
                array[fldsize++] = item;
        }
 
+       type lastElement() {
+               return get(size() - 1);
+       }
+
+       type firstElement() {
+               return get(0);
+       }
+
        type get(uint index) const {
                return array[index];
        }
 
-       void setExpand(uint index, type item) {
+       type setExpand(uint index, type item) {
+               type retval = (type) 0;
                if (index >= fldsize)
                        setSize(index + 1);
+               else
+                       retval = array[index];
                set(index, item);
+               return retval;
        }
 
        void set(uint index, type item) {