SingleLinkedList

Manages a circularly linked list of objects.

---------     ---------             ---------
| First |     | Node2 |             | Last  |
---------     ---------             ---------
| *next | --> | *next | --> ...-->  | *next |--┐
---------     ---------             ---------  |
   ^-------------------------------------------┘
Summary
SingleLinkedListManages a circularly linked list of objects.
CopyrightThis program is free software.
Files
C-kern/api/ds/inmem/slist.hHeader file of SingleLinkedList.
C-kern/ds/inmem/slist.cImplementation file of SingleLinkedList impl.
Types
struct slist_tExport slist_t.
struct slist_iterator_tExport slist_iterator_t.
Functions
test
unittest_ds_inmem_slistTest slist_t functionality.
slist_iterator_tIterates over elements contained in slist_t.
lifetime
slist_iterator_FREEStatic initializer.
initfirst_slistiteratorInitializes an iterator for slist_t.
free_slistiteratorFrees an iterator of slist_t.
iterate
next_slistiteratorReturns next iterated node.
slist_tPoints to last object in a list of objects.
lastPoints to last element (tail) of list.
lifetime
slist_INITStatic initializer.
init_slistInitializes a single linked list object.
initsingle_slistInitializes a single linked list object containing a single node.
free_slistFrees memory of all contained objects.
query
isempty_slistReturns true if list contains no nodes.
first_slistReturns the first element in the list.
last_slistReturns the last node in the list.
next_slistReturns the node coming after this node.
isinlist_slistReturns true if node is stored in a list else false.
foreach-support
iteratortype_slistDeclaration to associate slist_iterator_t with slist_t.
iteratedtype_slistDeclaration to associate slist_node_t with slist_t.
change
insertfirst_slistMakes new_node the new first element of list.
insertlast_slistMakes new_node the new last element of list.
insertafter_slistAdds new_node after prev_node into list.
removefirst_slistRemoves the first element from list.
removeafter_slistRemoves the next node coming after prev_node from the list.
change set
removeall_slistRemoves all nodes from the list.
generic
genericcast_slistCasts list into slist_t if that is possible.
slist_IMPLEMENTGenerates interface of single linked list storing elements of type object_t.
inline implementation
slist_iterator_t
free_slistiteratorImplements <slist_t.free_slistiterator>.
initfirst_slistiteratorImplements <slist_t.initfirst_slistiterator>.
next_slistiteratorImplements <slist_t.next_slistiterator>.
slist_t
genericcast_slistImplements slist_t.genericcast_slist.
isinlist_slistImplements slist_t.isinlist_slist.
first_slistImplements slist_t.first_slist.
init_slistImplements slist_t.init_slist.
initsingle_slistImplements slist_t.initsingle_slist.
isempty_slistImplements slist_t.isempty_slist.
last_slistImplements slist_t.last_slist.
next_slistImplements slist_t.next_slist.
removeall_slistImplements slist_t.removeall_slist with help of slist_t.free_slist.
slist_IMPLEMENTImplements slist_t.slist_IMPLEMENT.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/ds/inmem/slist.h

Header file of SingleLinkedList.

C-kern/ds/inmem/slist.c

Implementation file of SingleLinkedList impl.

Types

struct slist_t

typedef struct slist_t slist_t

Export slist_t.

struct slist_iterator_t

typedef struct slist_iterator_t slist_iterator_t

Export slist_iterator_t.

Functions

Summary

test

unittest_ds_inmem_slist

int unittest_ds_inmem_slist(void)

Test slist_t functionality.

slist_iterator_t

struct slist_iterator_t

Iterates over elements contained in slist_t.  The iterator supports removing or deleting of the current node.

Example

slist_t list ;
fill_list(&list) ;
slist_node_t * prev = last_slist(&list) ;
foreach (_slist, &list, node) {
   if (need_to_remove(node)) {
      removeafter_slist(&list, prev, node) ;
      delete_node(node) ;
   } else {
      prev = node ;
   }
}
Summary
lifetime
slist_iterator_FREEStatic initializer.
initfirst_slistiteratorInitializes an iterator for slist_t.
free_slistiteratorFrees an iterator of slist_t.
iterate
next_slistiteratorReturns next iterated node.

lifetime

slist_iterator_FREE

#define slist_iterator_FREE { 0, 0 }

Static initializer.

initfirst_slistiterator

int initfirst_slistiterator(/*out*/slist_iterator_t *iter,
slist_t *list)

Initializes an iterator for slist_t.

free_slistiterator

int free_slistiterator(slist_iterator_t *iter)

Frees an iterator of slist_t.  This is a no-op.

iterate

next_slistiterator

bool next_slistiterator(slist_iterator_t *iter,
/*out*/struct slist_node_t **node)

Returns next iterated node.  The first call after initfirst_slistiterator returns the first list element if it is not empty.

Returns

truenode contains a pointer to the next valid node in the list.
falseThere is no next node.  The last element was already returned or the list is empty.

slist_t

struct slist_t

Points to last object in a list of objects.  Every object points to its successor.  The list is organized as a ring.  So the last object points to “its successor” which is the first object or head of list.

To search for an element in the list needs time O(n).  Adding and removing needs O(1).

The list stores nodes of type slist_node_t.  To manage objects of arbitrary type add a struct member of this type and cast the pointers from slist_node_t to your object-type with help of offsetof(object-type, slist_node_name) or use the macro slist_IMPLEMENT which generates small wrappers for every single slist function which do this conversion automatically.

Example

typedef struct object_t object_t ;
typedef struct objectadapt_t objectadapt_t ;
struct object_t {
... ; slist_node_t slnode ; ...
} ;
struct objectadapt_t {
   typeadapt_EMBED(objectadapt_t, object_t, void) ; // void: keytype not used in list
} ;
slist_IMPLEMENT(_mylist, object_t, slnode.next) ;


void function() {
 slist_t mylist ;
 init_mylist(&mylist) ;
 object_t * new_object = ... ;
 new_object->slnode = slist_node_INIT ;

 // instead of
 err = insertfirst_slist(&mylist, &new_object->slnode)
 // you can now do
 err = insertfirst_mylist(&mylist, new_object) ;

 // instead of
 object_t * first = (object_t*)((uintptr_t)first_slist(&mylist) - offsetof(object_t,slnode)) ;
 // you can now do
 object_t * first = first_mylist(&mylist) ;

// free objects automatically
objectadapt_t      typeadapt = typeadapt_INIT_LIFETIME(0, &delete_object_function) ;
err = free_mylist(&mylist, genericcast_typeadapt(&typeadapt, object_t, void)) ;
}
Summary
lastPoints to last element (tail) of list.
lifetime
slist_INITStatic initializer.
init_slistInitializes a single linked list object.
initsingle_slistInitializes a single linked list object containing a single node.
free_slistFrees memory of all contained objects.
query
isempty_slistReturns true if list contains no nodes.
first_slistReturns the first element in the list.
last_slistReturns the last node in the list.
next_slistReturns the node coming after this node.
isinlist_slistReturns true if node is stored in a list else false.
foreach-support
iteratortype_slistDeclaration to associate slist_iterator_t with slist_t.
iteratedtype_slistDeclaration to associate slist_node_t with slist_t.
change
insertfirst_slistMakes new_node the new first element of list.
insertlast_slistMakes new_node the new last element of list.
insertafter_slistAdds new_node after prev_node into list.
removefirst_slistRemoves the first element from list.
removeafter_slistRemoves the next node coming after prev_node from the list.
change set
removeall_slistRemoves all nodes from the list.
generic
genericcast_slistCasts list into slist_t if that is possible.
slist_IMPLEMENTGenerates interface of single linked list storing elements of type object_t.

last

struct slist_node_t * last

Points to last element (tail) of list.

lifetime

slist_INIT

#define slist_INIT { (void*)0 }

Static initializer.  You can use it instead of init_slist.  After assigning you can call free_slist or any other function safely.

init_slist

void init_slist(/*out*/slist_t *list)

Initializes a single linked list object.  The caller has to provide an unitialized list object.  This function never fails.

initsingle_slist

void initsingle_slist(/*out*/slist_t *list,
slist_node_t *node)

Initializes a single linked list object containing a single node.

free_slist

int free_slist(slist_t *list,  
uint16_t nodeoffset,  
struct typeadapt_t *typeadp/*0 = >no free called*/)

Frees memory of all contained objects.  Set nodeadp to 0 if you do not want to call a free memory on every node.

query

isempty_slist

int isempty_slist(const slist_t *list)

Returns true if list contains no nodes.

first_slist

struct slist_node_t * first_slist(const slist_t *list)

Returns the first element in the list.  Returns NULL in case list contains no elements.

last_slist

struct slist_node_t * last_slist(const slist_t *list)

Returns the last node in the list.  Returns NULL in case list contains no elements.

next_slist

struct slist_node_t * next_slist(struct slist_node_t *node)

Returns the node coming after this node.  If node is the last node in the list the first is returned instead.

isinlist_slist

bool isinlist_slist(struct slist_node_t *node)

Returns true if node is stored in a list else false.

foreach-support

iteratortype_slist

typedef slist_iterator_t iteratortype_slist

Declaration to associate slist_iterator_t with slist_t.

iteratedtype_slist

typedef struct slist_node_t * iteratedtype_slist

Declaration to associate slist_node_t with slist_t.

change

insertfirst_slist

void insertfirst_slist(slist_t *list,
struct slist_node_t *new_node)

Makes new_node the new first element of list.  Ownership is transfered from caller to slist_t.

Note

Make sure that new_node is not part of a list !

insertlast_slist

void insertlast_slist(slist_t *list,
struct slist_node_t *new_node)

Makes new_node the new last element of list.  Ownership is transfered from caller to slist_t.

Note

Make sure that new_node is not part of a list !

insertafter_slist

void insertafter_slist(slist_t *list,
struct slist_node_t *prev_node,
struct slist_node_t *new_node)

Adds new_node after prev_node into list.  Ownership is transfered from caller to slist_t.

Note

Make sure that new_node is not part of a list and that prev_node is part of the list !

removefirst_slist

int removefirst_slist(slist_t *list,
struct slist_node_t **removed_node)

Removes the first element from list.  If list contains no elements EINVAL is returned.  If list contains elements removed_node points to the removed first elementa and 0 is returned.  Ownership of removed_node is transfered back to caller.

removeafter_slist

int removeafter_slist(slist_t *list,
struct slist_node_t *prev_node,
struct slist_node_t **removed_node)

Removes the next node coming after prev_node from the list.  If the list contains no elements EINVAL is returned.  Ownership of removed_node is transfered back to caller.

Note

Make sure that prev_node is part of the list else behaviour is undefined !

change set

removeall_slist

int removeall_slist(slist_t *list,  
uint16_t nodeoffset,  
struct typeadapt_t *typeadp/*0 = >no free called*/)

Removes all nodes from the list.  For every removed node typeadapt_lifetime_it.delete_object is called.  Set nodeadp to 0 if you do not want to call a free memory on every node.

generic

genericcast_slist

slist_t * genericcast_slist(void *list)

Casts list into slist_t if that is possible.  The generic object list must have a last pointer as first member.

slist_IMPLEMENT

void slist_IMPLEMENT(IDNAME _fsuffix,
TYPENAME object_t,
IDNAME name_nextptr) ;

Generates interface of single linked list storing elements of type object_t.

Parameter

_fsuffixIt is the suffix of the generated list interface functions, e.g.  “init##_fsuffix”.
object_tThe type of object which can be stored and retrieved from this list.  The object must contain a field of type slist_node_t or use <slist_node_EMBED>.
name_nextptrThe name (access path) of the next pointer in object_t.  Use either structmembername.next or the name used in macro <slist_node_EMBED>.

slist_iterator_t

free_slistiterator

#define free_slistiterator(iter) ((iter)->next = 0, 0)

Implements <slist_t.free_slistiterator>.

initfirst_slistiterator

#define initfirst_slistiterator(
   iter,
   list
) ( __extension__ ({ typeof(iter) _iter = (iter) ; typeof(list) _list = (list) ; *_iter = (typeof(*_iter)) { first_slist(_list), _list } ; 0 ; }))

Implements <slist_t.initfirst_slistiterator>.

next_slistiterator

#define next_slistiterator(
   iter,
   node
) ( __extension__ ({ typeof(iter) _iter = (iter) ; typeof(node) _nd = (node) ; bool _isNext = (0 != _iter->next) ; if (_isNext) { *_nd = _iter->next ; if (_iter->list->last == _iter->next) _iter->next = 0 ; else _iter->next = next_slist(_iter->next) ; } _isNext ; }))

Implements <slist_t.next_slistiterator>.

slist_t

genericcast_slist

#define genericcast_slist(
   list
) ( __extension__ ({ static_assert(offsetof(typeof(*(list)), last) == offsetof(slist_t, last), "ensure same structure") ; static_assert((typeof((list)->last))0 == (slist_node_t*)0, "ensure same type") ; (slist_t*) (list) ; }))

Implements slist_t.genericcast_slist.

isinlist_slist

#define isinlist_slist(node) (0 != (node)->next)

Implements slist_t.isinlist_slist.

first_slist

#define first_slist(list) ((list)->last ? next_slist((list)->last) : 0)

Implements slist_t.first_slist.

init_slist

#define init_slist(list) ((void)(*(list) = (slist_t)slist_INIT))

Implements slist_t.init_slist.

initsingle_slist

#define initsingle_slist(
   list,
   node
) ((void)(*(list) = (slist_t){ node }, (node)->next = (node)))

Implements slist_t.initsingle_slist.

isempty_slist

#define isempty_slist(list) (0 == (list)->last)

Implements slist_t.isempty_slist.

last_slist

#define last_slist(list) ((list)->last)

Implements slist_t.last_slist.

next_slist

#define next_slist(node) ((node)->next)

Implements slist_t.next_slist.

removeall_slist

#define removeall_slist(list,
nodeoffset,
typeadp) free_slist((list), (nodeoffset), (typeadp))

Implements slist_t.removeall_slist with help of slist_t.free_slist.

slist_IMPLEMENT

#define slist_IMPLEMENT(
   _fsuffix,
   object_t,
   name_nextptr
) typedef slist_iterator_t iteratortype##_fsuffix ; typedef object_t * iteratedtype##_fsuffix ; static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix##iterator(slist_iterator_t * iter) __attribute__ ((always_inline)) ; static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) __attribute__ ((always_inline)) ; static inline void init##_fsuffix(slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline int isempty##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * first##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * last##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * next##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline bool isinlist##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) __attribute__ ((always_inline)) ; static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline slist_node_t * asnode##_fsuffix(object_t * object) { static_assert(&((object_t*)0)->name_nextptr == (slist_node_t**)offsetof(object_t, name_nextptr), "correct type") ; return (slist_node_t *) ((uintptr_t)object + offsetof(object_t, name_nextptr)) ; } static inline object_t * asobject##_fsuffix(slist_node_t * node) { return (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) ; } static inline object_t * asobjectnull##_fsuffix(slist_node_t * node) { return node ? (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) : 0 ; } static inline void init##_fsuffix(slist_t * list) { init_slist(list) ; } static inline void initsingle##_fsuffix(slist_t * list, object_t * node) { initsingle_slist(list, asnode##_fsuffix(node)) ; } static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return free_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int isempty##_fsuffix(const slist_t * list) { return isempty_slist(list) ; } static inline object_t * first##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(first_slist(list)) ; } static inline object_t * last##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(last_slist(list)) ; } static inline object_t * next##_fsuffix(object_t * node) { return asobject##_fsuffix(next_slist(asnode##_fsuffix(node))) ; } static inline bool isinlist##_fsuffix(object_t * node) { return isinlist_slist(asnode##_fsuffix(node)) ; } static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) { insertfirst_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) { insertlast_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) { insertafter_slist(list, asnode##_fsuffix(prev_node), asnode##_fsuffix(new_node)) ; } static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) { int err = removefirst_slist(list, (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) { int err = removeafter_slist(list, asnode##_fsuffix(prev_node), (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return removeall_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) { return initfirst_slistiterator(iter, list) ; } static inline int free##_fsuffix##iterator(slist_iterator_t * iter) { return free_slistiterator(iter) ; } static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) { bool isNext = next_slistiterator(iter, (slist_node_t**)node) ; if (isNext) *node = asobject##_fsuffix(*(slist_node_t**)node) ; return isNext ; }

Implements slist_t.slist_IMPLEMENT.

Manages a circularly linked list of objects.
Implements a linear linked list data structure.
typedef struct slist_t slist_t
Export slist_t.
struct slist_t
Points to last object in a list of objects.
typedef struct slist_iterator_t slist_iterator_t
Export slist_iterator_t.
struct slist_iterator_t
Iterates over elements contained in slist_t.
int unittest_ds_inmem_slist(void)
Test slist_t functionality.
#define slist_iterator_FREE { 0, 0 }
Static initializer.
int initfirst_slistiterator(/*out*/slist_iterator_t *iter,
slist_t *list)
Initializes an iterator for slist_t.
int free_slistiterator(slist_iterator_t *iter)
Frees an iterator of slist_t.
bool next_slistiterator(slist_iterator_t *iter,
/*out*/struct slist_node_t **node)
Returns next iterated node.
struct slist_node_t * last
Points to last element (tail) of list.
#define slist_INIT { (void*)0 }
Static initializer.
void init_slist(/*out*/slist_t *list)
Initializes a single linked list object.
void initsingle_slist(/*out*/slist_t *list,
slist_node_t *node)
Initializes a single linked list object containing a single node.
int free_slist(slist_t *list,  
uint16_t nodeoffset,  
struct typeadapt_t *typeadp/*0 = >no free called*/)
Frees memory of all contained objects.
int isempty_slist(const slist_t *list)
Returns true if list contains no nodes.
struct slist_node_t * first_slist(const slist_t *list)
Returns the first element in the list.
struct slist_node_t * last_slist(const slist_t *list)
Returns the last node in the list.
struct slist_node_t * next_slist(struct slist_node_t *node)
Returns the node coming after this node.
bool isinlist_slist(struct slist_node_t *node)
Returns true if node is stored in a list else false.
typedef slist_iterator_t iteratortype_slist
Declaration to associate slist_iterator_t with slist_t.
typedef struct slist_node_t * iteratedtype_slist
Declaration to associate slist_node_t with slist_t.
struct slist_node_t
Provides the means for linking an object to another of the same type.
void insertfirst_slist(slist_t *list,
struct slist_node_t *new_node)
Makes new_node the new first element of list.
void insertlast_slist(slist_t *list,
struct slist_node_t *new_node)
Makes new_node the new last element of list.
void insertafter_slist(slist_t *list,
struct slist_node_t *prev_node,
struct slist_node_t *new_node)
Adds new_node after prev_node into list.
int removefirst_slist(slist_t *list,
struct slist_node_t **removed_node)
Removes the first element from list.
int removeafter_slist(slist_t *list,
struct slist_node_t *prev_node,
struct slist_node_t **removed_node)
Removes the next node coming after prev_node from the list.
int removeall_slist(slist_t *list,  
uint16_t nodeoffset,  
struct typeadapt_t *typeadp/*0 = >no free called*/)
Removes all nodes from the list.
slist_t * genericcast_slist(void *list)
Casts list into slist_t if that is possible.
void slist_IMPLEMENT(IDNAME _fsuffix,
TYPENAME object_t,
IDNAME name_nextptr) ;
Generates interface of single linked list storing elements of type object_t.
#define free_slistiterator(iter) ((iter)->next = 0, 0)
Implements slist_t.free_slistiterator.
#define initfirst_slistiterator(
   iter,
   list
) ( __extension__ ({ typeof(iter) _iter = (iter) ; typeof(list) _list = (list) ; *_iter = (typeof(*_iter)) { first_slist(_list), _list } ; 0 ; }))
Implements slist_t.initfirst_slistiterator.
#define next_slistiterator(
   iter,
   node
) ( __extension__ ({ typeof(iter) _iter = (iter) ; typeof(node) _nd = (node) ; bool _isNext = (0 != _iter->next) ; if (_isNext) { *_nd = _iter->next ; if (_iter->list->last == _iter->next) _iter->next = 0 ; else _iter->next = next_slist(_iter->next) ; } _isNext ; }))
Implements slist_t.next_slistiterator.
#define genericcast_slist(
   list
) ( __extension__ ({ static_assert(offsetof(typeof(*(list)), last) == offsetof(slist_t, last), "ensure same structure") ; static_assert((typeof((list)->last))0 == (slist_node_t*)0, "ensure same type") ; (slist_t*) (list) ; }))
Implements slist_t.genericcast_slist.
#define isinlist_slist(node) (0 != (node)->next)
Implements slist_t.isinlist_slist.
#define first_slist(list) ((list)->last ? next_slist((list)->last) : 0)
Implements slist_t.first_slist.
#define init_slist(list) ((void)(*(list) = (slist_t)slist_INIT))
Implements slist_t.init_slist.
#define initsingle_slist(
   list,
   node
) ((void)(*(list) = (slist_t){ node }, (node)->next = (node)))
Implements slist_t.initsingle_slist.
#define isempty_slist(list) (0 == (list)->last)
Implements slist_t.isempty_slist.
#define last_slist(list) ((list)->last)
Implements slist_t.last_slist.
#define next_slist(node) ((node)->next)
Implements slist_t.next_slist.
#define removeall_slist(list,
nodeoffset,
typeadp) free_slist((list), (nodeoffset), (typeadp))
Implements slist_t.removeall_slist with help of slist_t.free_slist.
#define slist_IMPLEMENT(
   _fsuffix,
   object_t,
   name_nextptr
) typedef slist_iterator_t iteratortype##_fsuffix ; typedef object_t * iteratedtype##_fsuffix ; static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix##iterator(slist_iterator_t * iter) __attribute__ ((always_inline)) ; static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) __attribute__ ((always_inline)) ; static inline void init##_fsuffix(slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline int isempty##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * first##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * last##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * next##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline bool isinlist##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) __attribute__ ((always_inline)) ; static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline slist_node_t * asnode##_fsuffix(object_t * object) { static_assert(&((object_t*)0)->name_nextptr == (slist_node_t**)offsetof(object_t, name_nextptr), "correct type") ; return (slist_node_t *) ((uintptr_t)object + offsetof(object_t, name_nextptr)) ; } static inline object_t * asobject##_fsuffix(slist_node_t * node) { return (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) ; } static inline object_t * asobjectnull##_fsuffix(slist_node_t * node) { return node ? (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) : 0 ; } static inline void init##_fsuffix(slist_t * list) { init_slist(list) ; } static inline void initsingle##_fsuffix(slist_t * list, object_t * node) { initsingle_slist(list, asnode##_fsuffix(node)) ; } static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return free_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int isempty##_fsuffix(const slist_t * list) { return isempty_slist(list) ; } static inline object_t * first##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(first_slist(list)) ; } static inline object_t * last##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(last_slist(list)) ; } static inline object_t * next##_fsuffix(object_t * node) { return asobject##_fsuffix(next_slist(asnode##_fsuffix(node))) ; } static inline bool isinlist##_fsuffix(object_t * node) { return isinlist_slist(asnode##_fsuffix(node)) ; } static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) { insertfirst_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) { insertlast_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) { insertafter_slist(list, asnode##_fsuffix(prev_node), asnode##_fsuffix(new_node)) ; } static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) { int err = removefirst_slist(list, (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) { int err = removeafter_slist(list, asnode##_fsuffix(prev_node), (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return removeall_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) { return initfirst_slistiterator(iter, list) ; } static inline int free##_fsuffix##iterator(slist_iterator_t * iter) { return free_slistiterator(iter) ; } static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) { bool isNext = next_slistiterator(iter, (slist_node_t**)node) ; if (isNext) *node = asobject##_fsuffix(*(slist_node_t**)node) ; return isNext ; }
Implements slist_t.slist_IMPLEMENT.
int (
   *delete_object
) (struct typeadapt_t * typeadp, struct typeadapt_object_t ** object)
Function frees memory and associated resources of object.
Close