ESAPI-C 1.0
The OWASP Enterprise Security API for C
|
A linked list implementation using macros. More...
Go to the source code of this file.
Defines | |
#define | UTLIST_VERSION 1.9.1 |
#define | LDECLTYPE(x) __typeof(x) |
This file contains macros to manipulate singly and doubly-linked lists. | |
#define | _SV(elt, list) |
#define | _NEXT(elt, list) ((elt)->next) |
#define | _NEXTASGN(elt, list, to) ((elt)->next)=(to) |
#define | _PREV(elt, list) ((elt)->prev) |
#define | _PREVASGN(elt, list, to) ((elt)->prev)=(to) |
#define | _RS(list) |
#define | _CASTASGN(a, b) (a)=(b) |
#define | LL_SORT(list, cmp) |
#define | DL_SORT(list, cmp) |
#define | CDL_SORT(list, cmp) |
#define | LL_PREPEND(head, add) |
#define | LL_APPEND(head, add) |
#define | LL_DELETE(head, del) |
#define | LL_APPEND_VS2008(head, add) |
#define | LL_DELETE_VS2008(head, del) |
#define | LL_FOREACH(head, el) for(el=head;el;el=el->next) |
#define | LL_FOREACH_SAFE(head, el, tmp) for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) |
#define | LL_SEARCH_SCALAR(head, out, field, val) |
#define | LL_SEARCH(head, out, elt, cmp) |
#define | DL_PREPEND(head, add) |
#define | DL_APPEND(head, add) |
#define | DL_DELETE(head, del) |
#define | DL_FOREACH(head, el) for(el=head;el;el=el->next) |
#define | DL_FOREACH_SAFE(head, el, tmp) for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) |
#define | DL_SEARCH_SCALAR LL_SEARCH_SCALAR |
#define | DL_SEARCH LL_SEARCH |
#define | CDL_PREPEND(head, add) |
#define | CDL_DELETE(head, del) |
#define | CDL_FOREACH(head, el) for(el=head;el;el=(el->next==head ? 0L : el->next)) |
#define | CDL_FOREACH_SAFE(head, el, tmp1, tmp2) |
#define | CDL_SEARCH_SCALAR(head, out, field, val) |
#define | CDL_SEARCH(head, out, elt, cmp) |
A linked list implementation using macros.
Definition in file utlist.h.
#define CDL_DELETE | ( | head, | |
del | |||
) |
#define CDL_FOREACH_SAFE | ( | head, | |
el, | |||
tmp1, | |||
tmp2 | |||
) |
#define CDL_PREPEND | ( | head, | |
add | |||
) |
#define CDL_SEARCH | ( | head, | |
out, | |||
elt, | |||
cmp | |||
) |
#define CDL_SEARCH_SCALAR | ( | head, | |
out, | |||
field, | |||
val | |||
) |
#define DL_APPEND | ( | head, | |
add | |||
) |
#define DL_DELETE | ( | head, | |
del | |||
) |
do { \ 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);
#define DL_PREPEND | ( | head, | |
add | |||
) |
#define LDECLTYPE | ( | x | ) | __typeof(x) |
This file contains macros to manipulate singly and doubly-linked lists.
1. LL_ macros: singly-linked lists. 2. DL_ macros: doubly-linked lists. 3. CDL_ macros: circular doubly-linked lists.
To use singly-linked lists, your structure must have a "next" pointer. To use doubly-linked lists, your structure must "prev" and "next" pointers. Either way, the pointer to the head of the list must be initialized to NULL.
----------------.EXAMPLE ------------------------- struct item { int id; struct item *prev, *next; }
struct item *list = NULL:
int main() { struct item *item; ... allocate and populate item ... DL_APPEND(list, item); } --------------------------------------------------
For doubly-linked lists, the append and delete macros are O(1) For singly-linked lists, append and delete are O(n) but prepend is O(1) The sort macro is O(n log(n)) for all types of single/double/circular lists.
#define LL_APPEND | ( | head, | |
add | |||
) |
#define LL_APPEND_VS2008 | ( | head, | |
add | |||
) |
#define LL_DELETE | ( | head, | |
del | |||
) |
#define LL_DELETE_VS2008 | ( | head, | |
del | |||
) |
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)
#define LL_PREPEND | ( | head, | |
add | |||
) |
#define LL_SEARCH | ( | head, | |
out, | |||
elt, | |||
cmp | |||
) |
#define LL_SEARCH_SCALAR | ( | head, | |
out, | |||
field, | |||
val | |||
) |
#define UTLIST_VERSION 1.9.1 |
Copyright (c) 2007-2010, Troy D. Hanson http://uthash.sourceforge.net All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.