Added routines to take first/last elements of objlist and ptrlist.

Sat, 26 Feb 2005 22:09:33 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 26 Feb 2005 22:09:33 +0100
changeset 92
55fcdff5bcea
parent 91
817f90f58aec
child 93
5f72042eb91c

Added routines to take first/last elements of objlist and ptrlist.

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	Sat Feb 26 21:58:19 2005 +0100
+++ b/objlist.c	Sat Feb 26 22:09:33 2005 +0100
@@ -276,3 +276,49 @@
     
     return TRUE;
 }
+
+
+Obj *objlist_take_first(ObjList **objlist)
+{
+    ObjList *node;
+    Obj*obj;
+    
+    optimise(objlist);
+    
+    node=*objlist;
+    
+    if(node==NULL)
+        return NULL;
+    
+    obj=node->watch.obj;
+    
+    assert(obj!=NULL);
+    
+    free_node(objlist, node);
+    
+    return obj;
+}
+    
+        
+Obj *objlist_take_last(ObjList **objlist)
+{
+    ObjList *node;
+    Obj*obj;
+    
+    optimise(objlist);
+    
+    node=*objlist;
+    
+    if(node==NULL)
+        return NULL;
+    
+    node=node->prev;
+    
+    obj=node->watch.obj;
+
+    assert(obj!=NULL);
+    
+    free_node(objlist, node);
+    
+    return obj;
+}
--- a/objlist.h	Sat Feb 26 21:58:19 2005 +0100
+++ b/objlist.h	Sat Feb 26 22:09:33 2005 +0100
@@ -58,5 +58,7 @@
 extern void objlist_iter_rev_init(ObjListIterTmp *state, ObjList *objlist);
 extern Obj *objlist_iter_rev(ObjListIterTmp *state);
 extern bool objlist_empty(ObjList *objlist);
+extern Obj *objlist_take_first(ObjList **objlist);
+extern Obj *objlist_take_last(ObjList **objlist);
 
 #endif /* LIBTU_OBJLIST_H */
--- a/ptrlist.c	Sat Feb 26 21:58:19 2005 +0100
+++ b/ptrlist.c	Sat Feb 26 22:09:33 2005 +0100
@@ -165,3 +165,36 @@
     return ptr;
 }
 
+
+void *ptrlist_take_first(PtrList **ptrlist)
+{
+    PtrList *node=*ptrlist;
+    void *ptr;
+    
+    if(node==NULL)
+        return NULL;
+    
+    ptr=node->ptr;
+    
+    free_node(ptrlist, node);
+    
+    return ptr;
+}
+    
+        
+void *ptrlist_take_last(PtrList **ptrlist)
+{
+    PtrList *node=*ptrlist;
+    void *ptr;
+    
+    if(node==NULL)
+        return NULL;
+    
+    node=node->prev;
+    
+    ptr=node->ptr;
+    
+    free_node(ptrlist, node);
+    
+    return ptr;
+}
--- a/ptrlist.h	Sat Feb 26 21:58:19 2005 +0100
+++ b/ptrlist.h	Sat Feb 26 22:09:33 2005 +0100
@@ -56,5 +56,7 @@
 extern void *ptrlist_iter(PtrListIterTmp *state);
 extern void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist);
 extern void *ptrlist_iter_rev(PtrListIterTmp *state);
+extern void *ptrlist_take_first(PtrList **ptrlist);
+extern void *ptrlist_take_last(PtrList **ptrlist);
 
 #endif /* LIBTU_PTRLIST_H */

mercurial