Loading...
Searching...
No Matches
utlist

Basic linked list operation definitions. More...

Detailed Description

Basic linked list operation definitions.

Files

file  utlist.h
 Macros for basic linked list operations.
 

Macros

#define UTLIST_VERSION   1.9.9
 Version number.
 

Compiler dependent defines

     These macros use decltype or the earlier __typeof GNU extension.
     As decltype is only available in newer compilers (VS2010 or gcc 4.3+
     when compiling c++ code), this code uses whatever method is needed
     or, for VS2008 where neither is available, uses casting workarounds.

     For VS2008 we use some workarounds to get around the lack of decltype,
     namely, we always reassign our tmp variable to the list head if we need
     to dereference its prev/next pointers, and save/restore the real head.
#define LDECLTYPE(x)   __typeof(x)
 
#define _SV(elt, list)
 
#define _NEXT(elt, list, next)   ((elt)->next)
 
#define _NEXTASGN(elt, list, to, next)   ((elt)->next)=(to)
 
#define _PREVASGN(elt, list, to, prev)   ((elt)->prev)=(to)
 
#define _RS(list)
 
#define _CASTASGN(a, b)   (a)=(b)
 

Mergesort based sort macros

     The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort
     Unwieldy variable names used here to avoid shadowing passed-in variables.
#define LL_SORT(list, cmp)    LL_SORT2(list, cmp, next)
 
#define LL_SORT2(list, cmp, next)
 
#define DL_SORT(list, cmp)    DL_SORT2(list, cmp, prev, next)
 
#define DL_SORT2(list, cmp, prev, next)
 
#define CDL_SORT(list, cmp)    CDL_SORT2(list, cmp, prev, next)
 
#define CDL_SORT2(list, cmp, prev, next)
 

Singly linked list macros (non-circular)

#define LL_PREPEND(head, add)    LL_PREPEND2(head,add,next)
 LL prepend element 'add' to list.
 
#define LL_PREPEND2(head, add, next)
 LL prepend to list with alternative next ptr name 'next'.
 
#define LL_CONCAT(head1, head2)    LL_CONCAT2(head1,head2,next)
 LL concat to append second list to first.
 
#define LL_CONCAT2(head1, head2, next)
 LL concat with alternative next ptr name 'next'.
 
#define LL_APPEND(head, add)    LL_APPEND2(head,add,next)
 LL append to append element 'add' to list.
 
#define LL_APPEND2(head, add, next)
 LL append with alternative next ptr name 'next'.
 
#define LL_DELETE(head, del)    LL_DELETE2(head,del,next)
 LL delete element 'del' from list.
 
#define LL_DELETE2(head, del, next)
 LL delete with alternative next ptr name 'name'.
 
#define LL_APPEND_VS2008(head, add)    LL_APPEND2_VS2008(head,add,next)
 
#define LL_APPEND2_VS2008(head, add, next)
 
#define LL_DELETE_VS2008(head, del)    LL_DELETE2_VS2008(head,del,next)
 
#define LL_DELETE2_VS2008(head, del, next)
 
#define LL_COUNT(head, el, counter)    LL_COUNT2(head,el,counter,next) \
 LL count list elements using 'counter'.
 
#define LL_COUNT2(head, el, counter, next)
 LL count with alternative next ptr name 'next'.
 
#define LL_FOREACH(head, el)    LL_FOREACH2(head,el,next)
 LL list iteration.
 
#define LL_FOREACH2(head, el, next)    for(el=head;el;el=(el)->next)
 LL list iteration with alternative next ptr name 'next'.
 
#define LL_FOREACH_SAFE(head, el, tmp)    LL_FOREACH_SAFE2(head,el,tmp,next)
 LL safe list iteration Use if list elements might be deleted while iterating.
 
#define LL_FOREACH_SAFE2(head, el, tmp, next)    for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
 LL safe list iteration with alternative ptr names.
 
#define LL_SEARCH_SCALAR(head, out, field, val)    LL_SEARCH_SCALAR2(head,out,field,val,next)
 LL scalar search for element with value 'val' for member 'field'.
 
#define LL_SEARCH_SCALAR2(head, out, field, val, next)
 LL scalar search with alternative next ptr name 'next'.
 
#define LL_SEARCH(head, out, elt, cmp)    LL_SEARCH2(head,out,elt,cmp,next)
 LL search element 'elt' in list using function 'cmp'.
 
#define LL_SEARCH2(head, out, elt, cmp, next)
 LL search with alternative next ptr name 'next'.
 
#define LL_REPLACE_ELEM(head, el, add)
 LL replace element 'el' with element 'add' in list.
 
#define LL_PREPEND_ELEM(head, el, add)
 LL prepend new element 'add' to element 'el' in list.
 

Doubly linked list macros (non-circular)

#define DL_PREPEND(head, add)    DL_PREPEND2(head,add,prev,next)
 DL prepend element 'add' to list.
 
#define DL_PREPEND2(head, add, prev, next)
 DL prepend to list with alternative ptr names.
 
#define DL_APPEND(head, add)    DL_APPEND2(head,add,prev,next)
 DL append to append element 'add' to list.
 
#define DL_APPEND2(head, add, prev, next)
 DL append with alternative next ptr name 'next'.
 
#define DL_CONCAT(head1, head2)    DL_CONCAT2(head1,head2,prev,next)
 DL concat to append second list to first.
 
#define DL_CONCAT2(head1, head2, prev, next)
 DL concat with alternative next ptr name 'next'.
 
#define DL_DELETE(head, del)    DL_DELETE2(head,del,prev,next)
 DL delete element 'del' from list.
 
#define DL_DELETE2(head, del, prev, next)
 DL delete with alternative ptr names.
 
#define DL_COUNT(head, el, counter)    DL_COUNT2(head,el,counter,next) \
 DL count list elements using 'counter'.
 
#define DL_COUNT2(head, el, counter, next)
 DL count with alternative next ptr name 'next'.
 
#define DL_FOREACH(head, el)    DL_FOREACH2(head,el,next)
 DL list iteration.
 
#define DL_FOREACH2(head, el, next)    for(el=head;el;el=(el)->next)
 DL list iteration with alternative next ptr name 'next'.
 
#define DL_FOREACH_SAFE(head, el, tmp)    DL_FOREACH_SAFE2(head,el,tmp,next)
 DL safe list iteration Use if list elements might be deleted while iterating.
 
#define DL_FOREACH_SAFE2(head, el, tmp, next)    for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
 DL safe list iteration with alternative ptr names.
 
#define DL_SEARCH_SCALAR   LL_SEARCH_SCALAR
 DL scalar search for element with value 'val' for member 'field' Identical to singly-linked counterpart.
 
#define DL_SEARCH_SCALAR2   LL_SEARCH_SCALAR2
 DL scalar search with alternative next ptr name 'next' Identical to singly-linked counterpart.
 
#define DL_SEARCH   LL_SEARCH
 DL search element 'elt' in list using function 'cmp' Identical to singly-linked counterpart.
 
#define DL_SEARCH2   LL_SEARCH2
 DL search with alternative next ptr name 'next' Identical to singly-linked counterpart.
 
#define DL_REPLACE_ELEM(head, el, add)
 DL replace element 'el' with element 'add' in list.
 
#define DL_PREPEND_ELEM(head, el, add)
 DL prepend new element 'add' to element 'el' in list.
 

Circular doubly linked list macros

#define CDL_PREPEND(head, add)    CDL_PREPEND2(head,add,prev,next)
 CDL prepend element 'add' to list.
 
#define CDL_PREPEND2(head, add, prev, next)
 CDL prepend to list with alternative ptr names.
 
#define CDL_DELETE(head, del)    CDL_DELETE2(head,del,prev,next)
 CDL delete element 'del' from list.
 
#define CDL_DELETE2(head, del, prev, next)
 CDL delete with alternative ptr names.
 
#define CDL_COUNT(head, el, counter)    CDL_COUNT2(head,el,counter,next) \
 CDL count list elements using 'counter'.
 
#define CDL_COUNT2(head, el, counter, next)
 CDL count with alternative next ptr name 'next'.
 
#define CDL_FOREACH(head, el)    CDL_FOREACH2(head,el,next)
 CDL list iteration.
 
#define CDL_FOREACH2(head, el, next)    for(el=head;el;el=((el)->next==head ? 0L : (el)->next))
 CDL list iteration with alternative next ptr name 'next'.
 
#define CDL_FOREACH_SAFE(head, el, tmp1, tmp2)    CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next)
 CDL safe list iteration Use if list elements might be deleted while iterating.
 
#define CDL_FOREACH_SAFE2(head, el, tmp1, tmp2, prev, next)
 CDL safe list iteration with alternative ptr names.
 
#define CDL_SEARCH_SCALAR(head, out, field, val)    CDL_SEARCH_SCALAR2(head,out,field,val,next)
 CDL scalar search for element with value 'val' for member 'field'.
 
#define CDL_SEARCH_SCALAR2(head, out, field, val, next)
 CDL scalar search with alternative next ptr name 'next'.
 
#define CDL_SEARCH(head, out, elt, cmp)    CDL_SEARCH2(head,out,elt,cmp,next)
 CDL search element 'elt' in list using function 'cmp'.
 
#define CDL_SEARCH2(head, out, elt, cmp, next)
 CDL search with alternative next ptr name 'next'.
 
#define CDL_REPLACE_ELEM(head, el, add)
 CDL replace element 'el' with element 'add' in list.
 
#define CDL_PREPEND_ELEM(head, el, add)
 CDL prepend new element 'add' to element 'el' in list.
 

Macro Definition Documentation

◆ _CASTASGN

#define _CASTASGN (   a,
 
)    (a)=(b)

Definition at line 123 of file utlist.h.

◆ _NEXT

#define _NEXT (   elt,
  list,
  next 
)    ((elt)->next)

Definition at line 118 of file utlist.h.

◆ _NEXTASGN

#define _NEXTASGN (   elt,
  list,
  to,
  next 
)    ((elt)->next)=(to)

Definition at line 119 of file utlist.h.

◆ _PREVASGN

#define _PREVASGN (   elt,
  list,
  to,
  prev 
)    ((elt)->prev)=(to)

Definition at line 121 of file utlist.h.

◆ _RS

#define _RS (   list)

Definition at line 122 of file utlist.h.

◆ _SV

#define _SV (   elt,
  list 
)

Definition at line 117 of file utlist.h.

◆ CDL_COUNT

#define CDL_COUNT (   head,
  el,
  counter 
)     CDL_COUNT2(head,el,counter,next) \

CDL count list elements using 'counter'.

Definition at line 775 of file utlist.h.

◆ CDL_COUNT2

#define CDL_COUNT2 (   head,
  el,
  counter,
  next 
)
Value:
{ \
counter = 0; \
CDL_FOREACH2(head,el,next){ ++counter; } \
}

CDL count with alternative next ptr name 'next'.

Definition at line 779 of file utlist.h.

◆ CDL_DELETE

#define CDL_DELETE (   head,
  del 
)     CDL_DELETE2(head,del,prev,next)

CDL delete element 'del' from list.

Definition at line 759 of file utlist.h.

◆ CDL_DELETE2

#define CDL_DELETE2 (   head,
  del,
  prev,
  next 
)
Value:
do { \
if ( ((head)==(del)) && ((head)->next == (head))) { \
(head) = 0L; \
} else { \
(del)->next->prev = (del)->prev; \
(del)->prev->next = (del)->next; \
if ((del) == (head)) (head)=(del)->next; \
} \
} while (0)

CDL delete with alternative ptr names.

Definition at line 763 of file utlist.h.

◆ CDL_FOREACH

#define CDL_FOREACH (   head,
  el 
)     CDL_FOREACH2(head,el,next)

CDL list iteration.

Definition at line 786 of file utlist.h.

◆ CDL_FOREACH2

#define CDL_FOREACH2 (   head,
  el,
  next 
)     for(el=head;el;el=((el)->next==head ? 0L : (el)->next))

CDL list iteration with alternative next ptr name 'next'.

Definition at line 790 of file utlist.h.

◆ CDL_FOREACH_SAFE

#define CDL_FOREACH_SAFE (   head,
  el,
  tmp1,
  tmp2 
)     CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next)

CDL safe list iteration Use if list elements might be deleted while iterating.

Definition at line 797 of file utlist.h.

◆ CDL_FOREACH_SAFE2

#define CDL_FOREACH_SAFE2 (   head,
  el,
  tmp1,
  tmp2,
  prev,
  next 
)
Value:
for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \
(el) && ((tmp2)=(el)->next, 1); \
((el) = (((el)==(tmp1)) ? 0L : (tmp2))))

CDL safe list iteration with alternative ptr names.

Definition at line 801 of file utlist.h.

◆ CDL_PREPEND

#define CDL_PREPEND (   head,
  add 
)     CDL_PREPEND2(head,add,prev,next)

CDL prepend element 'add' to list.

Definition at line 740 of file utlist.h.

◆ CDL_PREPEND2

#define CDL_PREPEND2 (   head,
  add,
  prev,
  next 
)
Value:
do { \
if (head) { \
(add)->prev = (head)->prev; \
(add)->next = (head); \
(head)->prev = (add); \
(add)->prev->next = (add); \
} else { \
(add)->prev = (add); \
(add)->next = (add); \
} \
(head)=(add); \
} while (0)

CDL prepend to list with alternative ptr names.

Definition at line 744 of file utlist.h.

◆ CDL_PREPEND_ELEM

#define CDL_PREPEND_ELEM (   head,
  el,
  add 
)
Value:
do { \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
(add)->next = (el); \
(add)->prev = (el)->prev; \
(el)->prev = (add); \
(add)->prev->next = (add); \
if ((head) == (el)) { \
(head) = (add); \
} \
} while (0)

CDL prepend new element 'add' to element 'el' in list.

Definition at line 852 of file utlist.h.

◆ CDL_REPLACE_ELEM

#define CDL_REPLACE_ELEM (   head,
  el,
  add 
)
Value:
do { \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
if ((el)->next == (el)) { \
(add)->next = (add); \
(add)->prev = (add); \
(head) = (add); \
} else { \
(add)->next = (el)->next; \
(add)->prev = (el)->prev; \
(add)->next->prev = (add); \
(add)->prev->next = (add); \
if ((head) == (el)) { \
(head) = (add); \
} \
} \
} while (0)

CDL replace element 'el' with element 'add' in list.

Definition at line 831 of file utlist.h.

◆ CDL_SEARCH

#define CDL_SEARCH (   head,
  out,
  elt,
  cmp 
)     CDL_SEARCH2(head,out,elt,cmp,next)

CDL search element 'elt' in list using function 'cmp'.

Definition at line 819 of file utlist.h.

◆ CDL_SEARCH2

#define CDL_SEARCH2 (   head,
  out,
  elt,
  cmp,
  next 
)
Value:
do { \
CDL_FOREACH2(head,out,next) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)

CDL search with alternative next ptr name 'next'.

Definition at line 823 of file utlist.h.

◆ CDL_SEARCH_SCALAR

#define CDL_SEARCH_SCALAR (   head,
  out,
  field,
  val 
)     CDL_SEARCH_SCALAR2(head,out,field,val,next)

CDL scalar search for element with value 'val' for member 'field'.

Definition at line 807 of file utlist.h.

◆ CDL_SEARCH_SCALAR2

#define CDL_SEARCH_SCALAR2 (   head,
  out,
  field,
  val,
  next 
)
Value:
do { \
CDL_FOREACH2(head,out,next) { \
if ((out)->field == (val)) break; \
} \
} while(0)

CDL scalar search with alternative next ptr name 'next'.

Definition at line 811 of file utlist.h.

◆ CDL_SORT

#define CDL_SORT (   list,
  cmp 
)     CDL_SORT2(list, cmp, prev, next)

Definition at line 258 of file utlist.h.

◆ CDL_SORT2

#define CDL_SORT2 (   list,
  cmp,
  prev,
  next 
)

Definition at line 261 of file utlist.h.

◆ DL_APPEND

#define DL_APPEND (   head,
  add 
)     DL_APPEND2(head,add,prev,next)

DL append to append element 'add' to list.

Definition at line 576 of file utlist.h.

◆ DL_APPEND2

#define DL_APPEND2 (   head,
  add,
  prev,
  next 
)
Value:
do { \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev->next = (add); \
(head)->prev = (add); \
(add)->next = NULL; \
} else { \
(head)=(add); \
(head)->prev = (head); \
(head)->next = NULL; \
} \
} while (0)

DL append with alternative next ptr name 'next'.

Definition at line 580 of file utlist.h.

◆ DL_CONCAT

#define DL_CONCAT (   head1,
  head2 
)     DL_CONCAT2(head1,head2,prev,next)

DL concat to append second list to first.

Definition at line 595 of file utlist.h.

◆ DL_CONCAT2

#define DL_CONCAT2 (   head1,
  head2,
  prev,
  next 
)
Value:
do { \
LDECLTYPE(head1) _tmp; \
if (head2) { \
if (head1) { \
_tmp = (head2)->prev; \
(head2)->prev = (head1)->prev; \
(head1)->prev->next = (head2); \
(head1)->prev = _tmp; \
} else { \
(head1)=(head2); \
} \
} \
} while (0)

DL concat with alternative next ptr name 'next'.

Definition at line 599 of file utlist.h.

◆ DL_COUNT

#define DL_COUNT (   head,
  el,
  counter 
)     DL_COUNT2(head,el,counter,next) \

DL count list elements using 'counter'.

Definition at line 638 of file utlist.h.

◆ DL_COUNT2

#define DL_COUNT2 (   head,
  el,
  counter,
  next 
)
Value:
{ \
counter = 0; \
DL_FOREACH2(head,el,next){ ++counter; } \
}

DL count with alternative next ptr name 'next'.

Definition at line 642 of file utlist.h.

◆ DL_DELETE

#define DL_DELETE (   head,
  del 
)     DL_DELETE2(head,del,prev,next)

DL delete element 'del' from list.

Definition at line 615 of file utlist.h.

◆ DL_DELETE2

#define DL_DELETE2 (   head,
  del,
  prev,
  next 
)
Value:
do { \
assert((del)->prev != NULL); \
if ((del)->prev == (del)) { \
(head)=NULL; \
} else if ((del)==(head)) { \
(del)->next->prev = (del)->prev; \
(head) = (del)->next; \
} else { \
(del)->prev->next = (del)->next; \
if ((del)->next) { \
(del)->next->prev = (del)->prev; \
} else { \
(head)->prev = (del)->prev; \
} \
} \
} while (0)

DL delete with alternative ptr names.

Definition at line 619 of file utlist.h.

◆ DL_FOREACH

#define DL_FOREACH (   head,
  el 
)     DL_FOREACH2(head,el,next)

DL list iteration.

Definition at line 649 of file utlist.h.

◆ DL_FOREACH2

#define DL_FOREACH2 (   head,
  el,
  next 
)     for(el=head;el;el=(el)->next)

DL list iteration with alternative next ptr name 'next'.

Definition at line 653 of file utlist.h.

◆ DL_FOREACH_SAFE

#define DL_FOREACH_SAFE (   head,
  el,
  tmp 
)     DL_FOREACH_SAFE2(head,el,tmp,next)

DL safe list iteration Use if list elements might be deleted while iterating.

Definition at line 660 of file utlist.h.

◆ DL_FOREACH_SAFE2

#define DL_FOREACH_SAFE2 (   head,
  el,
  tmp,
  next 
)     for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)

DL safe list iteration with alternative ptr names.

Definition at line 664 of file utlist.h.

◆ DL_PREPEND

#define DL_PREPEND (   head,
  add 
)     DL_PREPEND2(head,add,prev,next)

DL prepend element 'add' to list.

Definition at line 559 of file utlist.h.

◆ DL_PREPEND2

#define DL_PREPEND2 (   head,
  add,
  prev,
  next 
)
Value:
do { \
(add)->next = head; \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev = (add); \
} else { \
(add)->prev = (add); \
} \
(head) = (add); \
} while (0)

DL prepend to list with alternative ptr names.

Definition at line 563 of file utlist.h.

◆ DL_PREPEND_ELEM

#define DL_PREPEND_ELEM (   head,
  el,
  add 
)
Value:
do { \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
(add)->next = (el); \
(add)->prev = (el)->prev; \
(el)->prev = (add); \
if ((head) == (el)) { \
(head) = (add); \
} else { \
(add)->prev->next = (add); \
} \
} while (0)

DL prepend new element 'add' to element 'el' in list.

Definition at line 719 of file utlist.h.

◆ DL_REPLACE_ELEM

#define DL_REPLACE_ELEM (   head,
  el,
  add 
)
Value:
do { \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
if ((head) == (el)) { \
(head) = (add); \
(add)->next = (el)->next; \
if ((el)->next == NULL) { \
(add)->prev = (add); \
} else { \
(add)->prev = (el)->prev; \
(add)->next->prev = (add); \
} \
} else { \
(add)->next = (el)->next; \
(add)->prev = (el)->prev; \
(add)->prev->next = (add); \
if ((el)->next == NULL) { \
(head)->prev = (add); \
} else { \
(add)->next->prev = (add); \
} \
} \
} while (0)

DL replace element 'el' with element 'add' in list.

Definition at line 692 of file utlist.h.

◆ DL_SEARCH

#define DL_SEARCH   LL_SEARCH

DL search element 'elt' in list using function 'cmp' Identical to singly-linked counterpart.

Definition at line 683 of file utlist.h.

◆ DL_SEARCH2

#define DL_SEARCH2   LL_SEARCH2

DL search with alternative next ptr name 'next' Identical to singly-linked counterpart.

Definition at line 689 of file utlist.h.

◆ DL_SEARCH_SCALAR

#define DL_SEARCH_SCALAR   LL_SEARCH_SCALAR

DL scalar search for element with value 'val' for member 'field' Identical to singly-linked counterpart.

Definition at line 671 of file utlist.h.

◆ DL_SEARCH_SCALAR2

#define DL_SEARCH_SCALAR2   LL_SEARCH_SCALAR2

DL scalar search with alternative next ptr name 'next' Identical to singly-linked counterpart.

Definition at line 677 of file utlist.h.

◆ DL_SORT

#define DL_SORT (   list,
  cmp 
)     DL_SORT2(list, cmp, prev, next)

Definition at line 196 of file utlist.h.

◆ DL_SORT2

#define DL_SORT2 (   list,
  cmp,
  prev,
  next 
)

Definition at line 199 of file utlist.h.

◆ LDECLTYPE

#define LDECLTYPE (   x)    __typeof(x)

Definition at line 105 of file utlist.h.

◆ LL_APPEND

#define LL_APPEND (   head,
  add 
)     LL_APPEND2(head,add,next)

LL append to append element 'add' to list.

Definition at line 368 of file utlist.h.

◆ LL_APPEND2

#define LL_APPEND2 (   head,
  add,
  next 
)
Value:
do { \
LDECLTYPE(head) _tmp; \
(add)->next=NULL; \
if (head) { \
_tmp = head; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(add); \
} else { \
(head)=(add); \
} \
} while (0)

LL append with alternative next ptr name 'next'.

Definition at line 372 of file utlist.h.

◆ LL_APPEND2_VS2008

#define LL_APPEND2_VS2008 (   head,
  add,
  next 
)
Value:
do { \
if (head) { \
(add)->next = head; /* use add->next as a temp variable */ \
while ((add)->next->next) { (add)->next = (add)->next->next; } \
(add)->next->next=(add); \
} else { \
(head)=(add); \
} \
(add)->next=NULL; \
} while (0)

Definition at line 410 of file utlist.h.

◆ LL_APPEND_VS2008

#define LL_APPEND_VS2008 (   head,
  add 
)     LL_APPEND2_VS2008(head,add,next)

Definition at line 407 of file utlist.h.

◆ LL_CONCAT

#define LL_CONCAT (   head1,
  head2 
)     LL_CONCAT2(head1,head2,next)

LL concat to append second list to first.

Definition at line 351 of file utlist.h.

◆ LL_CONCAT2

#define LL_CONCAT2 (   head1,
  head2,
  next 
)
Value:
do { \
LDECLTYPE(head1) _tmp; \
if (head1) { \
_tmp = head1; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(head2); \
} else { \
(head1)=(head2); \
} \
} while (0)

LL concat with alternative next ptr name 'next'.

Definition at line 355 of file utlist.h.

◆ LL_COUNT

#define LL_COUNT (   head,
  el,
  counter 
)     LL_COUNT2(head,el,counter,next) \

LL count list elements using 'counter'.

Definition at line 458 of file utlist.h.

◆ LL_COUNT2

#define LL_COUNT2 (   head,
  el,
  counter,
  next 
)
Value:
{ \
counter = 0; \
LL_FOREACH2(head,el,next){ ++counter; } \
}

LL count with alternative next ptr name 'next'.

Definition at line 462 of file utlist.h.

◆ LL_DELETE

#define LL_DELETE (   head,
  del 
)     LL_DELETE2(head,del,next)

LL delete element 'del' from list.

Definition at line 386 of file utlist.h.

◆ LL_DELETE2

#define LL_DELETE2 (   head,
  del,
  next 
)
Value:
do { \
LDECLTYPE(head) _tmp; \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
_tmp = head; \
while (_tmp->next && (_tmp->next != (del))) { \
_tmp = _tmp->next; \
} \
if (_tmp->next) { \
_tmp->next = ((del)->next); \
} \
} \
} while (0)

LL delete with alternative next ptr name 'name'.

Definition at line 390 of file utlist.h.

◆ LL_DELETE2_VS2008

#define LL_DELETE2_VS2008 (   head,
  del,
  next 
)
Value:
do { \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
char *_tmp = (char*)(head); \
while ((head)->next && ((head)->next != (del))) { \
head = (head)->next; \
} \
if ((head)->next) { \
(head)->next = ((del)->next); \
} \
{ \
char **_head_alias = (char**)&(head); \
*_head_alias = _tmp; \
} \
} \
} while (0)

Definition at line 425 of file utlist.h.

◆ LL_DELETE_VS2008

#define LL_DELETE_VS2008 (   head,
  del 
)     LL_DELETE2_VS2008(head,del,next)

Definition at line 422 of file utlist.h.

◆ LL_FOREACH

#define LL_FOREACH (   head,
  el 
)     LL_FOREACH2(head,el,next)

LL list iteration.

Definition at line 469 of file utlist.h.

◆ LL_FOREACH2

#define LL_FOREACH2 (   head,
  el,
  next 
)     for(el=head;el;el=(el)->next)

LL list iteration with alternative next ptr name 'next'.

Definition at line 473 of file utlist.h.

◆ LL_FOREACH_SAFE

#define LL_FOREACH_SAFE (   head,
  el,
  tmp 
)     LL_FOREACH_SAFE2(head,el,tmp,next)

LL safe list iteration Use if list elements might be deleted while iterating.

Definition at line 480 of file utlist.h.

◆ LL_FOREACH_SAFE2

#define LL_FOREACH_SAFE2 (   head,
  el,
  tmp,
  next 
)     for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)

LL safe list iteration with alternative ptr names.

Definition at line 484 of file utlist.h.

◆ LL_PREPEND

#define LL_PREPEND (   head,
  add 
)     LL_PREPEND2(head,add,next)

LL prepend element 'add' to list.

Definition at line 340 of file utlist.h.

◆ LL_PREPEND2

#define LL_PREPEND2 (   head,
  add,
  next 
)
Value:
do { \
(add)->next = head; \
head = add; \
} while (0)

LL prepend to list with alternative next ptr name 'next'.

Definition at line 344 of file utlist.h.

◆ LL_PREPEND_ELEM

#define LL_PREPEND_ELEM (   head,
  el,
  add 
)
Value:
do { \
LDECLTYPE(head) _tmp; \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
(add)->next = (el); \
if ((head) == (el)) { \
(head) = (add); \
} else { \
_tmp = head; \
while (_tmp->next && (_tmp->next != (el))) { \
_tmp = _tmp->next; \
} \
if (_tmp->next) { \
_tmp->next = (add); \
} \
} \
} while (0)

LL prepend new element 'add' to element 'el' in list.

Definition at line 533 of file utlist.h.

◆ LL_REPLACE_ELEM

#define LL_REPLACE_ELEM (   head,
  el,
  add 
)
Value:
do { \
LDECLTYPE(head) _tmp; \
assert(head != NULL); \
assert(el != NULL); \
assert(add != NULL); \
(add)->next = (el)->next; \
if ((head) == (el)) { \
(head) = (add); \
} else { \
_tmp = head; \
while (_tmp->next && (_tmp->next != (el))) { \
_tmp = _tmp->next; \
} \
if (_tmp->next) { \
_tmp->next = (add); \
} \
} \
} while (0)

LL replace element 'el' with element 'add' in list.

Definition at line 512 of file utlist.h.

◆ LL_SEARCH

#define LL_SEARCH (   head,
  out,
  elt,
  cmp 
)     LL_SEARCH2(head,out,elt,cmp,next)

LL search element 'elt' in list using function 'cmp'.

Definition at line 500 of file utlist.h.

◆ LL_SEARCH2

#define LL_SEARCH2 (   head,
  out,
  elt,
  cmp,
  next 
)
Value:
do { \
LL_FOREACH2(head,out,next) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)

LL search with alternative next ptr name 'next'.

Definition at line 504 of file utlist.h.

◆ LL_SEARCH_SCALAR

#define LL_SEARCH_SCALAR (   head,
  out,
  field,
  val 
)     LL_SEARCH_SCALAR2(head,out,field,val,next)

LL scalar search for element with value 'val' for member 'field'.

Definition at line 488 of file utlist.h.

◆ LL_SEARCH_SCALAR2

#define LL_SEARCH_SCALAR2 (   head,
  out,
  field,
  val,
  next 
)
Value:
do { \
LL_FOREACH2(head,out,next) { \
if ((out)->field == (val)) break; \
} \
} while(0)

LL scalar search with alternative next ptr name 'next'.

Definition at line 492 of file utlist.h.

◆ LL_SORT

#define LL_SORT (   list,
  cmp 
)     LL_SORT2(list, cmp, next)

Definition at line 134 of file utlist.h.

◆ LL_SORT2

#define LL_SORT2 (   list,
  cmp,
  next 
)

Definition at line 137 of file utlist.h.

◆ UTLIST_VERSION

#define UTLIST_VERSION   1.9.9

Version number.

Definition at line 41 of file utlist.h.