aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_container_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_container_lib.h')
-rw-r--r--src/include/gnunet_container_lib.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index f3aaa943b..c77d82fd3 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -2073,6 +2073,59 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
2073 2073
2074 2074
2075 2075
2076/**
2077 * Insertion sort of @a element into DLL from @a head to @a tail
2078 * sorted by @a comparator.
2079 *
2080 * @param TYPE element type of the elements, i.e. `struct ListElement`
2081 * @param comparator function like memcmp() to compare elements; takes
2082 * three arguments, the @a comparator_cls and two elements,
2083 * returns an `int` (-1, 0 or 1)
2084 * @param comparator_cls closure for @a comparator
2085 * @param[in,out] head head of DLL
2086 * @param[in,out] tail tail of DLL
2087 * @param element element to insert
2088 */
2089#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE,comparator,comparator_cls,head,tail,element) do { \
2090 if ( (NULL == head) || \
2091 (0 < comparator (comparator_cls, \
2092 element, \
2093 head)) ) \
2094 { \
2095 /* insert at head, element < head */ \
2096 GNUNET_CONTAINER_DLL_insert (head, \
2097 tail, \
2098 element); \
2099 } \
2100 else \
2101 { \
2102 TYPE *pos; \
2103 \
2104 for (pos = head; \
2105 NULL != pos; \
2106 pos = pos->next) \
2107 if (0 < \
2108 comparator (comparator_cls, \
2109 element, \
2110 pos)) \
2111 break; /* element < pos */ \
2112 if (NULL == pos) /* => element > tail */ \
2113 { \
2114 GNUNET_CONTAINER_DLL_insert_tail (head, \
2115 tail, \
2116 element); \
2117 } \
2118 else /* prev < element < pos */ \
2119 { \
2120 GNUNET_CONTAINER_DLL_insert_after (head, \
2121 tail, \
2122 pos->prev, \
2123 element); \
2124 } \
2125 } \
2126} while (0)
2127
2128
2076/* ******************** Heap *************** */ 2129/* ******************** Heap *************** */
2077 2130
2078 2131