fix mutex_trylock bug
[c11tester.git] / stl-model.h
index 489939b739c97878a7a264b4af3d0cc08caf3e3a..611520fc70515fa745239df32b4248d1db8068d6 100644 (file)
@@ -5,7 +5,6 @@
 #include "mymemory.h"
 typedef unsigned int uint;
 
-
 template<typename _Tp>
 class mllnode {
 public:
@@ -59,15 +58,21 @@ public:
        void pop_front() {
                mllnode<_Tp> *tmp = head;
                head = head->next;
-               head->prev = NULL;
+               if (head == NULL)
+                       tail = NULL;
+               else
+                       head->prev = NULL;
                delete tmp;
                _size--;
        }
 
        void pop_back() {
                mllnode<_Tp> *tmp = tail;
-               tail = tail->next;
-               tail->next = NULL;
+               tail = tail->prev;
+               if (tail == NULL)
+                       head = NULL;
+               else
+                       tail->next = NULL;
                delete tmp;
                _size--;
        }
@@ -120,7 +125,7 @@ public:
                if (tail == node) {
                        tail = node->prev;
                } else {
-                       tail->next->prev = node->prev;
+                       node->next->prev = node->prev;
                }
                mllnode<_Tp> *next = node->next;
                delete node;
@@ -159,6 +164,8 @@ private:
        uint _size;
 };
 
+class actionlist;
+
 template<typename _Tp>
 class sllnode {
 public:
@@ -173,6 +180,7 @@ private:
        _Tp val;
        template<typename T>
        friend class SnapList;
+       friend class actionlist;
 };
 
 template<typename _Tp>
@@ -208,18 +216,51 @@ public:
                _size++;
        }
 
+       sllnode<_Tp>* add_front(_Tp val) {
+               sllnode<_Tp> * tmp = new sllnode<_Tp>();
+               tmp->prev = NULL;
+               tmp->next = head;
+               tmp->val = val;
+               if (head == NULL)
+                       tail = tmp;
+               else
+                       head->prev = tmp;
+               head = tmp;
+               _size++;
+               return tmp;
+       }
+
+       sllnode<_Tp> * add_back(_Tp val) {
+               sllnode<_Tp> * tmp = new sllnode<_Tp>();
+               tmp->prev = tail;
+               tmp->next = NULL;
+               tmp->val = val;
+               if (tail == NULL)
+                       head = tmp;
+               else tail->next = tmp;
+               tail = tmp;
+               _size++;
+               return tmp;
+       }
+
        void pop_front() {
                sllnode<_Tp> *tmp = head;
                head = head->next;
-               head->prev = NULL;
+               if (head == NULL)
+                       tail = NULL;
+               else
+                       head->prev = NULL;
                delete tmp;
                _size--;
        }
 
        void pop_back() {
                sllnode<_Tp> *tmp = tail;
-               tail = tail->next;
-               tail->next = NULL;
+               tail = tail->prev;
+               if (tail == NULL)
+                       head = NULL;
+               else
+                       tail->next = NULL;
                delete tmp;
                _size--;
        }
@@ -234,7 +275,7 @@ public:
                _size=0;
        }
 
-       void insertAfter(sllnode<_Tp> * node, _Tp val) {
+       sllnode<_Tp> * insertAfter(sllnode<_Tp> * node, _Tp val) {
                sllnode<_Tp> *tmp = new sllnode<_Tp>();
                tmp->val = val;
                tmp->prev = node;
@@ -246,6 +287,7 @@ public:
                        tmp->next->prev = tmp;
                }
                _size++;
+               return tmp;
        }
 
        void insertBefore(sllnode<_Tp> * node, _Tp val) {
@@ -272,7 +314,7 @@ public:
                if (tail == node) {
                        tail = node->prev;
                } else {
-                       tail->next->prev = node->prev;
+                       node->next->prev = node->prev;
                }
 
                sllnode<_Tp> *next = node->next;
@@ -334,7 +376,7 @@ public:
        }
 
        type back() const {
-               return array[size - 1];
+               return array[_size - 1];
        }
 
        void resize(uint psize) {
@@ -358,11 +400,11 @@ public:
                array[_size++] = item;
        }
 
-       type operator[](uint index) const {
+       type operator[](int index) const {
                return array[index];
        }
 
-       type & operator[](uint index) {
+       type & operator[](int index) {
                return array[index];
        }
 
@@ -463,11 +505,11 @@ public:
                array[_size++] = item;
        }
 
-       type & operator[](uint index) {
+       type operator[](int index) const {
                return array[index];
        }
 
-       type operator[](uint index) const {
+       type & operator[](int index) {
                return array[index];
        }
 
@@ -497,6 +539,15 @@ public:
                array[index] = item;
        }
 
+       void remove(type item) {
+               for(uint i = 0;i < _size;i++) {
+                       if (at(i) == item) {
+                               removeAt(i);
+                               return;
+                       }
+               }
+       }
+
        void removeAt(uint index) {
                for (uint i = index;(i + 1) < _size;i++) {
                        set(i, at(i + 1));