[augeas-devel] [PATCH 1 of 4] Add list_reverse and list_tail_cons
David Lutterkort
dlutter at redhat.com
Fri Aug 8 22:46:23 UTC 2008
1 file changed, 30 insertions(+)
src/list.h | 30 ++++++++++++++++++++++++++++++
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1218235118 25200
# Node ID 30fe26d31d9e9f7bd24539870f47727a8677ddd2
# Parent 10f6354c863e1feba41daa86e9d475c25007c0c2
Add list_reverse and list_tail_cons
list_reverse reverses a list in place. list_tail_cons appends to a list in
constant time, since it is given a pointer to the tail of the list.
diff -r 10f6354c863e -r 30fe26d31d9e src/list.h
--- a/src/list.h Thu Aug 07 18:06:22 2008 -0700
+++ b/src/list.h Fri Aug 08 15:38:38 2008 -0700
@@ -94,6 +94,36 @@
(list) = _e; \
} while(0)
+#define list_reverse(list) \
+ do { \
+ typeof(list) _head = (list); \
+ typeof(list) _prev = NULL; \
+ while (_head != NULL) { \
+ typeof(list) _next = _head->next; \
+ _head->next = _prev; \
+ _prev = _head; \
+ _head = _next; \
+ } \
+ (list) = _prev; \
+ } while (0)
+
+/* Append ELT to the end of LIST. TAIL must be NULL or a pointer to
+ the last element of LIST
+*/
+#define list_tail_cons(list, tail, elt) \
+ do { \
+ if ((list) == NULL) { \
+ (list) = (elt); \
+ (tail) = (list); \
+ } else { \
+ if ((tail) == NULL) \
+ for ((tail) = (list); (tail)->next != NULL; \
+ (tail) = (tail)->next); \
+ (tail)->next = (elt); \
+ (tail) = (elt); \
+ } \
+ } while(0)
+
/*
* Local variables:
* indent-tabs-mode: nil
More information about the augeas-devel
mailing list