[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: add generic insertion sort
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: add generic insertion sort logic |
Date: |
Wed, 25 Jan 2017 14:41:23 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 0b6a79bd6 add generic insertion sort logic
new 4195db9b1 add generic insertion sort logic
0b6a79bd6 is described below
commit 0b6a79bd69c8fbeb64fa0be14647fd2ee61ef043
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed Jan 25 14:41:00 2017 +0100
add generic insertion sort logic
---
src/include/gnunet_container_lib.h | 49 ++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/src/include/gnunet_container_lib.h
b/src/include/gnunet_container_lib.h
index f3aaa943b..d2f8c5d9c 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -2073,6 +2073,55 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct
GNUNET_CONTAINER_MultiH
+/**
+ * Insertion sort of @a element into DLL from @a head to @a tail
+ * sorted by @a comparator.
+ *
+ * @param TYPE element type of the elements, i.e. `struct ListElement`
+ * @param comparator function like memcmp() to compare elements; takes
+ * three arguments, the @a comparator_cls and two elements,
+ * returns an `int` (-1, 0 or 1)
+ * @param comparator_cls closure for @a comparator
+ * @param[in,out] head head of DLL
+ * @param[in,out] tail tail of DLL
+ * @param element element to insert
+ */
+#define
GNUNET_CONTAINER_DLL_insert_sorted(TYPE,comparator,comparator_cls,head,tail,element)
do { \
+ if ( (NULL == head) || \
+ (0 < comparator (comparator_cls, \
+ element, \
+ head)) ) \
+ { \
+ /* insert at head, e;e,emt < head */ \
+ GNUNET_CONTAINER_DLL_insert (head, \
+ tail, \
+ element); \
+ } \
+ else \
+ { \
+ TYPE *pos; \
+ \
+ for (pos = head; \
+ NULL != pos; \
+ pos = pos->next) \
+ if (0 < \
+ comparator (comparator_cls, \
+ element, \
+ pos)) \
+ break; /* element < pos */ \
+ if (NULL == pos) /* => element > tail */ \
+ GNUNET_CONTAINER_DLL_insert_tail (head, \
+ tail, \
+ element); \
+ else /* prev < element < pos */ \
+ GNUNET_CONTAINER_DLL_insert_after (head, \
+ tail, \
+ element, \
+ pos->prev); \
+ } \
+ } while (0)
+
+
/* ******************** Heap *************** */
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: add generic insertion sort logic,
gnunet <=