Some list code improvements

Sun, 06 May 2007 16:05:59 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 06 May 2007 16:05:59 +0200
changeset 111
7d1dccdd7215
parent 110
13134ea30227
child 112
ccc57312b8d0

Some list code improvements

objlist.c file | annotate | diff | comparison | revisions
objlist.h file | annotate | diff | comparison | revisions
ptrlist.c file | annotate | diff | comparison | revisions
ptrlist.h file | annotate | diff | comparison | revisions
--- a/objlist.c	Tue Apr 24 19:00:47 2007 +0200
+++ b/objlist.c	Sun May 06 16:05:59 2007 +0200
@@ -136,6 +136,12 @@
 }
 
 
+bool objlist_contains(ObjList *objlist, Obj *obj)
+{
+    return (objlist_find_node(objlist, obj)!=NULL);
+}
+
+
 bool objlist_insert_last(ObjList **objlist, Obj *obj)
 {
     ObjList *node=reuse(objlist);
@@ -177,7 +183,7 @@
     node=objlist_find_node(*objlist, obj);
     
     if(node==NULL)
-        return FALSE;
+        return objlist_insert_last(objlist, obj);
     
     UNLINK_ITEM(*objlist, node, next, prev);
     LINK_ITEM_LAST(*objlist, node, next, prev);
@@ -195,7 +201,7 @@
     node=objlist_find_node(*objlist, obj);
     
     if(node==NULL)
-        return FALSE;
+        return objlist_insert_first(objlist, obj);
     
     UNLINK_ITEM(*objlist, node, next, prev);
     LINK_ITEM_FIRST(*objlist, node, next, prev);
--- a/objlist.h	Tue Apr 24 19:00:47 2007 +0200
+++ b/objlist.h	Sun May 06 16:05:59 2007 +0200
@@ -48,6 +48,7 @@
 extern bool objlist_reinsert_last(ObjList **objlist, Obj *obj);
 extern bool objlist_reinsert_first(ObjList **objlist, Obj *obj);
 extern bool objlist_remove(ObjList **objlist, Obj *obj);
+extern bool objlist_contains(ObjList *objlist, Obj *obj);
 extern void objlist_clear(ObjList **objlist);
 extern void objlist_iter_init(ObjListIterTmp *state, ObjList *objlist);
 extern Obj *objlist_iter(ObjListIterTmp *state);
--- a/ptrlist.c	Tue Apr 24 19:00:47 2007 +0200
+++ b/ptrlist.c	Sun May 06 16:05:59 2007 +0200
@@ -53,6 +53,12 @@
 }
 
 
+bool ptrlist_contains(PtrList *ptrlist, void *ptr)
+{
+    return (ptrlist_find_node(ptrlist, ptr)!=NULL);
+}
+
+
 bool ptrlist_insert_last(PtrList **ptrlist, void *ptr)
 {
     PtrList *node=mknode(ptr);
@@ -84,7 +90,7 @@
     PtrList *node=ptrlist_find_node(*ptrlist, ptr);
     
     if(node==NULL)
-        return FALSE;
+        return ptrlist_insert_last(ptrlist, ptr);
     
     UNLINK_ITEM(*ptrlist, node, next, prev);
     LINK_ITEM_LAST(*ptrlist, node, next, prev);
@@ -98,7 +104,7 @@
     PtrList *node=ptrlist_find_node(*ptrlist, ptr);
     
     if(node==NULL)
-        return FALSE;
+        return ptrlist_insert_first(ptrlist, ptr);
     
     UNLINK_ITEM(*ptrlist, node, next, prev);
     LINK_ITEM_FIRST(*ptrlist, node, next, prev);
--- a/ptrlist.h	Tue Apr 24 19:00:47 2007 +0200
+++ b/ptrlist.h	Sun May 06 16:05:59 2007 +0200
@@ -46,6 +46,7 @@
 extern bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr);
 extern bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr);
 extern bool ptrlist_remove(PtrList **ptrlist, void *ptr);
+extern bool ptrlist_contains(PtrList *ptrlist, void *ptr);
 extern void ptrlist_clear(PtrList **ptrlist);
 extern void ptrlist_iter_init(PtrListIterTmp *state, PtrList *ptrlist);
 extern void *ptrlist_iter(PtrListIterTmp *state);

mercurial