diff options
author | Nils Durner <durner@gnunet.org> | 2009-10-03 15:36:09 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2009-10-03 15:36:09 +0000 |
commit | d5f3c16326273625b37cd0f2d5b4716ac650f51d (patch) | |
tree | 558efc6c02137036c8984fdb24b966117e3470d2 /src/include/gnunet_container_lib.h | |
parent | 382d50480d96cbd5b5b7a45997cfe6f33b914a3b (diff) | |
download | gnunet-d5f3c16326273625b37cd0f2d5b4716ac650f51d.tar.gz gnunet-d5f3c16326273625b37cd0f2d5b4716ac650f51d.zip |
use singly linked lists instead of vectors
Diffstat (limited to 'src/include/gnunet_container_lib.h')
-rw-r--r-- | src/include/gnunet_container_lib.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index bbf1ba2cf..8abf10e21 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h | |||
@@ -42,6 +42,10 @@ extern "C" | |||
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | 44 | ||
45 | #define GNUNET_MEM_DISP_TRANSIENT 0 | ||
46 | #define GNUNET_MEM_DISP_STATIC 2 | ||
47 | #define GNUNET_MEM_DISP_DYNAMIC 4 | ||
48 | |||
45 | /* ******************* bloomfilter ***************** */ | 49 | /* ******************* bloomfilter ***************** */ |
46 | 50 | ||
47 | /** | 51 | /** |
@@ -870,6 +874,101 @@ void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap | |||
870 | unsigned int | 874 | unsigned int |
871 | GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap); | 875 | GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap); |
872 | 876 | ||
877 | /* ******************** Singly linked list *************** */ | ||
878 | |||
879 | /* Handle to a singly linked list */ | ||
880 | struct GNUNET_CONTAINER_SList; | ||
881 | |||
882 | /* Handle to a singly linked list iterator */ | ||
883 | struct GNUNET_CONTAINER_SList_Iterator; | ||
884 | |||
885 | |||
886 | /** | ||
887 | * Add a new element to the list | ||
888 | * @param l list | ||
889 | * @param disp memory disposition | ||
890 | * @param buf payload buffer | ||
891 | * @param len length of the buffer | ||
892 | */ | ||
893 | void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, int disp, const void *buf, size_t len); | ||
894 | |||
895 | /** | ||
896 | * Create a new singly linked list | ||
897 | * @return the new list | ||
898 | */ | ||
899 | struct GNUNET_CONTAINER_SList *GNUNET_CONTAINER_slist_create (); | ||
900 | |||
901 | /** | ||
902 | * Destroy a singly linked list | ||
903 | * @param l the list to be destroyed | ||
904 | */ | ||
905 | void GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l); | ||
906 | |||
907 | /** | ||
908 | * Return the beginning of a list | ||
909 | * @param l list | ||
910 | * @return iterator pointing to the beginning | ||
911 | */ | ||
912 | const struct GNUNET_CONTAINER_SList_Iterator *GNUNET_CONTAINER_slist_begin(const struct GNUNET_CONTAINER_SList *l); | ||
913 | |||
914 | /** | ||
915 | * Clear a list | ||
916 | * @param l list | ||
917 | */ | ||
918 | void GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l); | ||
919 | |||
920 | /** | ||
921 | * Check if a list contains a certain element | ||
922 | * @param l list | ||
923 | * @param buf payload buffer to find | ||
924 | * @param lenght of the payload | ||
925 | */ | ||
926 | int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, const void *buf, size_t len); | ||
927 | |||
928 | /** | ||
929 | * Count the elements of a list | ||
930 | * @param l list | ||
931 | * @return number of elements in the list | ||
932 | */ | ||
933 | int GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l); | ||
934 | |||
935 | /** | ||
936 | * Remove an element from the list | ||
937 | * @param i iterator that points to the element to be removed | ||
938 | */ | ||
939 | void GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i); | ||
940 | |||
941 | /** | ||
942 | * Insert an element into a list at a specific position | ||
943 | * @param before where to insert the new element | ||
944 | * @param disp memory disposition | ||
945 | * @param buf payload buffer | ||
946 | * @param len length of the payload | ||
947 | */ | ||
948 | void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, int disp, const void *buf, size_t len); | ||
949 | |||
950 | /** | ||
951 | * Advance an iterator to the next element | ||
952 | * @param i iterator | ||
953 | * @return GNUNET_YES on success, GNUNET_NO if the end has been reached | ||
954 | */ | ||
955 | int GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i); | ||
956 | |||
957 | /** | ||
958 | * Check if an iterator points beyond the end of a list | ||
959 | * @param i iterator | ||
960 | * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator | ||
961 | * points to a valid element | ||
962 | */ | ||
963 | int GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i); | ||
964 | |||
965 | /** | ||
966 | * Retrieve the element at a specific position in a list | ||
967 | * @param i iterator | ||
968 | * @param len payload length | ||
969 | * @return payload | ||
970 | */ | ||
971 | void *GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, size_t *len); | ||
873 | 972 | ||
874 | 973 | ||
875 | #if 0 /* keep Emacsens' auto-indent happy */ | 974 | #if 0 /* keep Emacsens' auto-indent happy */ |