diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-23 18:12:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-23 18:12:22 +0000 |
commit | b38b47339b7c806432f251a566c857eb64c6e8cf (patch) | |
tree | 026f34cd672fab22a8453c5f3aee979609f507de /src/include | |
parent | cbaa6d6444ce82bea7761268ad61e9af477b2d42 (diff) | |
download | gnunet-b38b47339b7c806432f251a566c857eb64c6e8cf.tar.gz gnunet-b38b47339b7c806432f251a566c857eb64c6e8cf.zip |
-introducing MDLL macros
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_container_lib.h | 125 | ||||
-rw-r--r-- | src/include/platform.h | 2 |
2 files changed, 126 insertions, 1 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index a476b7f1b..2da177f16 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h | |||
@@ -832,6 +832,131 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct | |||
832 | (element)->prev = NULL; } while (0) | 832 | (element)->prev = NULL; } while (0) |
833 | 833 | ||
834 | 834 | ||
835 | /* ************ Multi-DLL interface, allows DLL elements to be | ||
836 | in multiple lists at the same time *********************** */ | ||
837 | |||
838 | /** | ||
839 | * Insert an element at the head of a MDLL. Assumes that head, tail and | ||
840 | * element are structs with prev and next fields. | ||
841 | * | ||
842 | * @param head pointer to the head of the MDLL | ||
843 | * @param tail pointer to the tail of the MDLL | ||
844 | * @param element element to insert | ||
845 | */ | ||
846 | #define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \ | ||
847 | GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ | ||
848 | GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ | ||
849 | (element)->next_##mdll = (head); \ | ||
850 | (element)->prev_##mdll = NULL; \ | ||
851 | if ((tail) == NULL) \ | ||
852 | (tail) = element; \ | ||
853 | else \ | ||
854 | (head)->prev_##mdll = element; \ | ||
855 | (head) = (element); } while (0) | ||
856 | |||
857 | |||
858 | /** | ||
859 | * Insert an element at the tail of a MDLL. Assumes that head, tail and | ||
860 | * element are structs with prev and next fields. | ||
861 | * | ||
862 | * @param head pointer to the head of the MDLL | ||
863 | * @param tail pointer to the tail of the MDLL | ||
864 | * @param element element to insert | ||
865 | */ | ||
866 | #define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \ | ||
867 | GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ | ||
868 | GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ | ||
869 | (element)->prev_##mdll = (tail); \ | ||
870 | (element)->next_##mdll = NULL; \ | ||
871 | if ((head) == NULL) \ | ||
872 | (head) = element; \ | ||
873 | else \ | ||
874 | (tail)->next_##mdll = element; \ | ||
875 | (tail) = (element); } while (0) | ||
876 | |||
877 | |||
878 | /** | ||
879 | * Insert an element into a MDLL after the given other element. Insert | ||
880 | * at the head if the other element is NULL. | ||
881 | * | ||
882 | * @param head pointer to the head of the MDLL | ||
883 | * @param tail pointer to the tail of the MDLL | ||
884 | * @param other prior element, NULL for insertion at head of MDLL | ||
885 | * @param element element to insert | ||
886 | */ | ||
887 | #define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \ | ||
888 | GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ | ||
889 | GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ | ||
890 | (element)->prev_##mdll = (other); \ | ||
891 | if (NULL == other) \ | ||
892 | { \ | ||
893 | (element)->next_##mdll = (head); \ | ||
894 | (head) = (element); \ | ||
895 | } \ | ||
896 | else \ | ||
897 | { \ | ||
898 | (element)->next_##mdll = (other)->next_##mdll; \ | ||
899 | (other)->next_##mdll = (element); \ | ||
900 | } \ | ||
901 | if (NULL == (element)->next_##mdll) \ | ||
902 | (tail) = (element); \ | ||
903 | else \ | ||
904 | (element)->next->prev_##mdll = (element); } while (0) | ||
905 | |||
906 | |||
907 | /** | ||
908 | * Insert an element into a MDLL before the given other element. Insert | ||
909 | * at the tail if the other element is NULL. | ||
910 | * | ||
911 | * @param head pointer to the head of the MDLL | ||
912 | * @param tail pointer to the tail of the MDLL | ||
913 | * @param other prior element, NULL for insertion at head of MDLL | ||
914 | * @param element element to insert | ||
915 | */ | ||
916 | #define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \ | ||
917 | GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ | ||
918 | GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ | ||
919 | (element)->next_##mdll = (other); \ | ||
920 | if (NULL == other) \ | ||
921 | { \ | ||
922 | (element)->prev = (tail); \ | ||
923 | (tail) = (element); \ | ||
924 | } \ | ||
925 | else \ | ||
926 | { \ | ||
927 | (element)->prev_##mdll = (other)->prev_##mdll; \ | ||
928 | (other)->prev_##mdll = (element); \ | ||
929 | } \ | ||
930 | if (NULL == (element)->prev_##mdll) \ | ||
931 | (head) = (element); \ | ||
932 | else \ | ||
933 | (element)->prev_##mdll->next_##mdll = (element); } while (0) | ||
934 | |||
935 | |||
936 | /** | ||
937 | * Remove an element from a MDLL. Assumes | ||
938 | * that head, tail and element are structs | ||
939 | * with prev and next fields. | ||
940 | * | ||
941 | * @param head pointer to the head of the MDLL | ||
942 | * @param tail pointer to the tail of the MDLL | ||
943 | * @param element element to remove | ||
944 | */ | ||
945 | #define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \ | ||
946 | GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \ | ||
947 | GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \ | ||
948 | if ((element)->prev_##mdll == NULL) \ | ||
949 | (head) = (element)->next_##mdll; \ | ||
950 | else \ | ||
951 | (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \ | ||
952 | if ((element)->next_##mdll == NULL) \ | ||
953 | (tail) = (element)->prev_##mdll; \ | ||
954 | else \ | ||
955 | (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \ | ||
956 | (element)->next_##mdll = NULL; \ | ||
957 | (element)->prev_##mdll = NULL; } while (0) | ||
958 | |||
959 | |||
835 | 960 | ||
836 | /* ******************** Heap *************** */ | 961 | /* ******************** Heap *************** */ |
837 | 962 | ||
diff --git a/src/include/platform.h b/src/include/platform.h index 8bd2e6706..912601dad 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -50,7 +50,7 @@ | |||
50 | #include <sys/types.h> | 50 | #include <sys/types.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #define ALLOW_EXTRA_CHECKS GNUNET_NO | 53 | #define ALLOW_EXTRA_CHECKS GNUNET_YES |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * For strptime (glibc2 needs this). | 56 | * For strptime (glibc2 needs this). |