GNUnet 0.21.0
MultiHashMap

Hash map with multiple values per key. More...

Collaboration diagram for MultiHashMap:

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIteratorCallback) (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_PeerMapIterator) (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_ShortmapIterator) (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback) (void *cls, const struct GNUNET_Uuid *key, void *value)
 Iterator over uuid map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIterator32Callback) (void *cls, uint32_t key, void *value)
 Iterator over hash map entries. More...
 

Enumerations

enum  GNUNET_CONTAINER_MultiHashMapOption { GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE , GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE , GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY , GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST }
 Options for storing values in the HashMap. More...
 

Functions

struct GNUNET_CONTAINER_MultiHashMapGNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi hash map. More...
 
void GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Remove all entries for the given key from the map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map)
 Remove all entries from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiHashMapIteratorGNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, struct GNUNET_HashCode *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
 Destroy a multihashmap iterator. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiPeerMapGNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
int GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiPeerMapIteratorGNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, struct GNUNET_PeerIdentity *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter)
 Destroy a multipeermap iterator. More...
 
int GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiShortmapGNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Given a key find a value in the map matching the key. More...
 
int GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Remove all entries for the given key from the map. More...
 
int GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
int GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiShortmapIteratorGNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, struct GNUNET_ShortHashCode *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter)
 Destroy a multishortmap iterator. More...
 
int GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiUuidmapGNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multiuuidmap_destroy (struct GNUNET_CONTAINER_MultiUuidmap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multiuuidmap_get (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multiuuidmap_remove_all (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains_value (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_put (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multiuuidmap_size (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Get the number of key-value pairs in the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterate (struct GNUNET_CONTAINER_MultiUuidmap *map, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiUuidmapIteratorGNUNET_CONTAINER_multiuuidmap_iterator_create (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterator_next (struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, struct GNUNET_Uuid *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multiuuidmap_iterator_destroy (struct GNUNET_CONTAINER_MultiUuidmapIterator *iter)
 Destroy a multiuuidmap iterator. More...
 
int GNUNET_CONTAINER_multiuuidmap_get_multiple (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multiuuidmap_get_random (const struct GNUNET_CONTAINER_MultiUuidmap *map, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiHashMap32GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
 Create a 32-bit key multi hash map. More...
 
void GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 *map)
 Destroy a 32-bit key hash map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap32_size (const struct GNUNET_CONTAINER_MultiHashMap32 *map)
 Get the number of key-value pairs in the map. More...
 
void * GNUNET_CONTAINER_multihashmap32_get (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Given a key find a value in the map matching the key. More...
 
int GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
 Iterate over all entries in the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
int GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 

Detailed Description

Hash map with multiple values per key.

See also
Documentation

Typedef Documentation

◆ GNUNET_CONTAINER_MultiHashMapIteratorCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIteratorCallback) (void *cls, const struct GNUNET_HashCode *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent key code
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 330 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_PeerMapIterator

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_PeerMapIterator) (void *cls, const struct GNUNET_PeerIdentity *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 670 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_ShortmapIterator

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_ShortmapIterator) (void *cls, const struct GNUNET_ShortHashCode *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 953 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiUuidmapIteratorCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback) (void *cls, const struct GNUNET_Uuid *key, void *value)

Iterator over uuid map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1236 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiHashMapIterator32Callback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiHashMapIterator32Callback) (void *cls, uint32_t key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent key code
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1519 of file gnunet_container_lib.h.

Enumeration Type Documentation

◆ GNUNET_CONTAINER_MultiHashMapOption

Options for storing values in the HashMap.

Enumerator
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE 

If a value with the given key exists, replace it.

Note that the old value would NOT be freed by replace (the application has to make sure that this happens if required).

GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE 

Allow multiple values with the same key.

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY 

There must only be one value per key; storing a value should fail if a value under the same key already exists.

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST 

, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY; implemented just like GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE but this option documents better what is intended if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY is what is desired).

Definition at line 357 of file gnunet_container_lib.h.

358{
366
372
379
390};
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.

Function Documentation

◆ GNUNET_CONTAINER_multihashmap_create()

struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi hash map.

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 180 of file container_multihashmap.c.

181{
183
184 GNUNET_assert (len > 0);
186 if (len * sizeof(union MapEntry) > GNUNET_MAX_MALLOC_CHECKED)
187 {
188 size_t s;
189 /* application *explicitly* requested very large map, hopefully
190 it checks the return value... */
191 s = len * sizeof(union MapEntry);
192 if ((s / sizeof(union MapEntry)) != len)
193 return NULL; /* integer overflow on multiplication */
194 if (NULL == (hm->map = GNUNET_malloc_large (s)))
195 {
196 /* out of memory */
198 "Out of memory allocating large hash map (%u entries)\n",
199 len);
200 GNUNET_free (hm);
201 return NULL;
202 }
203 }
204 else
205 {
206 hm->map = GNUNET_new_array (len, union MapEntry);
207 }
208 hm->map_length = len;
209 hm->use_small_entries = do_not_copy_keys;
210 return hm;
211}
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Internal representation of the hash map.
union MapEntry * map
All of our buckets.
unsigned int map_length
Length of the "map" array.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
Entry in the map.

References GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc_large, GNUNET_MAX_MALLOC_CHECKED, GNUNET_new, GNUNET_new_array, GNUNET_CONTAINER_MultiHashMap::map, GNUNET_CONTAINER_MultiHashMap::map_length, and GNUNET_CONTAINER_MultiHashMap::use_small_entries.

Referenced by check_unique(), create_download_context(), create_handle(), create_member(), create_member_session(), create_response(), create_room(), create_service(), create_srv_handle(), database_setup(), deserialize_download(), deserialize_search(), DHTU_ip_init(), diff_create(), GDS_CLIENTS_init(), GDS_ROUTING_init(), get_cadet(), get_file_handle(), GNUNET_CADET_connect(), GNUNET_DHT_connect(), GNUNET_FS_indexing_init(), GNUNET_FS_namespace_list_updateable(), GNUNET_FS_search_start_searching_(), GNUNET_FS_share_tree_trim(), GNUNET_IDENTITY_connect(), GSF_peer_connect_handler(), GSF_pending_request_init_(), GSF_plan_add_(), handle_alice_client_message(), handle_bob_client_message(), handle_client_accept(), handle_client_create_set(), handle_client_evaluate(), handle_client_join(), handle_port_open(), init_contact_store(), init_message_store(), init_operation_store(), init_socket(), intersection_accept(), intersection_evaluate(), iterate_forward_members(), iterate_notify_about_members(), libgnunet_plugin_datacache_heap_init(), libgnunet_plugin_datastore_heap_init(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search(), REST_openid_process_request(), rfn_create(), run(), search_start(), send_full_set(), start_service_run(), switch_member_session(), union_accept(), and union_evaluate().

◆ GNUNET_CONTAINER_multihashmap_destroy()

void GNUNET_CONTAINER_multihashmap_destroy ( struct GNUNET_CONTAINER_MultiHashMap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 215 of file container_multihashmap.c.

217{
219 for (unsigned int i = 0; i < map->map_length; i++)
220 {
221 union MapEntry me;
222
223 me = map->map[i];
225 {
226 struct SmallMapEntry *sme;
227 struct SmallMapEntry *nxt;
228
229 nxt = me.sme;
230 while (NULL != (sme = nxt))
231 {
232 nxt = sme->next;
233 GNUNET_free (sme);
234 }
235 me.sme = NULL;
236 }
237 else
238 {
239 struct BigMapEntry *bme;
240 struct BigMapEntry *nxt;
241
242 nxt = me.bme;
243 while (NULL != (bme = nxt))
244 {
245 nxt = bme->next;
246 GNUNET_free (bme);
247 }
248 me.bme = NULL;
249 }
250 }
253}
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
An entry in the hash map with the full key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
unsigned int map_length
Length of the "map" array.
union MapEntry * map
All of our buckets.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
An entry in the hash map with just a pointer to the key.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.

References GNUNET_assert, GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by __attribute__(), _GSS_operation_destroy(), check_unique(), cleanup(), cleanup_handle(), clear_contact_store(), clear_message_store(), clear_operation_store(), client_disconnect_cb(), close_all_files(), database_shutdown(), destroy_handle(), destroy_member(), destroy_member_session(), destroy_room(), destroy_service(), destroy_service_session(), destroy_srv_handle(), DHTU_ip_done(), disconnect(), disconnect_cb(), do_shutdown(), fail_intersection_operation(), free_download_context(), free_search_context(), free_update_information_graph(), GDS_ROUTING_done(), GNUNET_CADET_disconnect(), GNUNET_DHT_disconnect(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_indexing_done(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_stop(), GNUNET_FS_share_tree_trim(), GNUNET_IDENTITY_disconnect(), GSF_peer_disconnect_handler(), GSF_pending_request_done_(), GSF_plan_notify_peer_disconnect_(), intersection_op_cancel(), iterate_forward_members(), iterate_notify_about_members(), iterate_zones(), libgnunet_plugin_datacache_heap_done(), libgnunet_plugin_datastore_heap_done(), main(), print_finish(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), REST_openid_done(), search_start(), shutdown_rest(), shutdown_task(), stop_service_run(), and union_op_cancel().

◆ GNUNET_CONTAINER_multihashmap_get()

void * GNUNET_CONTAINER_multihashmap_get ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 281 of file container_multihashmap.c.

284{
285 union MapEntry me;
286
287 me = map->map[idx_of (map, key)];
289 {
290 struct SmallMapEntry *sme;
291
292 for (sme = me.sme; NULL != sme; sme = sme->next)
293 if (0 == GNUNET_memcmp (key, sme->key))
294 return sme->value;
295 }
296 else
297 {
298 struct BigMapEntry *bme;
299
300 for (bme = me.bme; NULL != bme; bme = bme->next)
301 if (0 == GNUNET_memcmp (key, &bme->key))
302 return bme->value;
303 }
304 return NULL;
305}
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Compute the index of the bucket for the given key.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void * value
Value of the entry.
struct GNUNET_HashCode key
Key for the entry.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.

References GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_file(), add_to_keyword_counter(), add_to_meta_counter(), callback_room_message(), cancel_store_operation(), cb_intersection_element_removed(), change_srv_handle_member_id(), check_and_remove_pending_reversal(), check_member_session_history(), close_handle_room(), close_service_room(), code_redirect(), collector(), consume_fail(), consume_ticket(), cookie_identity_interpretation(), create_response(), delete_store_message(), diff_insert(), ego_sign_data(), entry_handle_room_at(), execute_add(), execute_remove(), find_port(), find_target(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), get_file_handle(), get_gns_cont(), get_handle_contact(), get_handle_room(), get_member_session(), get_redirect_state(), get_room_message(), get_room_recipient(), get_room_sender(), get_service_room(), get_srv_handle_member_id(), get_store_contact(), get_store_contact_raw(), get_store_message(), get_store_message_link(), get_store_operation_type(), get_url_parameter_copy(), GNUNET_FS_add_to_index(), GNUNET_FS_handle_on_demand_block(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), handle_client_set_add(), handle_delete_message(), handle_identity_update(), handle_port_close(), handle_room_message(), handle_transcript_message(), handle_union_p2p_demand(), handle_union_p2p_offer(), is_message_in_message_control_flow(), join_room_run(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), mark_as_reachable(), message_token(), mq_init(), namecache_lookup_block(), namestore_flat_lookup_records(), namestore_get(), notify_srv_handle_member_id(), ns_lookup_result_cb(), on_message_cb(), open_handle_room(), parse_credentials_basic_auth(), parse_credentials_post_body(), pending_reversal_timeout(), post_data_iter(), queue_destroy(), remove_high_frequency_keywords(), rfn_vote(), route_packet(), setup_sender(), sock_read(), token_endpoint(), update_message_control_flow(), use_store_operation(), and userinfo_endpoint().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 406 of file container_multihashmap.c.

409{
410 union MapEntry me;
411 unsigned int i;
412
414
415 i = idx_of (map, key);
416 me = map->map[i];
418 {
419 struct SmallMapEntry *p;
420
421 p = NULL;
422 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
423 {
424 if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
425 {
426 if (NULL == p)
427 map->map[i].sme = sme->next;
428 else
429 p->next = sme->next;
431 GNUNET_free (sme);
432 map->size--;
433 return GNUNET_YES;
434 }
435 p = sme;
436 }
437 }
438 else
439 {
440 struct BigMapEntry *p;
441
442 p = NULL;
443 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
444 {
445 if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
446 {
447 if (NULL == p)
448 map->map[i].bme = bme->next;
449 else
450 p->next = bme->next;
452 GNUNET_free (bme);
453 map->size--;
454 return GNUNET_YES;
455 }
456 p = bme;
457 }
458 }
459 return GNUNET_NO;
460}
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiHashMap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiHashMap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static char * value
Value of the record to add/remove.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
@ GNUNET_YES
@ GNUNET_NO
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
unsigned int size
Number of entries in the map.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by add_file(), bind_loose_channel(), cancel_store_operation(), cb_intersection_element_removed(), clean_channel(), clean_request(), client_release_ports(), close_handle_room(), close_service_room(), consume_fail(), consume_ticket(), create_target(), delete_linked_hash(), delete_store_message(), delete_value(), expire_oldest_entry(), filter_all(), free_channel_state(), free_destination_entry(), free_ego(), free_pending_request(), free_service_record(), free_validation_state(), get_store_message(), GNUNET_CADET_close_port(), GNUNET_DHT_get_stop(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), GSC_drop_loose_channel(), GSF_cadet_query_cancel(), GSF_plan_notify_peer_disconnect_(), GSF_plan_notify_request_done_(), handle_delete_message(), handle_identity_update(), handle_port_close(), handle_union_p2p_elements(), heap_plugin_del(), iterator_bf_reduce(), libgnunet_plugin_datacache_heap_done(), migrate_and_drop_keywords(), migrate_and_drop_metadata(), move_to_pending(), ns_lookup_result_cb(), peer_destroy(), pending_reversal_timeout(), pending_reversals_delete_it(), process_result_with_request(), queue_destroy(), receiver_destroy(), reconstruct_cb(), remove_all(), remove_client_query_record(), remove_iterator(), remove_member_session(), remove_store_contact(), sender_destroy(), setup_state_record(), update_store_contact(), and validation_transmit_on_queue().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove_all()

int GNUNET_CONTAINER_multihashmap_remove_all ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 464 of file container_multihashmap.c.

467{
468 union MapEntry me;
469 unsigned int i;
470 int ret;
471
473
474 ret = 0;
475 i = idx_of (map, key);
476 me = map->map[i];
478 {
479 struct SmallMapEntry *sme;
480 struct SmallMapEntry *p;
481
482 p = NULL;
483 sme = me.sme;
484 while (NULL != sme)
485 {
486 if (0 == GNUNET_memcmp (key, sme->key))
487 {
488 if (NULL == p)
489 map->map[i].sme = sme->next;
490 else
491 p->next = sme->next;
493 GNUNET_free (sme);
494 map->size--;
495 if (NULL == p)
496 sme = map->map[i].sme;
497 else
498 sme = p->next;
499 ret++;
500 }
501 else
502 {
503 p = sme;
504 sme = sme->next;
505 }
506 }
507 }
508 else
509 {
510 struct BigMapEntry *bme;
511 struct BigMapEntry *p;
512
513 p = NULL;
514 bme = me.bme;
515 while (NULL != bme)
516 {
517 if (0 == GNUNET_memcmp (key, &bme->key))
518 {
519 if (NULL == p)
520 map->map[i].bme = bme->next;
521 else
522 p->next = bme->next;
524 GNUNET_free (bme);
525 map->size--;
526 if (NULL == p)
527 bme = map->map[i].bme;
528 else
529 bme = p->next;
530 ret++;
531 }
532 else
533 {
534 p = bme;
535 bme = bme->next;
536 }
537 }
538 }
539 return ret;
540}
static int ret
Final status code.
Definition: gnunet-arm.c:94

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by clear_member_chain_history(), close_srv_handle_room(), delete_store_message(), expire_blocks(), link_room_deletion(), namecache_cache_block(), and namestore_flat_store_records().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_clear()

unsigned int GNUNET_CONTAINER_multihashmap_clear ( struct GNUNET_CONTAINER_MultiHashMap map)

Remove all entries from the map.

Note that the values would not be "freed".

Parameters
mapthe map
Returns
number of values removed

Definition at line 571 of file container_multihashmap.c.

572{
573 unsigned int ret;
574
575 ret = map->size;
577 return ret;
578}
static int remove_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Callback used to remove all entries from the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.

References GNUNET_CONTAINER_multihashmap_iterate(), map, remove_all(), ret, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by check_member_session_completion(), and task_notify_srv_handle_member_id().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 582 of file container_multihashmap.c.

585{
586 union MapEntry me;
587
588 me = map->map[idx_of (map, key)];
590 {
591 struct SmallMapEntry *sme;
592
593 for (sme = me.sme; NULL != sme; sme = sme->next)
594 if (0 == GNUNET_memcmp (key, sme->key))
595 return GNUNET_YES;
596 }
597 else
598 {
599 struct BigMapEntry *bme;
600
601 for (bme = me.bme; NULL != bme; bme = bme->next)
602 if (0 == GNUNET_memcmp (key, &bme->key))
603 return GNUNET_YES;
604 }
605 return GNUNET_NO;
606}

References GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by allocate_v4_address(), allocate_v6_address(), build_authz_response(), check_member_session_history(), code_redirect(), collector(), contains_store_message(), cookie_identity_interpretation(), ego_get_all(), ego_get_response(), ego_sign_data(), forward_about_members(), free_validation_state(), get_gns_cont(), get_url_parameter_copy(), handle_query_message(), handle_union_p2p_offer(), handle_validation_response(), is_srv_handle_routing(), iterate_save_messages(), load_message_store_entries(), load_message_store_links(), mq_init(), namestore_get(), notify_about_members(), parse_credentials_basic_auth(), parse_credentials_post_body(), publicize_rm(), regex_next_edge(), run(), userinfo_endpoint(), and validation_transmit_on_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 610 of file container_multihashmap.c.

614{
615 union MapEntry me;
616
617 me = map->map[idx_of (map, key)];
619 {
620 struct SmallMapEntry *sme;
621
622 for (sme = me.sme; NULL != sme; sme = sme->next)
623 if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
624 return GNUNET_YES;
625 }
626 else
627 {
628 struct BigMapEntry *bme;
629
630 for (bme = me.bme; NULL != bme; bme = bme->next)
631 if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
632 return GNUNET_YES;
633 }
634 return GNUNET_NO;
635}

References GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by plan(), and schedule_block_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists
Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if UNIQUE_ONLY was the option and the value already exists

Definition at line 710 of file container_multihashmap.c.

714{
715 union MapEntry me;
716 unsigned int i;
717
718 i = idx_of (map, key);
721 {
722 me = map->map[i];
724 {
725 struct SmallMapEntry *sme;
726
727 for (sme = me.sme; NULL != sme; sme = sme->next)
728 if (0 == GNUNET_memcmp (key, sme->key))
729 {
731 return GNUNET_SYSERR;
732 sme->value = value;
733 return GNUNET_NO;
734 }
735 }
736 else
737 {
738 struct BigMapEntry *bme;
739
740 for (bme = me.bme; NULL != bme; bme = bme->next)
741 if (0 == GNUNET_memcmp (key, &bme->key))
742 {
744 return GNUNET_SYSERR;
745 bme->value = value;
746 return GNUNET_NO;
747 }
748 }
749 }
750 if (map->size / 3 >= map->map_length / 4)
751 {
752 grow (map);
753 i = idx_of (map, key);
754 }
756 {
757 struct SmallMapEntry *sme;
758
759 sme = GNUNET_new (struct SmallMapEntry);
760 sme->key = key;
761 sme->value = value;
762 sme->next = map->map[i].sme;
763 map->map[i].sme = sme;
764 }
765 else
766 {
767 struct BigMapEntry *bme;
768
769 bme = GNUNET_new (struct BigMapEntry);
770 bme->key = *key;
771 bme->value = value;
772 bme->next = map->map[i].bme;
773 map->map[i].bme = bme;
774 }
775 map->size++;
776 return GNUNET_OK;
777}
static void grow(struct GNUNET_CONTAINER_MultiHashMap *map)
Grow the given map to a more appropriate size.
@ GNUNET_OK
@ GNUNET_SYSERR

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_link(), add_member_session(), add_to_keyword_counter(), add_to_meta_counter(), boot_queue(), callback_scan_for_operations(), change_srv_handle_member_id(), check_unique(), collector(), create_handle_member_id(), create_randomized_element_iterator(), database_setup(), decode_and_send(), deserialize_search_result(), dht_get_string_handler(), diff_insert(), entry_service_room(), execute_add(), filtered_map_initialization(), find_target(), forward_about_members(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_ROUTING_add(), get_file_handle(), get_store_contact(), get_store_message(), GNUNET_CADET_open_port(), GNUNET_DHT_get_start(), GNUNET_FS_add_to_index(), GNUNET_FS_namespace_list_updateable(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), GSF_pending_request_create_(), GSF_plan_add_(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_bob_client_message(), handle_bob_client_message_multipart(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_set_add(), handle_dht_local_get(), handle_identity_update(), handle_p2p_get(), handle_port_open(), handle_room_message(), handle_transcript_message(), handle_union_p2p_inquiry(), handle_union_p2p_offer(), handle_validation_response(), header_iterator(), heap_plugin_put(), init_socket(), initialize_map_unfiltered(), iterate_copy_history(), join_room_run(), link_room_message(), load_member_session_history(), load_message_store_entries(), load_message_store_links(), load_state(), login_cont(), maint_child_death(), mq_init(), namecache_cache_block(), namestore_flat_store_records(), notify_about_members(), notify_srv_handle_member_id(), open_service_room(), open_srv_handle_room(), post_data_iter(), process_ksk_result(), process_sks_result(), publicize_rm(), put_diff(), put_rfn(), put_set(), put_store_message(), put_task(), queue(), read_index_list(), regex_find_path(), REGEX_INTERNAL_search(), regex_next_edge(), register_hashcode(), rfn_vote(), route_packet(), run(), schedule_block_download(), setup_sender(), setup_state_record(), sock_read(), store_all_states(), store_service(), token_endpoint(), transmit_pending(), update_member_chain_history(), update_message_control_flow(), update_sre_result_maps(), update_store_contact(), url_iterator(), and use_store_operation().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_size()

unsigned int GNUNET_CONTAINER_multihashmap_size ( const struct GNUNET_CONTAINER_MultiHashMap map)

◆ GNUNET_CONTAINER_multihashmap_iterate()

int GNUNET_CONTAINER_multihashmap_iterate ( struct GNUNET_CONTAINER_MultiHashMap map,
GNUNET_CONTAINER_MultiHashMapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 309 of file container_multihashmap.c.

313{
314 int count;
315 union MapEntry me;
316 union MapEntry *ce;
317 struct GNUNET_HashCode kc;
318
319 GNUNET_assert (NULL != map);
322 count = 0;
323 for (unsigned i = 0; i < map->map_length; i++)
324 {
325 me = map->map[i];
327 {
328 struct SmallMapEntry *sme;
329
330 ce->sme = me.sme;
331 while (NULL != (sme = ce->sme))
332 {
333 ce->sme = sme->next;
334 if (NULL != it)
335 {
336 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
337 {
339 return GNUNET_SYSERR;
340 }
341 }
342 count++;
343 }
344 }
345 else
346 {
347 struct BigMapEntry *bme;
348
349 ce->bme = me.bme;
350 while (NULL != (bme = ce->bme))
351 {
352 ce->bme = bme->next;
353 if (NULL != it)
354 {
355 kc = bme->key;
356 if (GNUNET_OK != it (it_cls, &kc, bme->value))
357 {
359 return GNUNET_SYSERR;
360 }
361 }
362 count++;
363 }
364 }
365 }
367 return count;
368}
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
A 512-bit hashcode.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by _GSS_operation_destroy(), begin_bf_exchange(), callback_mq_error(), callback_reconnect(), cleanup(), cleanup_handle(), clear_contact_store(), clear_message_store(), clear_operation_store(), client_disconnect_cb(), close_all_files(), collect_generation_garbage(), database_shutdown(), destroy_handle(), destroy_member(), destroy_room(), destroy_service(), destroy_service_session(), destroy_srv_handle(), disconnect_cb(), do_reconnect(), do_shutdown(), enc_notify_cb(), free_search_context(), get_member_session_of(), GNUNET_CADET_disconnect(), GNUNET_CONTAINER_multihashmap_clear(), GNUNET_FS_search_continue(), GNUNET_FS_search_pause(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_start_searching_(), GNUNET_FS_search_stop(), GNUNET_IDENTITY_disconnect(), GNUNET_MESSENGER_find_rooms(), GSF_iterate_pending_requests_(), GSF_peer_disconnect_handler(), GSF_pending_request_done_(), handle_alices_cryptodata_message(), handle_client_accept(), handle_intersection_p2p_done(), handle_union_p2p_request_full(), handle_union_p2p_send_full(), handle_union_p2p_strata_estimator(), handle_validation_response(), heap_get_keys(), heap_plugin_get_closest(), heap_plugin_get_key(), initialize_key_to_element(), iterate_member_sessions(), iterate_zones(), libgnunet_plugin_datastore_heap_done(), load_member_next_sessions(), main(), maybe_finish(), namecache_expire_blocks(), namestore_flat_iterate_records(), namestore_flat_zone_to_name(), print_finish(), process_bf(), reconnect_cbk(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), reschedule_connect(), reset_cadet(), REST_openid_done(), run(), save_member(), save_member_session_history(), save_message_store(), save_operation_store(), save_state(), schedule_transmit_search_request(), send_alices_cryptodata_message(), send_bloomfilter(), send_full_set(), share_tree_trim(), shutdown_task(), signal_search_resume(), stop_service_run(), switch_member_session(), sync_member_contacts(), task_notify_srv_handle_member_id(), transmit_cryptographic_reply(), and try_reconnect().

◆ GNUNET_CONTAINER_multihashmap_iterator_create()

struct GNUNET_CONTAINER_MultiHashMapIterator * GNUNET_CONTAINER_multihashmap_iterator_create ( const struct GNUNET_CONTAINER_MultiHashMap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be used anymore if elements have been removed from 'map' after the creation of the iterator, or 'map' has been destroyed. Adding elements to 'map' may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 908 of file container_multihashmap.c.

910{
912
914 iter->map = map;
916 iter->me = map->map[0];
917 return iter;
918}
const struct GNUNET_CONTAINER_MultiHashMap * map
Map that we are iterating over.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
union MapEntry me
Position in the bucket idx.

References GNUNET_new, GNUNET_CONTAINER_MultiHashMapIterator::map, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiHashMapIterator::me, GNUNET_CONTAINER_MultiHashMapIterator::modification_counter, and GNUNET_CONTAINER_MultiPeerMap::modification_counter.

Referenced by apply_diff_to_rfn(), handle_client_iterate(), handle_intersection_p2p_done(), process_bf(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next ( struct GNUNET_CONTAINER_MultiHashMapIterator iter,
struct GNUNET_HashCode key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 922 of file container_multihashmap.c.

926{
927 /* make sure the map has not been modified */
929
930 /* look for the next entry, skipping empty buckets */
931 while (1)
932 {
933 if (iter->idx >= iter->map->map_length)
934 return GNUNET_NO;
935 if (GNUNET_YES == iter->map->use_small_entries)
936 {
937 if (NULL != iter->me.sme)
938 {
939 if (NULL != key)
940 *key = *iter->me.sme->key;
941 if (NULL != value)
942 *value = iter->me.sme->value;
943 iter->me.sme = iter->me.sme->next;
944 return GNUNET_YES;
945 }
946 }
947 else
948 {
949 if (NULL != iter->me.bme)
950 {
951 if (NULL != key)
952 *key = iter->me.bme->key;
953 if (NULL != value)
954 *value = iter->me.bme->value;
955 iter->me.bme = iter->me.bme->next;
956 return GNUNET_YES;
957 }
958 }
959 iter->idx += 1;
960 if (iter->idx < iter->map->map_length)
961 iter->me = iter->map->map[iter->idx];
962 }
963}
unsigned int idx
Current bucket index.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiHashMapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiHashMap::map, GNUNET_CONTAINER_MultiHashMapIterator::map, GNUNET_CONTAINER_MultiHashMap::map_length, GNUNET_CONTAINER_MultiHashMapIterator::me, GNUNET_CONTAINER_MultiHashMap::modification_counter, GNUNET_CONTAINER_MultiHashMapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiHashMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by apply_diff_to_rfn(), send_client_element(), send_remaining_elements(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_iterator_destroy()

void GNUNET_CONTAINER_multihashmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiHashMapIterator iter)

Destroy a multihashmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 967 of file container_multihashmap.c.

969{
970 GNUNET_free (iter);
971}

References GNUNET_free.

Referenced by _GSS_operation_destroy(), apply_diff_to_rfn(), client_disconnect_cb(), handle_client_iter_ack(), intersection_op_cancel(), send_client_element(), send_remaining_elements(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_get_multiple()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
GNUNET_CONTAINER_MultiHashMapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 781 of file container_multihashmap.c.

786{
787 int count;
788 union MapEntry *me;
789 union MapEntry *ce;
790
793 count = 0;
794 me = &map->map[idx_of (map, key)];
796 {
797 struct SmallMapEntry *sme;
798
799 ce->sme = me->sme;
800 while (NULL != (sme = ce->sme))
801 {
802 ce->sme = sme->next;
803 if (0 != GNUNET_memcmp (key, sme->key))
804 continue;
805 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
806 {
808 return GNUNET_SYSERR;
809 }
810 count++;
811 }
812 }
813 else
814 {
815 struct BigMapEntry *bme;
816
817 ce->bme = me->bme;
818 while (NULL != (bme = ce->bme))
819 {
820 ce->bme = bme->next;
821 if (0 != GNUNET_memcmp (key, &bme->key))
822 continue;
823 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
824 {
826 return GNUNET_SYSERR;
827 }
828 count++;
829 }
830 }
832 return count;
833}

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by close_srv_handle_room(), delete_linked_hash(), find_trees(), GDS_CLIENTS_handle_reply(), GDS_ROUTING_add(), GDS_ROUTING_process(), GNUNET_FS_namespace_list_updateable(), GSF_plan_add_(), handle_client_result(), handle_dht_local_get_result_seen(), handle_dht_local_get_stop(), handle_p2p_get(), handle_p2p_put(), handle_port_open(), handle_put(), handle_reply(), heap_plugin_get(), heap_plugin_get_key(), heap_plugin_put(), heap_plugin_remove_key(), iter_hashcodes(), link_room_deletion(), link_room_message(), process_ksk_result(), process_sks_result(), regex_next_edge(), and try_handle_plaintext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_get_random()

unsigned int GNUNET_CONTAINER_multihashmap_get_random ( const struct GNUNET_CONTAINER_MultiHashMap map,
GNUNET_CONTAINER_MultiHashMapIteratorCallback  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 848 of file container_multihashmap.c.

852{
853 unsigned int off;
854 unsigned int idx;
855 union MapEntry me;
856
857 if (0 == map->size)
858 return 0;
859 if (NULL == it)
860 return 1;
862 for (idx = 0; idx < map->map_length; idx++)
863 {
864 me = map->map[idx];
866 {
867 struct SmallMapEntry *sme;
868 struct SmallMapEntry *nxt;
869
870 nxt = me.sme;
871 while (NULL != (sme = nxt))
872 {
873 nxt = sme->next;
874 if (0 == off)
875 {
876 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
877 return GNUNET_SYSERR;
878 return 1;
879 }
880 off--;
881 }
882 }
883 else
884 {
885 struct BigMapEntry *bme;
886 struct BigMapEntry *nxt;
887
888 nxt = me.bme;
889 while (NULL != (bme = nxt))
890 {
891 nxt = bme->next;
892 if (0 == off)
893 {
894 if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
895 return GNUNET_SYSERR;
896 return 1;
897 }
898 off--;
899 }
900 }
901 }
902 GNUNET_break (0);
903 return GNUNET_SYSERR;
904}
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_create()

struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 179 of file container_multipeermap.c.

181{
183
184 GNUNET_assert (len > 0);
186 map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
187 if (NULL == map->map)
188 {
190 return NULL;
191 }
192 map->map_length = len;
193 map->use_small_entries = do_not_copy_keys;
194 return map;
195}
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by client_connect_cb(), core_init(), create_srv_room(), CustomPeerMap_create(), GDS_NEIGHBOURS_init(), GNUNET_CORE_connect(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_HOSTLIST_server_start(), GNUNET_MESSENGER_create_room_state(), GNUNET_PEER_intern(), GNUNET_TRANSPORT_application_init(), GSC_SESSIONS_init(), GSF_cadet_start_server(), GSF_connected_peer_init_(), GSF_plan_init(), handle_client_send_request(), handle_connection_create(), handle_peer_push(), handle_suggest(), new_sub(), run(), View_change_len(), and View_create().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_destroy()

void GNUNET_CONTAINER_multipeermap_destroy ( struct GNUNET_CONTAINER_MultiPeerMap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 199 of file container_multipeermap.c.

201{
203 for (unsigned int i = 0; i < map->map_length; i++)
204 {
205 union MapEntry me;
206
207 me = map->map[i];
209 {
210 struct SmallMapEntry *sme;
211 struct SmallMapEntry *nxt;
212
213 nxt = me.sme;
214 while (NULL != (sme = nxt))
215 {
216 nxt = sme->next;
217 GNUNET_free (sme);
218 }
219 me.sme = NULL;
220 }
221 else
222 {
223 struct BigMapEntry *bme;
224 struct BigMapEntry *nxt;
225
226 nxt = me.bme;
227 while (NULL != (bme = nxt))
228 {
229 nxt = bme->next;
230 GNUNET_free (bme);
231 }
232 me.bme = NULL;
233 }
234 }
237}

References GNUNET_assert, GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by cleaning_task(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_srv_room(), destroy_sub(), do_shutdown(), GDS_NEIGHBOURS_done(), GNUNET_CORE_disconnect(), GNUNET_CRYPTO_ecc_dlog_release(), GNUNET_MESSENGER_destroy_room_state(), GNUNET_TRANSPORT_application_done(), GSC_SESSIONS_done(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_plan_done(), handle_connection_create(), peers_terminate(), shutdown_rest(), shutdown_task(), View_change_len(), and View_destroy().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_get()

void * GNUNET_CONTAINER_multipeermap_get ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 268 of file container_multipeermap.c.

271{
272 union MapEntry me;
273
274 me = map->map[idx_of (map, key)];
276 {
277 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
278 if (0 == GNUNET_memcmp (key, sme->key))
279 return sme->value;
280 }
281 else
282 {
283 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
284 if (0 == GNUNET_memcmp (key, &bme->key))
285 return bme->value;
286 }
287 return NULL;
288}
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by connect_notify(), consider_for_advertising(), cummulative_ack(), CustomPeerMap_get_index_pointer(), CustomPeerMap_remove_peer(), enter_srv_room_at(), find_session(), GCP_get(), GDS_NEIGHBOURS_lookup_peer(), GDS_u_connect(), get_cadet(), get_peer_ctx(), get_srv_room_tunnel(), GNUNET_CORE_get_mq(), GNUNET_CRYPTO_ecc_dlog(), GNUNET_PEER_intern(), GNUNET_PEER_search(), GSF_peer_get_(), GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), handle_client_send(), handle_client_send_request(), handle_connect_notify(), handle_core_connect(), handle_disconnect_notify(), handle_dv_box(), handle_notify_inbound(), handle_revocation_union_request(), handle_send_ready(), handle_suggest_cancel(), learn_dv_path(), lookup_neighbour(), lookup_virtual_link(), neighbour_find(), process_peer(), process_peer_monitoring_cb(), rebuild_srv_room_basement_structure(), route_control_message_without_fc(), View_change_len(), View_clear(), and View_remove_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 389 of file container_multipeermap.c.

392{
393 union MapEntry me;
394 unsigned int i;
395
397 i = idx_of (map, key);
398 me = map->map[i];
400 {
401 struct SmallMapEntry *p = NULL;
402
403 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
404 {
405 if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
406 {
407 if (NULL == p)
408 map->map[i].sme = sme->next;
409 else
410 p->next = sme->next;
412 GNUNET_free (sme);
413 map->size--;
414 return GNUNET_YES;
415 }
416 p = sme;
417 }
418 }
419 else
420 {
421 struct BigMapEntry *p = NULL;
422
423 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
424 {
425 if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
426 {
427 if (NULL == p)
428 map->map[i].bme = bme->next;
429 else
430 p->next = bme->next;
432 GNUNET_free (bme);
433 map->size--;
434 return GNUNET_YES;
435 }
436 p = bme;
437 }
438 }
439 return GNUNET_NO;
440}
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by callback_room_connect(), callback_room_disconnect(), destroy_ack_cummulator(), destroy_active_client_request(), destroy_it(), destroy_peer(), disconnect_and_free_peer_entry(), disconnect_cb(), enter_srv_room_at(), free_backtalker(), free_dv_route(), free_neighbour(), free_peer(), free_validation_state(), free_virtual_link(), GDS_u_disconnect(), GNUNET_PEER_change_rc(), GNUNET_PEER_decrement_rcs(), GNUNET_TRANSPORT_application_suggest_cancel(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_reject_request(), GSC_SESSIONS_end(), GSF_peer_disconnect_handler(), GSF_plan_notify_peer_disconnect_(), handle_client_send(), handle_core_disconnect(), neighbour_delete(), queue_destroy(), and stop_peer_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove_all()

int GNUNET_CONTAINER_multipeermap_remove_all ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 444 of file container_multipeermap.c.

447{
448 union MapEntry me;
449 unsigned int i;
450 int ret;
451
453
454 ret = 0;
455 i = idx_of (map, key);
456 me = map->map[i];
458 {
459 struct SmallMapEntry *sme;
460 struct SmallMapEntry *p;
461
462 p = NULL;
463 sme = me.sme;
464 while (NULL != sme)
465 {
466 if (0 == GNUNET_memcmp (key, sme->key))
467 {
468 if (NULL == p)
469 map->map[i].sme = sme->next;
470 else
471 p->next = sme->next;
473 GNUNET_free (sme);
474 map->size--;
475 if (NULL == p)
476 sme = map->map[i].sme;
477 else
478 sme = p->next;
479 ret++;
480 }
481 else
482 {
483 p = sme;
484 sme = sme->next;
485 }
486 }
487 }
488 else
489 {
490 struct BigMapEntry *bme;
491 struct BigMapEntry *p;
492
493 p = NULL;
494 bme = me.bme;
495 while (NULL != bme)
496 {
497 if (0 == GNUNET_memcmp (key, &bme->key))
498 {
499 if (NULL == p)
500 map->map[i].bme = bme->next;
501 else
502 p->next = bme->next;
504 GNUNET_free (bme);
505 map->size--;
506 if (NULL == p)
507 bme = map->map[i].bme;
508 else
509 bme = p->next;
510 ret++;
511 }
512 else
513 {
514 p = bme;
515 bme = bme->next;
516 }
517 }
518 }
519 return ret;
520}

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by add_valid_peer(), core_disconnects(), CustomPeerMap_remove_peer(), destroy_peer(), View_clear(), and View_remove_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 524 of file container_multipeermap.c.

527{
528 union MapEntry me;
529
530 me = map->map[idx_of (map, key)];
532 {
533 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
534 if (0 == GNUNET_memcmp (key, sme->key))
535 return GNUNET_YES;
536 }
537 else
538 {
539 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
540 if (0 == GNUNET_memcmp (key, &bme->key))
541 return GNUNET_YES;
542 }
543 return GNUNET_NO;
544}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by callback_room_disconnect(), check_peer_known(), check_peer_valid(), check_removable(), clean_peer(), CustomPeerMap_contains_peer(), CustomPeerMap_put(), destroy_peer(), get_peer_ctx(), GSC_CLIENTS_deliver_message(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_solicit_request(), handle_add_queue_message(), handle_client_send_request(), handle_dv_learn(), handle_peer_pull_reply(), handle_peer_pull_request(), handle_peer_push(), mq_notify_sent_cb(), send_pull_request(), send_push(), View_clear(), and View_contains_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains_value ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 548 of file container_multipeermap.c.

552{
553 union MapEntry me;
554
555 me = map->map[idx_of (map, key)];
557 {
558 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
559 if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
560 return GNUNET_YES;
561 }
562 else
563 {
564 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
565 if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
566 return GNUNET_YES;
567 }
568 return GNUNET_NO;
569}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_put()

int GNUNET_CONTAINER_multipeermap_put ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 632 of file container_multipeermap.c.

636{
637 union MapEntry me;
638 unsigned int i;
639
640 i = idx_of (map, key);
643 {
644 me = map->map[i];
646 {
647 struct SmallMapEntry *sme;
648
649 for (sme = me.sme; NULL != sme; sme = sme->next)
650 if (0 == GNUNET_memcmp (key, sme->key))
651 {
653 return GNUNET_SYSERR;
654 sme->value = value;
655 return GNUNET_NO;
656 }
657 }
658 else
659 {
660 struct BigMapEntry *bme;
661
662 for (bme = me.bme; NULL != bme; bme = bme->next)
663 if (0 == GNUNET_memcmp (key, &bme->key))
664 {
666 return GNUNET_SYSERR;
667 bme->value = value;
668 return GNUNET_NO;
669 }
670 }
671 }
672 if (map->size / 3 >= map->map_length / 4)
673 {
674 grow (map);
675 i = idx_of (map, key);
676 }
678 {
679 struct SmallMapEntry *sme;
680
681 sme = GNUNET_new (struct SmallMapEntry);
682 sme->key = key;
683 sme->value = value;
684 sme->next = map->map[i].sme;
685 map->map[i].sme = sme;
686 }
687 else
688 {
689 struct BigMapEntry *bme;
690
691 bme = GNUNET_new (struct BigMapEntry);
692 bme->key = *key;
693 bme->value = value;
694 bme->next = map->map[i].bme;
695 map->map[i].bme = bme;
696 }
697 map->size++;
698 return GNUNET_OK;
699}
static void grow(struct GNUNET_CONTAINER_MultiPeerMap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by activate_core_visible_dv_path(), add_valid_peer(), callback_room_connect(), connect_peer(), core_connects(), create_peer_ctx(), cummulative_ack(), CustomPeerMap_put(), enter_srv_room_at(), GCP_get(), GDS_u_connect(), get_cadet(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_PEER_intern(), GNUNET_TRANSPORT_application_suggest(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_SESSIONS_create(), GSF_peer_connect_handler(), GSF_plan_add_(), handle_add_queue_message(), handle_client_init(), handle_client_send_request(), handle_connect(), handle_connection_create(), handle_core_connect(), handle_dv_box(), handle_flow_control(), handle_suggest(), handle_validation_response(), insert_in_sampler(), learn_dv_path(), make_peer(), new_peer_entry(), on_message_cb(), process_notify(), process_peer_monitoring_cb(), setup_queue(), start_address_validation(), View_change_len(), and View_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_size()

◆ GNUNET_CONTAINER_multipeermap_iterate()

int GNUNET_CONTAINER_multipeermap_iterate ( struct GNUNET_CONTAINER_MultiPeerMap map,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 292 of file container_multipeermap.c.

296{
297 int count;
298 union MapEntry me;
299 union MapEntry *ce;
300 struct GNUNET_PeerIdentity kc;
301
302 count = 0;
303 GNUNET_assert (NULL != map);
306 for (unsigned int i = 0; i < map->map_length; i++)
307 {
308 me = map->map[i];
310 {
311 struct SmallMapEntry *sme;
312
313 ce->sme = me.sme;
314 while (NULL != (sme = ce->sme))
315 {
316 ce->sme = sme->next;
317 if (NULL != it)
318 {
319 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
320 {
322 return GNUNET_SYSERR;
323 }
324 }
325 count++;
326 }
327 }
328 else
329 {
330 struct BigMapEntry *bme;
331
332 ce->bme = me.bme;
333 while (NULL != (bme = ce->bme))
334 {
335 ce->bme = bme->next;
336 if (NULL != it)
337 {
338 kc = bme->key;
339 if (GNUNET_OK != it (it_cls, &kc, bme->value))
340 {
342 return GNUNET_SYSERR;
343 }
344 }
345 count++;
346 }
347 }
348 }
350 return count;
351}
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
The identity of the host (wraps the signing key of the peer).

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_peer_task(), cleaning_task(), client_disconnect_cb(), consider_for_advertising(), cron_flush_respect(), destroy_srv_room(), disconnect(), do_shutdown(), forward_srv_room_message(), GCP_destroy_all_peers(), GCP_iterate_all(), get_random_peer_from_peermap(), get_valid_peers(), GNUNET_CORE_disconnect(), GNUNET_TRANSPORT_application_done(), GSC_SESSIONS_broadcast_typemap(), GSC_SESSIONS_done(), GSC_SESSIONS_notify_client_about_sessions(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_handle_local_client_disconnect_(), GSF_iterate_connected_peers_(), handle_client_start(), handle_dv_learn(), handle_monitor_start(), handle_p2p_estimate(), peers_terminate(), process_notify(), publicize_rm(), reconnect(), reconnect_later(), schedule_next_hello(), send_find_peer_message(), send_srv_room_message(), shutdown_task(), start_dv_learn(), store_valid_peers(), and update_flood_message().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_iterator_create()

struct GNUNET_CONTAINER_MultiPeerMapIterator * GNUNET_CONTAINER_multipeermap_iterator_create ( const struct GNUNET_CONTAINER_MultiPeerMap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 829 of file container_multipeermap.c.

831{
833
835 iter->map = map;
837 iter->me = map->map[0];
838 return iter;
839}
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
const struct GNUNET_CONTAINER_MultiPeerMap * map
Map that we are iterating over.

References GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMapIterator::map, map, GNUNET_CONTAINER_MultiPeerMapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiPeerMapIterator::modification_counter.

◆ GNUNET_CONTAINER_multipeermap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_iterator_next ( struct GNUNET_CONTAINER_MultiPeerMapIterator iter,
struct GNUNET_PeerIdentity key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified.

This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed.

Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 843 of file container_multipeermap.c.

847{
848 /* make sure the map has not been modified */
850
851 /* look for the next entry, skipping empty buckets */
852 while (1)
853 {
854 if (iter->idx >= iter->map->map_length)
855 return GNUNET_NO;
856 if (GNUNET_YES == iter->map->use_small_entries)
857 {
858 if (NULL != iter->me.sme)
859 {
860 if (NULL != key)
861 *key = *iter->me.sme->key;
862 if (NULL != value)
863 *value = iter->me.sme->value;
864 iter->me.sme = iter->me.sme->next;
865 return GNUNET_YES;
866 }
867 }
868 else
869 {
870 if (NULL != iter->me.bme)
871 {
872 if (NULL != key)
873 *key = iter->me.bme->key;
874 if (NULL != value)
875 *value = iter->me.bme->value;
876 iter->me.bme = iter->me.bme->next;
877 return GNUNET_YES;
878 }
879 }
880 iter->idx += 1;
881 if (iter->idx < iter->map->map_length)
882 iter->me = iter->map->map[iter->idx];
883 }
884}
unsigned int idx
Current bucket index.

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiPeerMapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMapIterator::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, GNUNET_CONTAINER_MultiPeerMapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

◆ GNUNET_CONTAINER_multipeermap_iterator_destroy()

void GNUNET_CONTAINER_multipeermap_iterator_destroy ( struct GNUNET_CONTAINER_MultiPeerMapIterator iter)

Destroy a multipeermap iterator.

Parameters
iterthe iterator to destroy

Definition at line 888 of file container_multipeermap.c.

890{
891 GNUNET_free (iter);
892}

References GNUNET_free.

◆ GNUNET_CONTAINER_multipeermap_get_multiple()

int GNUNET_CONTAINER_multipeermap_get_multiple ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 703 of file container_multipeermap.c.

708{
709 int count;
710 union MapEntry me;
711 union MapEntry *ce;
712
715 count = 0;
716 me = map->map[idx_of (map, key)];
718 {
719 struct SmallMapEntry *sme;
720
721 ce->sme = me.sme;
722 while (NULL != (sme = ce->sme))
723 {
724 ce->sme = sme->next;
725 if (0 != GNUNET_memcmp (key, sme->key))
726 continue;
727 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
728 {
730 return GNUNET_SYSERR;
731 }
732 count++;
733 }
734 }
735 else
736 {
737 struct BigMapEntry *bme;
738
739 ce->bme = me.bme;
740 while (NULL != (bme = ce->bme))
741 {
742 ce->bme = bme->next;
743 if (0 != GNUNET_memcmp (key, &bme->key))
744 continue;
745 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
746 {
748 return GNUNET_SYSERR;
749 }
750 count++;
751 }
752 }
754 return count;
755}

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_add_queue_message(), handle_validation_response(), lookup_queue(), and start_address_validation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_get_random()

unsigned int GNUNET_CONTAINER_multipeermap_get_random ( const struct GNUNET_CONTAINER_MultiPeerMap map,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 770 of file container_multipeermap.c.

774{
775 unsigned int off;
776 union MapEntry me;
777
778 if (0 == map->size)
779 return 0;
780 if (NULL == it)
781 return 1;
783 for (unsigned int idx = 0; idx < map->map_length; idx++)
784 {
785 me = map->map[idx];
787 {
788 struct SmallMapEntry *sme;
789 struct SmallMapEntry *nxt;
790
791 nxt = me.sme;
792 while (NULL != (sme = nxt))
793 {
794 nxt = sme->next;
795 if (0 == off)
796 {
797 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
798 return GNUNET_SYSERR;
799 return 1;
800 }
801 off--;
802 }
803 }
804 else
805 {
806 struct BigMapEntry *bme;
807 struct BigMapEntry *nxt;
808
809 nxt = me.bme;
810 while (NULL != (bme = nxt))
811 {
812 nxt = bme->next;
813 if (0 == off)
814 {
815 if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
816 return GNUNET_SYSERR;
817 return 1;
818 }
819 off--;
820 }
821 }
822 }
823 GNUNET_break (0);
824 return GNUNET_SYSERR;
825}

References GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multishortmap_create()

struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 195 of file container_multishortmap.c.

196{
198
199 GNUNET_assert (len > 0);
201 map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
202 if (NULL == map->map)
203 {
205 return NULL;
206 }
207 map->map_length = len;
208 map->use_small_entries = do_not_copy_keys;
209 return map;
210}
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by create_message_control(), create_room(), GCO_init(), GCP_get(), GNUNET_CORE_cmd_connect_peers(), GNUNET_PQ_connect2(), GNUNET_TESTING_cmd_start_peer(), GNUNET_TESTING_get_topo_from_string(), GNUNET_TESTING_run(), GNUNET_TRANSPORT_cmd_start_peer(), init_member_store(), init_peer_store(), run(), and start_helper().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_destroy()

void GNUNET_CONTAINER_multishortmap_destroy ( struct GNUNET_CONTAINER_MultiShortmap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 214 of file container_multishortmap.c.

216{
218 for (unsigned int i = 0; i < map->map_length; i++)
219 {
220 union MapEntry me;
221
222 me = map->map[i];
224 {
225 struct SmallMapEntry *sme;
226 struct SmallMapEntry *nxt;
227
228 nxt = me.sme;
229 while (NULL != (sme = nxt))
230 {
231 nxt = sme->next;
232 GNUNET_free (sme);
233 }
234 me.sme = NULL;
235 }
236 else
237 {
238 struct BigMapEntry *bme;
239 struct BigMapEntry *nxt;
240
241 nxt = me.bme;
242 while (NULL != (bme = nxt))
243 {
244 nxt = bme->next;
245 GNUNET_free (bme);
246 }
247 me.bme = NULL;
248 }
249 }
252}

References GNUNET_assert, GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by clear_member_store(), clear_peer_store(), destroy_message_control(), destroy_peer(), destroy_room(), do_shutdown(), finish_test(), free_barrier_nodes(), GCO_shutdown(), GNUNET_PQ_connect2(), GNUNET_PQ_disconnect(), GNUNET_TESTING_free_topology(), and shutdown_rest().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_get()

void * GNUNET_CONTAINER_multishortmap_get ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 283 of file container_multishortmap.c.

286{
287 union MapEntry me;
288
289 me = map->map[idx_of (map, key)];
291 {
292 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
293 if (0 == GNUNET_memcmp (key, sme->key))
294 return sme->value;
295 }
296 else
297 {
298 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
299 if (0 == GNUNET_memcmp (key, &bme->key))
300 return bme->value;
301 }
302 return NULL;
303}
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by GCC_lookup(), get_node_info(), get_route(), get_store_member(), GNUNET_PQ_event_listen(), GNUNET_PQ_event_listen_cancel(), GNUNET_TESTING_barrier_get_node(), GNUNET_TESTING_get_barrier_(), GNUNET_TESTING_get_topo_from_string(), sock_read(), and start_helper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_remove()

int GNUNET_CONTAINER_multishortmap_remove ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 401 of file container_multishortmap.c.

405{
406 union MapEntry me;
407 unsigned int i;
408
410 i = idx_of (map, key);
411 me = map->map[i];
413 {
414 struct SmallMapEntry *p = NULL;
415
416 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
417 {
418 if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
419 {
420 if (NULL == p)
421 map->map[i].sme = sme->next;
422 else
423 p->next = sme->next;
425 GNUNET_free (sme);
426 map->size--;
427 return GNUNET_YES;
428 }
429 p = sme;
430 }
431 }
432 else
433 {
434 struct BigMapEntry *p = NULL;
435
436 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
437 {
438 if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
439 {
440 if (NULL == p)
441 map->map[i].bme = bme->next;
442 else
443 p->next = bme->next;
445 GNUNET_free (bme);
446 map->size--;
447 return GNUNET_YES;
448 }
449 p = bme;
450 }
451 }
452 return GNUNET_NO;
453}
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiShortmap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiShortmap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by destroy_route(), free_barrier_node_cb(), GCC_destroy(), GCP_remove_connection(), GNUNET_PQ_event_listen_cancel(), handle_id_message(), handle_leave_message(), kce_destroy(), start_dv_learn(), and task_message_control().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_remove_all()

int GNUNET_CONTAINER_multishortmap_remove_all ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 457 of file container_multishortmap.c.

460{
461 union MapEntry me;
462 unsigned int i;
463 int ret;
464
466
467 ret = 0;
468 i = idx_of (map, key);
469 me = map->map[i];
471 {
472 struct SmallMapEntry *sme;
473 struct SmallMapEntry *p;
474
475 p = NULL;
476 sme = me.sme;
477 while (NULL != sme)
478 {
479 if (0 == GNUNET_memcmp (key, sme->key))
480 {
481 if (NULL == p)
482 map->map[i].sme = sme->next;
483 else
484 p->next = sme->next;
486 GNUNET_free (sme);
487 map->size--;
488 if (NULL == p)
489 sme = map->map[i].sme;
490 else
491 sme = p->next;
492 ret++;
493 }
494 else
495 {
496 p = sme;
497 sme = sme->next;
498 }
499 }
500 }
501 else
502 {
503 struct BigMapEntry *bme;
504 struct BigMapEntry *p;
505
506 p = NULL;
507 bme = me.bme;
508 while (NULL != bme)
509 {
510 if (0 == GNUNET_memcmp (key, &bme->key))
511 {
512 if (NULL == p)
513 map->map[i].bme = bme->next;
514 else
515 p->next = bme->next;
517 GNUNET_free (bme);
518 map->size--;
519 if (NULL == p)
520 bme = map->map[i].bme;
521 else
522 bme = p->next;
523 ret++;
524 }
525 else
526 {
527 p = bme;
528 bme = bme->next;
529 }
530 }
531 }
532 return ret;
533}

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multishortmap_contains()

int GNUNET_CONTAINER_multishortmap_contains ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 537 of file container_multishortmap.c.

540{
541 union MapEntry me;
542
543 me = map->map[idx_of (map, key)];
545 {
546 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
547 if (0 == GNUNET_memcmp (key, sme->key))
548 return GNUNET_YES;
549 }
550 else
551 {
552 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
553 if (0 == GNUNET_memcmp (key, &bme->key))
554 return GNUNET_YES;
555 }
556 return GNUNET_NO;
557}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by generate_free_member_id(), GNUNET_TESTING_get_topo_from_string(), and start_helper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_contains_value()

int GNUNET_CONTAINER_multishortmap_contains_value ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 561 of file container_multishortmap.c.

565{
566 union MapEntry me;
567
568 me = map->map[idx_of (map, key)];
570 {
571 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
572 if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
573 return GNUNET_YES;
574 }
575 else
576 {
577 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
578 if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
579 return GNUNET_YES;
580 }
581 return GNUNET_NO;
582}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_join_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 644 of file container_multishortmap.c.

649{
650 union MapEntry me;
651 unsigned int i;
652
653 i = idx_of (map, key);
656 {
657 me = map->map[i];
659 {
660 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
661 if (0 == GNUNET_memcmp (key, sme->key))
662 {
664 return GNUNET_SYSERR;
665 sme->value = value;
666 return GNUNET_NO;
667 }
668 }
669 else
670 {
671 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
672 if (0 == GNUNET_memcmp (key, &bme->key))
673 {
675 return GNUNET_SYSERR;
676 bme->value = value;
677 return GNUNET_NO;
678 }
679 }
680 }
681 if (map->size / 3 >= map->map_length / 4)
682 {
683 grow (map);
684 i = idx_of (map, key);
685 }
687 {
688 struct SmallMapEntry *sme;
689
690 sme = GNUNET_new (struct SmallMapEntry);
691 sme->key = key;
692 sme->value = value;
693 sme->next = map->map[i].sme;
694 map->map[i].sme = sme;
695 }
696 else
697 {
698 struct BigMapEntry *bme;
699
700 bme = GNUNET_new (struct BigMapEntry);
701 bme->key = *key;
702 bme->value = value;
703 bme->next = map->map[i].bme;
704 map->map[i].bme = bme;
705 }
706 map->size++;
707 return GNUNET_OK;
708}
static void grow(struct GNUNET_CONTAINER_MultiShortmap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_peer_store_entry(), add_store_member(), barrier_attached(), connection_create(), enqueue_message_control(), GCP_add_connection(), GNUNET_PQ_event_listen(), GNUNET_TESTING_add_barrier_(), GNUNET_TESTING_get_topo_from_string(), handle_connection_create(), handle_id_message(), handle_join_message(), kce_generate(), load_peer_store(), notify_connect(), start_dv_learn(), and start_helper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_size()

unsigned int GNUNET_CONTAINER_multishortmap_size ( const struct GNUNET_CONTAINER_MultiShortmap map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 275 of file container_multishortmap.c.

277{
278 return map->size;
279}

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by consider_peer_activate(), consider_peer_destroy(), destroy_peer(), destroy_route(), GCO_shutdown(), generate_free_member_id(), GNUNET_PQ_disconnect(), GNUNET_PQ_event_listen_cancel(), handle_connection_create(), kce_generate(), scheduler_fd_cb(), secret_destroy(), and start_dv_learn().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterate()

int GNUNET_CONTAINER_multishortmap_iterate ( struct GNUNET_CONTAINER_MultiShortmap map,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 307 of file container_multishortmap.c.

311{
312 int count;
313 union MapEntry me;
314 union MapEntry *ce;
315 struct GNUNET_ShortHashCode kc;
316
317 count = 0;
318 GNUNET_assert (NULL != map);
321 for (unsigned int i = 0; i < map->map_length; i++)
322 {
323 me = map->map[i];
325 {
326 struct SmallMapEntry *sme;
327
328 ce->sme = me.sme;
329 while (NULL != (sme = ce->sme))
330 {
331 ce->sme = sme->next;
332 if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
333 {
335 return GNUNET_SYSERR;
336 }
337 count++;
338 }
339 }
340 else
341 {
342 struct BigMapEntry *bme;
343
344 ce->bme = me.bme;
345 while (NULL != (bme = ce->bme))
346 {
347 ce->bme = bme->next;
348 if (NULL != it)
349 {
350 kc = bme->key;
351 if (GNUNET_OK != it (it_cls, &kc, bme->value))
352 {
354 return GNUNET_SYSERR;
355 }
356 }
357 count++;
358 }
359 }
360 }
362 return count;
363}
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
A 256-bit hashcode.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by clear_member_store(), clear_peer_store(), find_room_member(), finish_test(), free_barrier_nodes(), free_namespaces_cb(), GNUNET_PQ_event_reconnect_(), GNUNET_TESTING_free_topology(), iterate_room_members(), iterate_store_members(), load_member_store(), log_namespaces(), log_topo(), save_member_store(), save_peer_store(), and send_simple_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_create()

struct GNUNET_CONTAINER_MultiShortmapIterator * GNUNET_CONTAINER_multishortmap_iterator_create ( const struct GNUNET_CONTAINER_MultiShortmap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multishortmap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 838 of file container_multishortmap.c.

840{
842
844 iter->map = map;
846 iter->me = map->map[0];
847 return iter;
848}
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
const struct GNUNET_CONTAINER_MultiShortmap * map
Map that we are iterating over.

References GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiShortmapIterator::map, map, GNUNET_CONTAINER_MultiShortmapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiShortmapIterator::modification_counter.

Referenced by backchannel_check_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_iterator_next ( struct GNUNET_CONTAINER_MultiShortmapIterator iter,
struct GNUNET_ShortHashCode key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 852 of file container_multishortmap.c.

856{
857 /* make sure the map has not been modified */
859
860 /* look for the next entry, skipping empty buckets */
861 while (1)
862 {
863 if (iter->idx >= iter->map->map_length)
864 return GNUNET_NO;
865 if (GNUNET_YES == iter->map->use_small_entries)
866 {
867 if (NULL != iter->me.sme)
868 {
869 if (NULL != key)
870 *key = *iter->me.sme->key;
871 if (NULL != value)
872 *value = iter->me.sme->value;
873 iter->me.sme = iter->me.sme->next;
874 return GNUNET_YES;
875 }
876 }
877 else
878 {
879 if (NULL != iter->me.bme)
880 {
881 if (NULL != key)
882 *key = iter->me.bme->key;
883 if (NULL != value)
884 *value = iter->me.bme->value;
885 iter->me.bme = iter->me.bme->next;
886 return GNUNET_YES;
887 }
888 }
889 iter->idx += 1;
890 if (iter->idx < iter->map->map_length)
891 iter->me = iter->map->map[iter->idx];
892 }
893}
unsigned int idx
Current bucket index.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry * map
All of our buckets.

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiShortmapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiShortmap::map, GNUNET_CONTAINER_MultiShortmapIterator::map, GNUNET_CONTAINER_MultiShortmap::map_length, GNUNET_CONTAINER_MultiShortmapIterator::me, GNUNET_CONTAINER_MultiShortmap::modification_counter, GNUNET_CONTAINER_MultiShortmapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiShortmap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by backchannel_check_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_destroy()

void GNUNET_CONTAINER_multishortmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiShortmapIterator iter)

Destroy a multishortmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 897 of file container_multishortmap.c.

899{
900 GNUNET_free (iter);
901}

References GNUNET_free.

◆ GNUNET_CONTAINER_multishortmap_get_multiple()

int GNUNET_CONTAINER_multishortmap_get_multiple ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration
Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 722 of file container_multishortmap.c.

727{
728 int count;
729 union MapEntry me;
730 union MapEntry *ce;
731
734 count = 0;
735 me = map->map[idx_of (map, key)];
737 {
738 struct SmallMapEntry *sme;
739
740 ce->sme = me.sme;
741 while (NULL != (sme = ce->sme))
742 {
743 ce->sme = sme->next;
744 if (0 != GNUNET_memcmp (key, sme->key))
745 continue;
746 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
747 {
749 return GNUNET_SYSERR;
750 }
751 count++;
752 }
753 }
754 else
755 {
756 struct BigMapEntry *bme;
757
758 ce->bme = me.bme;
759 while (NULL != (bme = ce->bme))
760 {
761 ce->bme = bme->next;
762 if (0 != GNUNET_memcmp (key, &bme->key))
763 continue;
764 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
765 {
767 return GNUNET_SYSERR;
768 }
769 count++;
770 }
771 }
773 return count;
774}

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by get_store_peer_of(), GNUNET_PQ_event_do_poll(), process_message_control(), and update_store_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_get_random()

unsigned int GNUNET_CONTAINER_multishortmap_get_random ( const struct GNUNET_CONTAINER_MultiShortmap map,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 789 of file container_multishortmap.c.

793{
794 unsigned int off;
795 union MapEntry me;
796
797 if (0 == map->size)
798 return 0;
799 if (NULL == it)
800 return 1;
802 for (unsigned int idx = 0; idx < map->map_length; idx++)
803 {
804 me = map->map[idx];
806 {
807 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
808 {
809 if (0 == off)
810 {
811 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
812 return GNUNET_SYSERR;
813 return 1;
814 }
815 off--;
816 }
817 }
818 else
819 {
820 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
821 {
822 if (0 == off)
823 {
824 if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
825 return GNUNET_SYSERR;
826 return 1;
827 }
828 off--;
829 }
830 }
831 }
832 GNUNET_break (0);
833 return GNUNET_SYSERR;
834}

References MapEntry::bme, GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_create()

struct GNUNET_CONTAINER_MultiUuidmap * GNUNET_CONTAINER_multiuuidmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 195 of file container_multiuuidmap.c.

196{
198
199 GNUNET_assert (len > 0);
201 map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
202 if (NULL == map->map)
203 {
205 return NULL;
206 }
207 map->map_length = len;
208 map->use_small_entries = do_not_copy_keys;
209 return map;
210}
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_destroy()

void GNUNET_CONTAINER_multiuuidmap_destroy ( struct GNUNET_CONTAINER_MultiUuidmap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 214 of file container_multiuuidmap.c.

216{
218 for (unsigned int i = 0; i < map->map_length; i++)
219 {
220 union MapEntry me;
221
222 me = map->map[i];
224 {
225 struct SmallMapEntry *sme;
226 struct SmallMapEntry *nxt;
227
228 nxt = me.sme;
229 while (NULL != (sme = nxt))
230 {
231 nxt = sme->next;
232 GNUNET_free (sme);
233 }
234 me.sme = NULL;
235 }
236 else
237 {
238 struct BigMapEntry *bme;
239 struct BigMapEntry *nxt;
240
241 nxt = me.bme;
242 while (NULL != (bme = nxt))
243 {
244 nxt = bme->next;
245 GNUNET_free (bme);
246 }
247 me.bme = NULL;
248 }
249 }
252}

References GNUNET_assert, GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by do_shutdown().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_get()

void * GNUNET_CONTAINER_multiuuidmap_get ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 283 of file container_multiuuidmap.c.

286{
287 union MapEntry me;
288
289 me = map->map[idx_of (map, key)];
291 {
292 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
293 if (0 == GNUNET_memcmp (key, sme->key))
294 return sme->value;
295 }
296 else
297 {
298 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
299 if (0 == GNUNET_memcmp (key, &bme->key))
300 return bme->value;
301 }
302 return NULL;
303}
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_reliability_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_remove ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 401 of file container_multiuuidmap.c.

404{
405 union MapEntry me;
406 unsigned int i;
407
409 i = idx_of (map, key);
410 me = map->map[i];
412 {
413 struct SmallMapEntry *p = NULL;
414
415 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
416 {
417 if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
418 {
419 if (NULL == p)
420 map->map[i].sme = sme->next;
421 else
422 p->next = sme->next;
424 GNUNET_free (sme);
425 map->size--;
426 return GNUNET_YES;
427 }
428 p = sme;
429 }
430 }
431 else
432 {
433 struct BigMapEntry *p = NULL;
434
435 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
436 {
437 if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
438 {
439 if (NULL == p)
440 map->map[i].bme = bme->next;
441 else
442 p->next = bme->next;
444 GNUNET_free (bme);
445 map->size--;
446 return GNUNET_YES;
447 }
448 p = bme;
449 }
450 }
451 return GNUNET_NO;
452}
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by free_pending_acknowledgement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_remove_all()

int GNUNET_CONTAINER_multiuuidmap_remove_all ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 456 of file container_multiuuidmap.c.

459{
460 union MapEntry me;
461 unsigned int i;
462 int ret;
463
465
466 ret = 0;
467 i = idx_of (map, key);
468 me = map->map[i];
470 {
471 struct SmallMapEntry *sme;
472 struct SmallMapEntry *p;
473
474 p = NULL;
475 sme = me.sme;
476 while (NULL != sme)
477 {
478 if (0 == GNUNET_memcmp (key, sme->key))
479 {
480 if (NULL == p)
481 map->map[i].sme = sme->next;
482 else
483 p->next = sme->next;
485 GNUNET_free (sme);
486 map->size--;
487 if (NULL == p)
488 sme = map->map[i].sme;
489 else
490 sme = p->next;
491 ret++;
492 }
493 else
494 {
495 p = sme;
496 sme = sme->next;
497 }
498 }
499 }
500 else
501 {
502 struct BigMapEntry *bme;
503 struct BigMapEntry *p;
504
505 p = NULL;
506 bme = me.bme;
507 while (NULL != bme)
508 {
509 if (0 == GNUNET_memcmp (key, &bme->key))
510 {
511 if (NULL == p)
512 map->map[i].bme = bme->next;
513 else
514 p->next = bme->next;
516 GNUNET_free (bme);
517 map->size--;
518 if (NULL == p)
519 bme = map->map[i].bme;
520 else
521 bme = p->next;
522 ret++;
523 }
524 else
525 {
526 p = bme;
527 bme = bme->next;
528 }
529 }
530 }
531 return ret;
532}

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 536 of file container_multiuuidmap.c.

539{
540 union MapEntry me;
541
542 me = map->map[idx_of (map, key)];
544 {
545 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
546 if (0 == GNUNET_memcmp (key, sme->key))
547 return GNUNET_YES;
548 }
549 else
550 {
551 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
552 if (0 == GNUNET_memcmp (key, &bme->key))
553 return GNUNET_YES;
554 }
555 return GNUNET_NO;
556}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains_value ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 560 of file container_multiuuidmap.c.

564{
565 union MapEntry me;
566
567 me = map->map[idx_of (map, key)];
569 {
570 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
571 if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
572 return GNUNET_YES;
573 }
574 else
575 {
576 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
577 if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
578 return GNUNET_YES;
579 }
580 return GNUNET_NO;
581}

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_put ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 643 of file container_multiuuidmap.c.

647{
648 union MapEntry me;
649 unsigned int i;
650
651 i = idx_of (map, key);
654 {
655 me = map->map[i];
657 {
658 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
659 if (0 == GNUNET_memcmp (key, sme->key))
660 {
662 return GNUNET_SYSERR;
663 sme->value = value;
664 return GNUNET_NO;
665 }
666 }
667 else
668 {
669 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
670 if (0 == GNUNET_memcmp (key, &bme->key))
671 {
673 return GNUNET_SYSERR;
674 bme->value = value;
675 return GNUNET_NO;
676 }
677 }
678 }
679 if (map->size / 3 >= map->map_length / 4)
680 {
681 grow (map);
682 i = idx_of (map, key);
683 }
685 {
686 struct SmallMapEntry *sme;
687
688 sme = GNUNET_new (struct SmallMapEntry);
689 sme->key = key;
690 sme->value = value;
691 sme->next = map->map[i].sme;
692 map->map[i].sme = sme;
693 }
694 else
695 {
696 struct BigMapEntry *bme;
697
698 bme = GNUNET_new (struct BigMapEntry);
699 bme->key = *key;
700 bme->value = value;
701 bme->next = map->map[i].bme;
702 map->map[i].bme = bme;
703 }
704 map->size++;
705 return GNUNET_OK;
706}
static void grow(struct GNUNET_CONTAINER_MultiUuidmap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by prepare_pending_acknowledgement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_size()

unsigned int GNUNET_CONTAINER_multiuuidmap_size ( const struct GNUNET_CONTAINER_MultiUuidmap map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 275 of file container_multiuuidmap.c.

277{
278 return map->size;
279}

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

◆ GNUNET_CONTAINER_multiuuidmap_iterate()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterate ( struct GNUNET_CONTAINER_MultiUuidmap map,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 307 of file container_multiuuidmap.c.

311{
312 int count;
313 union MapEntry me;
314 union MapEntry *ce;
315 struct GNUNET_Uuid kc;
316
317 count = 0;
318 GNUNET_assert (NULL != map);
321 for (unsigned int i = 0; i < map->map_length; i++)
322 {
323 me = map->map[i];
325 {
326 struct SmallMapEntry *sme;
327
328 ce->sme = me.sme;
329 while (NULL != (sme = ce->sme))
330 {
331 ce->sme = sme->next;
332 if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
333 {
335 return GNUNET_SYSERR;
336 }
337 count++;
338 }
339 }
340 else
341 {
342 struct BigMapEntry *bme;
343
344 ce->bme = me.bme;
345 while (NULL != (bme = ce->bme))
346 {
347 ce->bme = bme->next;
348 if (NULL != it)
349 {
350 kc = bme->key;
351 if (GNUNET_OK != it (it_cls, &kc, bme->value))
352 {
354 return GNUNET_SYSERR;
355 }
356 }
357 count++;
358 }
359 }
360 }
362 return count;
363}
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
A UUID, a 128 bit "random" value.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by do_shutdown().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_iterator_create()

struct GNUNET_CONTAINER_MultiUuidmapIterator * GNUNET_CONTAINER_multiuuidmap_iterator_create ( const struct GNUNET_CONTAINER_MultiUuidmap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multiuuidmap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 836 of file container_multiuuidmap.c.

838{
840
842 iter->map = map;
844 iter->me = map->map[0];
845 return iter;
846}
const struct GNUNET_CONTAINER_MultiUuidmap * map
Map that we are iterating over.
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.

References GNUNET_new, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiUuidmapIterator::map, map, GNUNET_CONTAINER_MultiUuidmapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiUuidmapIterator::modification_counter.

◆ GNUNET_CONTAINER_multiuuidmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterator_next ( struct GNUNET_CONTAINER_MultiUuidmapIterator iter,
struct GNUNET_Uuid key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 850 of file container_multiuuidmap.c.

854{
855 /* make sure the map has not been modified */
857
858 /* look for the next entry, skipping empty buckets */
859 while (1)
860 {
861 if (iter->idx >= iter->map->map_length)
862 return GNUNET_NO;
863 if (GNUNET_YES == iter->map->use_small_entries)
864 {
865 if (NULL != iter->me.sme)
866 {
867 if (NULL != key)
868 *key = *iter->me.sme->key;
869 if (NULL != value)
870 *value = iter->me.sme->value;
871 iter->me.sme = iter->me.sme->next;
872 return GNUNET_YES;
873 }
874 }
875 else
876 {
877 if (NULL != iter->me.bme)
878 {
879 if (NULL != key)
880 *key = iter->me.bme->key;
881 if (NULL != value)
882 *value = iter->me.bme->value;
883 iter->me.bme = iter->me.bme->next;
884 return GNUNET_YES;
885 }
886 }
887 iter->idx += 1;
888 if (iter->idx < iter->map->map_length)
889 iter->me = iter->map->map[iter->idx];
890 }
891}
unsigned int idx
Current bucket index.
union MapEntry * map
All of our buckets.
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiUuidmapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiUuidmap::map, GNUNET_CONTAINER_MultiUuidmapIterator::map, GNUNET_CONTAINER_MultiUuidmap::map_length, GNUNET_CONTAINER_MultiUuidmapIterator::me, GNUNET_CONTAINER_MultiUuidmap::modification_counter, GNUNET_CONTAINER_MultiUuidmapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiUuidmap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

◆ GNUNET_CONTAINER_multiuuidmap_iterator_destroy()

void GNUNET_CONTAINER_multiuuidmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiUuidmapIterator iter)

Destroy a multiuuidmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 895 of file container_multiuuidmap.c.

897{
898 GNUNET_free (iter);
899}

References GNUNET_free.

◆ GNUNET_CONTAINER_multiuuidmap_get_multiple()

int GNUNET_CONTAINER_multiuuidmap_get_multiple ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration
Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 720 of file container_multiuuidmap.c.

725{
726 int count;
727 union MapEntry me;
728 union MapEntry *ce;
729
732 count = 0;
733 me = map->map[idx_of (map, key)];
735 {
736 struct SmallMapEntry *sme;
737
738 ce->sme = me.sme;
739 while (NULL != (sme = ce->sme))
740 {
741 ce->sme = sme->next;
742 if (0 != GNUNET_memcmp (key, sme->key))
743 continue;
744 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
745 {
747 return GNUNET_SYSERR;
748 }
749 count++;
750 }
751 }
752 else
753 {
754 struct BigMapEntry *bme;
755
756 ce->bme = me.bme;
757 while (NULL != (bme = ce->bme))
758 {
759 ce->bme = bme->next;
760 if (0 != GNUNET_memcmp (key, &bme->key))
761 continue;
762 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
763 {
765 return GNUNET_SYSERR;
766 }
767 count++;
768 }
769 }
771 return count;
772}

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_get_random()

unsigned int GNUNET_CONTAINER_multiuuidmap_get_random ( const struct GNUNET_CONTAINER_MultiUuidmap map,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 787 of file container_multiuuidmap.c.

791{
792 unsigned int off;
793 union MapEntry me;
794
795 if (0 == map->size)
796 return 0;
797 if (NULL == it)
798 return 1;
800 for (unsigned int idx = 0; idx < map->map_length; idx++)
801 {
802 me = map->map[idx];
804 {
805 for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
806 {
807 if (0 == off)
808 {
809 if (GNUNET_OK != it (it_cls, sme->key, sme->value))
810 return GNUNET_SYSERR;
811 return 1;
812 }
813 off--;
814 }
815 }
816 else
817 {
818 for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
819 {
820 if (0 == off)
821 {
822 if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
823 return GNUNET_SYSERR;
824 return 1;
825 }
826 off--;
827 }
828 }
829 }
830 GNUNET_break (0);
831 return GNUNET_SYSERR;
832}

References MapEntry::bme, GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_create()

struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create ( unsigned int  len)

Create a 32-bit key multi hash map.

Parameters
leninitial size (map will grow as needed)
Returns
NULL on error

Create a 32-bit key multi hash map.

Parameters
leninitial size (map will grow as needed)
Returns
NULL on error

Definition at line 142 of file container_multihashmap32.c.

143{
145
146 GNUNET_assert (len > 0);
148 ret->map = GNUNET_malloc_large (len * sizeof(struct MapEntry *));
149 if (NULL == ret->map)
150 {
152 return NULL;
153 }
154 ret->map_length = len;
155 return ret;
156}
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, and ret.

Referenced by client_connect_cb(), CustomPeerMap_create(), GCT_create_tunnel(), GNUNET_CADET_connect(), GNUNET_MQ_assoc_add(), handle_fragment_box(), and initialize_key_to_element().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_destroy()

void GNUNET_CONTAINER_multihashmap32_destroy ( struct GNUNET_CONTAINER_MultiHashMap32 map)

Destroy a 32-bit key hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Destroy a 32-bit key hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 166 of file container_multihashmap32.c.

168{
169 struct MapEntry *e;
170
171 for (unsigned int i = 0; i < map->map_length; i++)
172 {
173 while (NULL != (e = map->map[i]))
174 {
175 map->map[i] = e->next;
176 GNUNET_free (e);
177 }
178 }
181}
struct MapEntry * next
If there is a hash collision, we create a linked list.

References GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, and MapEntry::next.

Referenced by _GSS_operation_destroy(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_tunnel(), free_virtual_link(), GNUNET_CADET_disconnect(), GNUNET_MQ_destroy(), and union_op_cancel().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_size()

unsigned int GNUNET_CONTAINER_multihashmap32_size ( const struct GNUNET_CONTAINER_MultiHashMap32 map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 200 of file container_multihashmap32.c.

202{
203 return map->size;
204}

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by client_disconnect_cb(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), CustomPeerMap_remove_peer_by_index(), CustomPeerMap_size(), GCT_count_channels(), handle_client_accept(), handle_client_evaluate(), send_client_done(), send_client_element(), union_accept(), and union_evaluate().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_get()

void * GNUNET_CONTAINER_multihashmap32_get ( const struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 208 of file container_multihashmap32.c.

211{
212 struct MapEntry *e;
213
214 e = map->map[idx_of (map, key)];
215 while (NULL != e)
216 {
217 if (key == e->key)
218 return e->value;
219 e = e->next;
220 }
221 return NULL;
222}
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key)
Compute the index of the bucket for the given key.
void * value
Value of the entry.
uint32_t key
Key for the entry.

References idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, MapEntry::next, and MapEntry::value.

Referenced by CustomPeerMap_get_peer_by_index(), CustomPeerMap_remove_peer(), find_channel(), get_next_free_ctn(), GNUNET_MQ_assoc_get(), GNUNET_MQ_assoc_remove(), handle_plaintext_channel_open(), and lookup_channel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_iterate()

int GNUNET_CONTAINER_multihashmap32_iterate ( struct GNUNET_CONTAINER_MultiHashMap32 map,
GNUNET_CONTAINER_MultiHashMapIterator32Callback  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 226 of file container_multihashmap32.c.

230{
231 int count;
232 struct MapEntry **ce;
233
234 count = 0;
235 GNUNET_assert (NULL != map);
238 for (unsigned int i = 0; i < map->map_length; i++)
239 {
240 struct MapEntry *e;
241
242 *ce = map->map[i];
243 while (NULL != (e = *ce))
244 {
245 *ce = e->next;
246 if (NULL != it)
247 {
248 if (GNUNET_OK != it (it_cls, e->key, e->value))
249 {
251 return GNUNET_SYSERR;
252 }
253 }
254 count++;
255 }
256 }
258 return count;
259}
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves agai...

References GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, MapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, and MapEntry::value.

Referenced by _GSS_operation_destroy(), client_disconnect_cb(), free_virtual_link(), GCT_change_estate(), GCT_debug(), GCT_destroy_tunnel_now(), GCT_iterate_channels(), GNUNET_CADET_disconnect(), handle_mq_error(), handle_union_p2p_full_done(), prepare_ibf(), and union_op_cancel().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove ( struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 280 of file container_multihashmap32.c.

284{
285 struct MapEntry *e;
286 struct MapEntry *p;
287 unsigned int i;
288
290
291 i = idx_of (map, key);
292 p = NULL;
293 e = map->map[i];
294 while (e != NULL)
295 {
296 if ((key == e->key) && (value == e->value))
297 {
298 if (p == NULL)
299 map->map[i] = e->next;
300 else
301 p->next = e->next;
303 GNUNET_free (e);
304 map->size--;
305 return GNUNET_YES;
306 }
307 p = e;
308 e = e->next;
309 }
310 return GNUNET_NO;
311}
static void update_next_cache(struct GNUNET_CONTAINER_MultiHashMap32 *map, const struct MapEntry *me)
We are about to free() the me, make sure it is not in the list of next values for any iterator in the...

References GNUNET_free, GNUNET_NO, GNUNET_YES, idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::modification_counter, MapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, update_next_cache(), value, and MapEntry::value.

Referenced by channel_destroy_iterator(), destroy_channel(), free_reassembly_context(), GCT_remove_channel(), GSC_handle_remote_channel_destroy(), and handle_channel_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_remove_all()

int GNUNET_CONTAINER_multihashmap32_remove_all ( struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 315 of file container_multihashmap32.c.

318{
319 struct MapEntry *e;
320 struct MapEntry *p;
321 unsigned int i;
322 int ret;
323
325
326 ret = 0;
327 i = idx_of (map, key);
328 p = NULL;
329 e = map->map[i];
330 while (e != NULL)
331 {
332 if (key == e->key)
333 {
334 if (p == NULL)
335 map->map[i] = e->next;
336 else
337 p->next = e->next;
339 GNUNET_free (e);
340 map->size--;
341 if (p == NULL)
342 e = map->map[i];
343 else
344 e = p->next;
345 ret++;
346 }
347 else
348 {
349 p = e;
350 e = e->next;
351 }
352 }
353 return ret;
354}

References GNUNET_free, idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::modification_counter, MapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, and update_next_cache().

Referenced by CustomPeerMap_remove_peer(), and GNUNET_MQ_assoc_remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains ( const struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 358 of file container_multihashmap32.c.

361{
362 struct MapEntry *e;
363
364 e = map->map[idx_of (map, key)];
365 while (e != NULL)
366 {
367 if (key == e->key)
368 return GNUNET_YES;
369 e = e->next;
370 }
371 return GNUNET_NO;
372}

References GNUNET_NO, GNUNET_YES, idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, and MapEntry::next.

Referenced by CustomPeerMap_clear(), CustomPeerMap_get_peer_by_index(), and CustomPeerMap_remove_peer_by_index().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains_value ( const struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 376 of file container_multihashmap32.c.

380{
381 struct MapEntry *e;
382
383 e = map->map[idx_of (map, key)];
384 while (e != NULL)
385 {
386 if ((key == e->key) && (e->value == value))
387 return GNUNET_YES;
388 e = e->next;
389 }
390 return GNUNET_NO;
391}

References GNUNET_NO, GNUNET_YES, idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, MapEntry::next, value, and MapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put ( struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists
Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if UNIQUE_ONLY was the option and the value already exists

Definition at line 449 of file container_multihashmap32.c.

454{
455 struct MapEntry *e;
456 unsigned int i;
457
458 i = idx_of (map, key);
461 {
462 e = map->map[i];
463 while (e != NULL)
464 {
465 if (key == e->key)
466 {
468 return GNUNET_SYSERR;
469 e->value = value;
470 return GNUNET_NO;
471 }
472 e = e->next;
473 }
474 }
475 if (map->size / 3 >= map->map_length / 4)
476 {
477 grow (map);
478 i = idx_of (map, key);
479 }
480 e = GNUNET_new (struct MapEntry);
481 e->key = key;
482 e->value = value;
483 e->next = map->map[i];
484 map->map[i] = e;
485 map->size++;
486 return GNUNET_OK;
487}
static void grow(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Grow the given map to a more appropriate size.

References GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, GNUNET_CONTAINER_MultiPeerMap::map_length, MapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, value, and MapEntry::value.

Referenced by create_channel(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), GCT_add_channel(), GNUNET_MQ_assoc_add(), GSC_bind(), handle_channel_create(), handle_fragment_box(), handle_plaintext_channel_open(), and op_register_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_get_multiple()

int GNUNET_CONTAINER_multihashmap32_get_multiple ( struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key,
GNUNET_CONTAINER_MultiHashMapIterator32Callback  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 491 of file container_multihashmap32.c.

496{
497 int count;
498 struct MapEntry *e;
499 struct MapEntry **ce;
500
501 count = 0;
504
505 *ce = map->map[idx_of (map, key)];
506 while (NULL != (e = *ce))
507 {
508 *ce = e->next;
509 if (key != e->key)
510 continue;
511 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, e->value)))
512 {
514 return GNUNET_SYSERR;
515 }
516 count++;
517 }
519 return count;
520}

References GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, MapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, map, MapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, and MapEntry::value.

Referenced by handle_fragment_box(), op_get_element(), and send_offers_for_key().

Here is the call graph for this function:
Here is the caller graph for this function: