GNUnet  0.19.3
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...
 
int 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...
 
int 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...
 
static int free_iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
static int iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. 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 329 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 669 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 952 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 1235 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 1518 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 356 of file gnunet_container_lib.h.

357 {
365 
371 
378 
389 };
@ 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 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#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, len, 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(), 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(), GNUNET_PEERSTORE_watch(), GNUNET_TESTBED_barrier_init_(), GSF_peer_connect_handler(), GSF_pending_request_init_(), GSF_plan_add_(), GST_barriers_init(), handle_alice_client_message(), handle_bob_client_message(), handle_client_accept(), handle_client_create_set(), handle_client_evaluate(), handle_client_join(), handle_link_controllers(), handle_port_open(), init_contact_store(), init_ego_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(), libgnunet_plugin_dhtu_ip_init(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search(), rfn_create(), run(), search_start(), send_full_set(), 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];
224  if (map->use_small_entries)
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  }
251  GNUNET_free (map->map);
252  GNUNET_free (map);
253 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
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, map, GNUNET_CONTAINER_MultiPeerMap::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 _GSS_operation_destroy(), check_key_type(), check_unique(), cleanup(), cleanup_handle(), clear_contact_store(), clear_ego_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(), disconnect_cb(), do_shutdown(), fail_intersection_operation(), free_download_context(), free_search_context(), free_update_information_graph(), GNUNET_CADET_disconnect(), GNUNET_DHT_disconnect(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_indexing_done(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_stop(), GNUNET_FS_share_tree_trim(), GNUNET_PEERSTORE_disconnect(), GNUNET_TESTBED_barrier_remove_(), GSF_peer_disconnect_handler(), GSF_plan_notify_peer_disconnect_(), GST_barriers_destroy(), intersection_op_cancel(), iterate_forward_members(), iterate_notify_about_members(), iterate_zones(), kill_slave(), libgnunet_plugin_datacache_heap_done(), libgnunet_plugin_dhtu_ip_done(), libgnunet_plugin_rest_openid_connect_done(), main(), print_finish(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), search_start(), shutdown_rest(), shutdown_task(), 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)];
288  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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_ego_lookup(), callback_ego_rename(), cancel_store_operation(), cb_intersection_element_removed(), change_srv_handle_member_id(), check_and_remove_pending_reversal(), check_member_session_history(), close_handle_room(), code_redirect(), collector(), consume_fail(), consume_ticket(), cookie_identity_interpretation(), create_response(), delete_store_ego(), 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_member_session(), get_redirect_state(), get_room_message(), 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_url_parameter_copy(), GNUNET_FS_add_to_index(), GNUNET_FS_handle_on_demand_block(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), handle_barrier_cancel(), handle_barrier_status(), handle_barrier_wait(), handle_client_set_add(), handle_delete_message(), handle_identity_update(), handle_member_id(), handle_port_close(), handle_recv_message(), handle_union_p2p_demand(), handle_union_p2p_offer(), handle_watch_record(), is_message_in_message_control_flow(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), mark_as_reachable(), message_token(), namecache_lookup_block(), namestore_flat_lookup_records(), namestore_get(), ns_lookup_result_cb(), open_handle_room(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), pending_reversal_timeout(), post_data_iter(), queue_destroy(), remove_high_frequency_keywords(), rfn_vote(), route_packet(), token_endpoint(), update_message_control_flow(), update_store_ego(), 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];
417  if (map->use_small_entries)
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;
430  update_next_cache_sme (map, sme);
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;
451  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), callback_ego_rename(), cancel_store_operation(), cb_intersection_element_removed(), clean_channel(), clean_request(), client_disconnect_it(), client_release_ports(), close_handle_room(), close_service_room(), consume_fail(), consume_ticket(), create_target(), delete_entries(), delete_store_ego(), delete_value(), expire_entries(), expire_oldest_entry(), filter_all(), free_channel_state(), free_destination_entry(), free_ego(), free_pending_request(), free_service_record(), get_store_message(), GNUNET_CADET_close_port(), GNUNET_DHT_get_stop(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), GNUNET_PEERSTORE_watch_cancel(), GNUNET_TESTBED_barrier_remove_(), 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(), handle_watch_cancel(), iterator_bf_reduce(), libgnunet_plugin_datacache_heap_done(), migrate_and_drop_keywords(), migrate_and_drop_metadata(), move_to_pending(), ns_lookup_result_cb(), pending_reversal_timeout(), pending_reversals_delete_it(), process_result_with_request(), reconstruct_cb(), reghost_free_iterator(), remove_all(), remove_barrier(), remove_client_query_record(), remove_iterator(), remove_member_session(), remove_store_contact(), setup_state_record(), unbind_store_ego(), and update_store_contact().

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];
477  if (map->use_small_entries)
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;
492  update_next_cache_sme (map, sme);
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;
523  update_next_cache_bme (map, bme);
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
Return value of the commandline.
Definition: gnunet-abd.c:81

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::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(), expire_blocks(), map_remove_iterator(), 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().

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)];
589  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), do_flood(), ego_get_all(), ego_get_response(), ego_sign_data(), forward_about_members(), get_gns_cont(), get_url_parameter_copy(), GNUNET_TESTBED_barrier_init_(), handle_barrier_cancel(), handle_barrier_init(), handle_room_message(), handle_union_p2p_offer(), 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(), peerinfo_get(), regex_next_edge(), register_host(), run(), and userinfo_endpoint().

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)];
618  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by bind_store_ego(), plan(), schedule_block_download(), and unbind_store_ego().

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];
723  if (map->use_small_entries)
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  }
755  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), bind_store_ego(), callback_ego_rename(), callback_scan_for_operations(), change_srv_handle_member_id(), check_dht_local_get_result_seen(), 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_cb(), 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(), GNUNET_PEERSTORE_watch(), GNUNET_TESTBED_barrier_init_(), GSF_pending_request_create_(), GSF_plan_add_(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_barrier_init(), handle_bob_client_message(), handle_bob_client_message_multipart(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_set_add(), handle_identity_update(), handle_p2p_get(), handle_port_open(), handle_room_message(), handle_union_p2p_inquiry(), handle_union_p2p_offer(), handle_watch(), header_iterator(), heap_plugin_put(), init_socket(), initialize_map_unfiltered(), iterate_copy_history(), 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(), open_service_room(), peerstore_flat_store_record(), post_data_iter(), process_ksk_result(), process_sks_result(), 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(), register_host(), rfn_vote(), route_packet(), run(), schedule_block_download(), set_result_cb(), setup_state_record(), store_all_states(), store_service(), token_endpoint(), transmit_pending(), update_member_chain_history(), update_message_control_flow(), update_sre_result_maps(), update_store_contact(), update_store_ego(), url_iterator(), and use_store_operation().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_size()

◆ 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);
320  ce = &map->next_cache[map->next_cache_off];
322  count = 0;
323  for (unsigned i = 0; i < map->map_length; i++)
324  {
325  me = map->map[i];
326  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), callback_set_handle_name(), check_all_done(), check_key_type(), cleanup(), cleanup_handle(), clear_contact_store(), clear_ego_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(), free_search_context(), get_member_session_of(), get_store_operation_type(), 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_MESSENGER_find_rooms(), GNUNET_PEERSTORE_disconnect(), GSF_iterate_pending_requests_(), GSF_peer_disconnect_handler(), GST_barriers_destroy(), GST_link_notify_disconnect(), 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(), heap_get_keys(), heap_plugin_get_closest(), heap_plugin_get_key(), initialize_key_to_element(), iterate_member_sessions(), iterate_zones(), kill_slave(), libgnunet_plugin_rest_openid_connect_done(), load_member_next_sessions(), main(), maybe_finish(), namecache_expire_blocks(), namestore_flat_iterate_records(), namestore_flat_zone_to_name(), peerstore_flat_delete_records(), peerstore_flat_expire_records(), peerstore_flat_iterate_records(), print_finish(), process_bf(), reconnect(), reconnect_cbk(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), reschedule_connect(), reset_cadet(), run(), save_member(), save_member_session_history(), save_message_store(), save_srv_handle_configuration(), save_state(), schedule_transmit_search_request(), send_alices_cryptodata_message(), send_bloomfilter(), send_full_set(), set_srv_handle_ego(), share_tree_trim(), shutdown_task(), signal_search_resume(), switch_member_session(), sync_member_contacts(), 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, map, GNUNET_CONTAINER_MultiHashMapIterator::map, GNUNET_CONTAINER_MultiPeerMap::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()

int 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 
791  ce = &map->next_cache[map->next_cache_off];
793  count = 0;
794  me = &map->map[idx_of (map, key)];
795  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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 callback_ego_create(), check_client_hello(), find_closest(), find_trees(), forward_reply(), GDS_CLIENTS_handle_reply(), GDS_ROUTING_add(), GDS_ROUTING_process(), get_cb(), GNUNET_FS_namespace_list_updateable(), GSF_plan_add_(), handle_dht_local_get_result_seen(), handle_p2p_get(), handle_p2p_put(), handle_port_open(), handle_put(), handle_reply(), heap_plugin_get_key(), heap_plugin_put(), heap_plugin_remove_key(), iter_hashcodes(), process_ksk_result(), process_sks_result(), regex_next_edge(), register_host(), and watch_notifier().

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];
865  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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  {
189  GNUNET_free (map);
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, len, map, GNUNET_CONTAINER_MultiPeerMap::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(), GAS_addresses_init(), GAS_connectivity_init(), GAS_preference_init(), GAS_reservations_init(), GNUNET_ATS_connectivity_init(), GNUNET_ATS_solvers_solver_start(), GNUNET_CORE_connect(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_PEER_intern(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GSC_SESSIONS_init(), GSF_cadet_start_server(), GSF_connected_peer_init_(), GSF_plan_init(), GST_ats_init(), GST_blacklist_add_peer(), GST_manipulation_init(), GST_neighbours_start(), GST_validation_start(), handle_client_send_request(), handle_connection_create(), handle_peer_push(), handle_suggest(), init_socket(), libgnunet_plugin_transport_http_client_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_init(), new_sub(), run(), setup_ac(), update_preference(), 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];
208  if (map->use_small_entries)
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  }
235  GNUNET_free (map->map);
236  GNUNET_free (map);
237 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::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(), cleanup_map(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_srv_room(), destroy_sub(), do_shutdown(), end(), GAS_addresses_done(), GAS_connectivity_done(), GAS_preference_client_disconnect(), GAS_preference_done(), GAS_reservations_done(), GDS_NEIGHBOURS_done(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), GNUNET_CORE_disconnect(), GNUNET_CRYPTO_ecc_dlog_release(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_core_disconnect(), GSC_SESSIONS_done(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_plan_done(), GST_ats_done(), GST_validation_stop(), handle_connection_create(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_done(), main(), 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)];
275  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_host_to_known_hosts(), addr_info_cb(), blacklist_check(), connect_notify(), consider_for_advertising(), cummulative_ack(), CustomPeerMap_get_index_pointer(), CustomPeerMap_remove_peer(), enter_srv_room_at(), find_session(), free_preference(), GAS_preference_get_by_peer(), GAS_reservations_set_bandwidth(), 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_(), GST_manipulation_manipulate_metrics(), GST_manipulation_peer_disconnect(), GST_manipulation_send(), GST_manipulation_set_metric(), handle_client_send(), handle_client_send_request(), handle_connect_notify(), handle_core_connect(), handle_disconnect_notify(), handle_dv_box(), handle_hello(), handle_notify_inbound(), handle_revocation_union_request(), handle_send_ready(), handle_suggest_cancel(), handle_tcp_nat_probe(), incoming_channel(), learn_dv_path(), lookup_neighbour(), lookup_virtual_link(), neighbour_find(), process_peer(), process_peer_monitoring_cb(), profiler_reply_handle(), profiler_reply_handle_info(), rebuild_srv_room_basement_structure(), reservations_reserve(), update_hello(), update_preference(), update_relative_values_for_peer(), View_change_len(), View_clear(), and View_remove_peer().

Here is the call 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];
399  if (map->use_small_entries)
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;
411  update_next_cache_sme (map, sme);
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;
431  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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 ats_perf_mon_cb(), callback_room_connect(), callback_room_disconnect(), cleanup_validation_entry(), client_delete_session(), destroy_ack_cummulator(), destroy_active_client_request(), destroy_ai(), destroy_it(), destroy_peer(), disconnect_and_free_peer_entry(), disconnect_cb(), enforce_del_address(), enter_srv_room_at(), free_addr_it(), free_address(), free_all_it(), free_backtalker(), free_dv_route(), free_iterator(), free_matching_requests(), free_neighbour(), free_peer(), free_preference(), free_tmps(), free_validation_state(), free_virtual_link(), GAS_reservations_set_bandwidth(), 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(), handle_send_transmit_continuation(), handle_tcp_nat_probe(), iterator(), neighbour_delete(), queue_destroy(), receiver_destroy(), sender_destroy(), server_delete_session(), stop_peer_request(), tcp_plugin_disconnect_session(), udp_disconnect_session(), and unix_plugin_session_disconnect().

Here is the call 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];
457  if (map->use_small_entries)
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;
472  update_next_cache_sme (map, sme);
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;
503  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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)];
531  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by addr_info_cb(), callback_room_disconnect(), check_access(), check_peer_known(), check_peer_valid(), check_removable(), clean_peer(), compute_rand_delay(), CustomPeerMap_contains_peer(), CustomPeerMap_put(), destroy_peer(), GAS_connectivity_has_peer(), get_peer_ctx(), GSC_CLIENTS_deliver_message(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_solicit_request(), handle_client_send_request(), handle_dv_learn(), handle_feedback(), handle_peer_pull_request(), handle_peer_push(), mq_notify_sent_cb(), send_pull_request(), send_push(), tcp_plugin_get_session(), 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)];
556  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_tcp_data(), set_prop_task(), tcp_plugin_send(), udp_plugin_send(), udp_plugin_update_session_timeout(), unix_plugin_send(), and unix_plugin_update_session_timeout().

Here is the call graph for this function:
Here is the caller 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];
645  if (map->use_small_entries)
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  }
677  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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_host_to_known_hosts(), add_valid_peer(), addr_info_cb(), ats_perf_mon_cb(), boot_queue(), callback_room_connect(), connect_peer(), core_connects(), create_peer_ctx(), cummulative_ack(), CustomPeerMap_put(), enforce_add_address(), enter_srv_room_at(), find_validation_entry(), GAS_addresses_add(), GAS_handle_request_address(), GAS_reservations_set_bandwidth(), GCP_get(), GDS_u_connect(), get_cadet(), GNUNET_ATS_connectivity_suggest(), 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_(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_blacklist_add_peer(), GST_manipulation_set_metric(), handle_add_queue_message(), handle_client_init(), handle_client_send(), handle_client_send_request(), handle_connect(), handle_connection_create(), handle_core_connect(), handle_dv_box(), handle_flow_control(), handle_suggest(), handle_tcp_nat_probe(), handle_tcp_welcome(), handle_validation_response(), http_client_plugin_get_session(), info_cb(), insert_in_sampler(), learn_dv_path(), make_peer(), mq_init(), new_peer_entry(), peer_id_cb(), process_peer_monitoring_cb(), run(), server_lookup_connection(), setup_ac(), setup_neighbour(), setup_queue(), setup_sender(), start_address_validation(), tcp_plugin_get_session(), udp_plugin_create_session(), unix_plugin_get_session(), update_preference(), View_change_len(), and View_put().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_size()

unsigned int GNUNET_CONTAINER_multipeermap_size ( const struct GNUNET_CONTAINER_MultiPeerMap map)

◆ 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);
304  ce = &map->next_cache[map->next_cache_off];
306  for (unsigned int i = 0; i < map->map_length; i++)
307  {
308  me = map->map[i];
309  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), ats_perf_mon_cb(), check_proof_of_work(), cleaning_task(), cleanup_map(), client_disconnect_cb(), client_lookup_session(), consider_for_advertising(), cron_flush_respect(), destroy_srv_room(), disconnect(), disconnect_and_schedule_reconnect(), do_shutdown(), end(), forward_srv_room_message(), GAS_addresses_destroy_all(), GAS_addresses_get_peer_info(), GAS_connectivity_done(), GAS_connectivity_remove_client(), GAS_normalization_update_property(), GAS_preference_client_disconnect(), GAS_preference_done(), GAS_reservations_done(), GCP_destroy_all_peers(), GCP_iterate_all(), get_random_peer_from_peermap(), get_valid_peers(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), 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_(), GST_ats_done(), GST_neighbours_iterate(), GST_validation_stop(), handle_client_start(), handle_dv_learn(), handle_get_all(), handle_monitor_start(), handle_notify(), handle_p2p_estimate(), http_client_plugin_setup_monitor(), http_server_plugin_setup_monitor(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_unix_done(), peers_terminate(), preference_aging(), recalculate_relative_preferences(), reconnect(), reconnect_later(), schedule_next_hello(), send_find_peer_message(), send_srv_room_message(), shutdown_task(), start_dv_learn(), store_valid_peers(), tcp_plugin_setup_monitor(), template_plugin_setup_monitor(), udp_plugin_setup_monitor(), unix_plugin_setup_monitor(), update_preference(), and utilization_transmission().

◆ 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, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMapIterator::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 
713  ce = &map->next_cache[map->next_cache_off];
715  count = 0;
716  me = map->map[idx_of (map, key)];
717  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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 ats_perf_mon_cb(), enc_notify_cb(), find_ai(), find_ai_no_session(), find_exact_address(), find_validation_entry(), GAS_addresses_get_peer_info(), GAS_handle_request_address_cancel(), get_active_address(), get_best_address(), GST_blacklist_test_allowed(), GST_clients_broadcast_disconnect(), GST_validation_get_addresses(), handle_add_queue_message(), handle_get(), handle_validation_response(), http_client_plugin_peer_disconnect(), http_server_plugin_disconnect_peer(), lookup_queue(), lookup_session(), server_lookup_connection(), setup_sender(), start_address_validation(), tcp_plugin_disconnect(), tcp_plugin_get_session(), try_handle_plaintext(), udp_disconnect(), udp_plugin_lookup_session(), unix_plugin_peer_disconnect(), and update_relative_values_for_peer().

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];
786  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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  {
204  GNUNET_free (map);
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, len, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by create_room(), GCO_init(), GCP_get(), GNUNET_PQ_connect2(), GNUNET_TESTING_command_new(), GNUNET_TESTING_get_topo_from_string(), init_member_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];
223  if (map->use_small_entries)
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  }
250  GNUNET_free (map->map);
251  GNUNET_free (map);
252 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::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(), destroy_peer(), destroy_room(), do_shutdown(), free_barriers_cb(), GCO_shutdown(), GNUNET_PQ_connect2(), GNUNET_PQ_disconnect(), GNUNET_TESTING_free_topology(), interpreter_delete_barriers(), shutdown_rest(), and TST_interpreter_finish_attached_cmds().

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)];
290  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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_topo_from_string(), sock_read(), start_helper(), and TST_interpreter_get_barrier().

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];
412  if (map->use_small_entries)
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;
424  update_next_cache_sme (map, sme);
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;
444  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), and start_dv_learn().

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];
470  if (map->use_small_entries)
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;
485  update_next_cache_sme (map, sme);
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;
516  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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)];
544  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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)];
569  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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];
658  if (map->use_small_entries)
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  }
686  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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_store_member(), barrier_attached(), connection_create(), GCP_add_connection(), GNUNET_PQ_event_listen(), GNUNET_TESTING_get_topo_from_string(), handle_connection_create(), handle_id_message(), handle_join_message(), kce_generate(), notify_connect(), start_dv_learn(), start_helper(), and TST_interpreter_add_barrier().

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);
319  ce = &map->next_cache[map->next_cache_off];
321  for (unsigned int i = 0; i < map->map_length; i++)
322  {
323  me = map->map[i];
324  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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(), find_room_member(), free_barriers_cb(), free_namespaces_cb(), GNUNET_PQ_event_reconnect_(), GNUNET_TESTING_free_topology(), interpreter_delete_barriers(), iterate_room_members(), iterate_store_members(), load_member_store(), log_namespaces(), log_topo(), save_member_store(), send_simple_run(), and TST_interpreter_finish_attached_cmds().

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, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiShortmapIterator::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 
732  ce = &map->next_cache[map->next_cache_off];
734  count = 0;
735  me = map->map[idx_of (map, key)];
736  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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 event_do_poll().

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];
805  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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  {
204  GNUNET_free (map);
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, len, map, GNUNET_CONTAINER_MultiPeerMap::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];
223  if (map->use_small_entries)
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  }
250  GNUNET_free (map->map);
251  GNUNET_free (map);
252 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::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)];
290  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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];
411  if (map->use_small_entries)
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;
423  update_next_cache_sme (map, sme);
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;
443  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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];
469  if (map->use_small_entries)
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;
484  update_next_cache_sme (map, sme);
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;
515  update_next_cache_bme (map, bme);
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, map, GNUNET_CONTAINER_MultiPeerMap::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)];
543  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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)];
568  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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];
656  if (map->use_small_entries)
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  }
684  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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()

int 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);
319  ce = &map->next_cache[map->next_cache_off];
321  for (unsigned int i = 0; i < map->map_length; i++)
322  {
323  me = map->map[i];
324  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiUuidmapIterator::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 
730  ce = &map->next_cache[map->next_cache_off];
732  count = 0;
733  me = map->map[idx_of (map, key)];
734  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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];
803  if (map->use_small_entries)
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, map, GNUNET_CONTAINER_MultiPeerMap::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  {
151  GNUNET_free (ret);
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, len, and ret.

Referenced by client_connect_cb(), CustomPeerMap_create(), GCT_create_tunnel(), GNUNET_CADET_connect(), GNUNET_MQ_assoc_add(), GNUNET_TESTBED_insert_opc_(), GNUNET_TESTBED_run(), GNUNET_TRANSPORT_monitor_plugins(), GST_cache_init(), GST_connection_pool_init(), 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  }
179  GNUNET_free (map->map);
180  GNUNET_free (map);
181 }
static struct Experiment * e

References e, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, and GNUNET_CONTAINER_MultiPeerMap::map_length.

Referenced by _GSS_operation_destroy(), cleanup(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_tunnel(), free_virtual_link(), GNUNET_CADET_disconnect(), GNUNET_MQ_destroy(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TRANSPORT_monitor_plugins_cancel(), GST_cache_clear(), GST_connection_pool_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 add_entry(), cleanup(), client_disconnect_cb(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), CustomPeerMap_remove_peer_by_index(), CustomPeerMap_size(), GCT_count_channels(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_remove_opc_(), GNUNET_TESTBED_shutdown_peers(), GST_cache_clear(), GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), handle_client_accept(), handle_client_evaluate(), interrupt(), 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,