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

◆ GNUNET_CONTAINER_PeerMapIterator

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

Iterator over hash map entries.

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

Definition at line 670 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_ShortmapIterator

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

Iterator over hash map entries.

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

Definition at line 953 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiUuidmapIteratorCallback

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

Iterator over uuid map entries.

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

Definition at line 1236 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiHashMapIterator32Callback

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

Iterator over hash map entries.

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

Definition at line 1519 of file gnunet_container_lib.h.

Enumeration Type Documentation

◆ GNUNET_CONTAINER_MultiHashMapOption

Options for storing values in the HashMap.

Enumerator
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE 

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

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

GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE 

Allow multiple values with the same key.

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY 

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

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST 

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

Definition at line 357 of file gnunet_container_lib.h.

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

Function Documentation

◆ GNUNET_CONTAINER_multihashmap_create()

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

Create a multi hash map.

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

Definition at line 181 of file container_multihashmap.c.

182 {
184 
185  GNUNET_assert (len > 0);
187  if (len * sizeof(union MapEntry) > GNUNET_MAX_MALLOC_CHECKED)
188  {
189  size_t s;
190  /* application *explicitly* requested very large map, hopefully
191  it checks the return value... */
192  s = len * sizeof(union MapEntry);
193  if ((s / sizeof(union MapEntry)) != len)
194  return NULL; /* integer overflow on multiplication */
195  if (NULL == (hm->map = GNUNET_malloc_large (s)))
196  {
197  /* out of memory */
199  "Out of memory allocating large hash map (%u entries)\n",
200  len);
201  GNUNET_free (hm);
202  return NULL;
203  }
204  }
205  else
206  {
207  hm->map = GNUNET_new_array (len, union MapEntry);
208  }
209  hm->map_length = len;
210  hm->use_small_entries = do_not_copy_keys;
211  return hm;
212 }
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 216 of file container_multihashmap.c.

218 {
220  for (unsigned int i = 0; i < map->map_length; i++)
221  {
222  union MapEntry me;
223 
224  me = map->map[i];
225  if (map->use_small_entries)
226  {
227  struct SmallMapEntry *sme;
228  struct SmallMapEntry *nxt;
229 
230  nxt = me.sme;
231  while (NULL != (sme = nxt))
232  {
233  nxt = sme->next;
234  GNUNET_free (sme);
235  }
236  me.sme = NULL;
237  }
238  else
239  {
240  struct BigMapEntry *bme;
241  struct BigMapEntry *nxt;
242 
243  nxt = me.bme;
244  while (NULL != (bme = nxt))
245  {
246  nxt = bme->next;
247  GNUNET_free (bme);
248  }
249  me.bme = NULL;
250  }
251  }
252  GNUNET_free (map->map);
253  GNUNET_free (map);
254 }
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 282 of file container_multihashmap.c.

285 {
286  union MapEntry me;
287 
288  me = map->map[idx_of (map, key)];
289  if (map->use_small_entries)
290  {
291  struct SmallMapEntry *sme;
292 
293  for (sme = me.sme; NULL != sme; sme = sme->next)
294  if (0 == GNUNET_memcmp (key, sme->key))
295  return sme->value;
296  }
297  else
298  {
299  struct BigMapEntry *bme;
300 
301  for (bme = me.bme; NULL != bme; bme = bme->next)
302  if (0 == GNUNET_memcmp (key, &bme->key))
303  return bme->value;
304  }
305  return NULL;
306 }
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(), mq_init(), 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(), sock_read(), 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 397 of file container_multihashmap.c.

410 {
411  union MapEntry me;
412  unsigned int i;
413 
415 
416  i = idx_of (map, key);
417  me = map->map[i];
418  if (map->use_small_entries)
419  {
420  struct SmallMapEntry *p;
421 
422  p = NULL;
423  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
424  {
425  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
426  {
427  if (NULL == p)
428  map->map[i].sme = sme->next;
429  else
430  p->next = sme->next;
431  update_next_cache_sme (map, sme);
432  GNUNET_free (sme);
433  map->size--;
434  return GNUNET_YES;
435  }
436  p = sme;
437  }
438  }
439  else
440  {
441  struct BigMapEntry *p;
442 
443  p = NULL;
444  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
445  {
446  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
447  {
448  if (NULL == p)
449  map->map[i].bme = bme->next;
450  else
451  p->next = bme->next;
452  update_next_cache_bme (map, bme);
453  GNUNET_free (bme);
454  map->size--;
455  return GNUNET_YES;
456  }
457  p = bme;
458  }
459  }
460  return GNUNET_NO;
461 }
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 map, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and MapEntry::sme.

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(), peer_destroy(), 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().

◆ 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 465 of file container_multihashmap.c.

468 {
469  union MapEntry me;
470  unsigned int i;
471  int ret;
472 
474 
475  ret = 0;
476  i = idx_of (map, key);
477  me = map->map[i];
478  if (map->use_small_entries)
479  {
480  struct SmallMapEntry *sme;
481  struct SmallMapEntry *p;
482 
483  p = NULL;
484  sme = me.sme;
485  while (NULL != sme)
486  {
487  if (0 == GNUNET_memcmp (key, sme->key))
488  {
489  if (NULL == p)
490  map->map[i].sme = sme->next;
491  else
492  p->next = sme->next;
493  update_next_cache_sme (map, sme);
494  GNUNET_free (sme);
495  map->size--;
496  if (NULL == p)
497  sme = map->map[i].sme;
498  else
499  sme = p->next;
500  ret++;
501  }
502  else
503  {
504  p = sme;
505  sme = sme->next;
506  }
507  }
508  }
509  else
510  {
511  struct BigMapEntry *bme;
512  struct BigMapEntry *p;
513 
514  p = NULL;
515  bme = me.bme;
516  while (NULL != bme)
517  {
518  if (0 == GNUNET_memcmp (key, &bme->key))
519  {
520  if (NULL == p)
521  map->map[i].bme = bme->next;
522  else
523  p->next = bme->next;
524  update_next_cache_bme (map, bme);
525  GNUNET_free (bme);
526  map->size--;
527  if (NULL == p)
528  bme = map->map[i].bme;
529  else
530  bme = p->next;
531  ret++;
532  }
533  else
534  {
535  p = bme;
536  bme = bme->next;
537  }
538  }
539  }
540  return ret;
541 }
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 572 of file container_multihashmap.c.

573 {
574  unsigned int ret;
575 
576  ret = map->size;
578  return ret;
579 }
static int remove_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Callback used to remove all entries from the map.
enum GNUNET_GenericReturnValue 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 572 of file container_multihashmap.c.

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

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 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 572 of file container_multihashmap.c.

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

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

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 645 of file container_multihashmap.c.

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

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(), sock_read(), store_all_states(), store_service(), token_endpoint(), transmit_pending(), update_member_chain_history(), update_message_control_flow(), update_sre_result_maps(), update_store_contact(), update_store_ego(), url_iterator(), and use_store_operation().

◆ GNUNET_CONTAINER_multihashmap_size()

◆ GNUNET_CONTAINER_multihashmap_iterate()

enum GNUNET_GenericReturnValue 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 282 of file container_multihashmap.c.

314 {
315  int count;
316  union MapEntry me;
317  union MapEntry *ce;
318  struct GNUNET_HashCode kc;
319 
320  GNUNET_assert (NULL != map);
321  ce = &map->next_cache[map->next_cache_off];
323  count = 0;
324  for (unsigned i = 0; i < map->map_length; i++)
325  {
326  me = map->map[i];
327  if (map->use_small_entries)
328  {
329  struct SmallMapEntry *sme;
330 
331  ce->sme = me.sme;
332  while (NULL != (sme = ce->sme))
333  {
334  ce->sme = sme->next;
335  if (NULL != it)
336  {
337  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
338  {
340  return GNUNET_SYSERR;
341  }
342  }
343  count++;
344  }
345  }
346  else
347  {
348  struct BigMapEntry *bme;
349 
350  ce->bme = me.bme;
351  while (NULL != (bme = ce->bme))
352  {
353  ce->bme = bme->next;
354  if (NULL != it)
355  {
356  kc = bme->key;
357  if (GNUNET_OK != it (it_cls, &kc, bme->value))
358  {
360  return GNUNET_SYSERR;
361  }
362  }
363  count++;
364  }
365  }
366  }
368  return count;
369 }
#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.

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 909 of file container_multihashmap.c.

911 {
913 
915  iter->map = map;
917  iter->me = map->map[0];
918  return iter;
919 }
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 909 of file container_multihashmap.c.

927 {
928  /* make sure the map has not been modified */
930 
931  /* look for the next entry, skipping empty buckets */
932  while (1)
933  {
934  if (iter->idx >= iter->map->map_length)
935  return GNUNET_NO;
936  if (GNUNET_YES == iter->map->use_small_entries)
937  {
938  if (NULL != iter->me.sme)
939  {
940  if (NULL != key)
941  *key = *iter->me.sme->key;
942  if (NULL != value)
943  *value = iter->me.sme->value;
944  iter->me.sme = iter->me.sme->next;
945  return GNUNET_YES;
946  }
947  }
948  else
949  {
950  if (NULL != iter->me.bme)
951  {
952  if (NULL != key)
953  *key = iter->me.bme->key;
954  if (NULL != value)
955  *value = iter->me.bme->value;
956  iter->me.bme = iter->me.bme->next;
957  return GNUNET_YES;
958  }
959  }
960  iter->idx += 1;
961  if (iter->idx < iter->map->map_length)
962  iter->me = iter->map->map[iter->idx];
963  }
964 }
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...

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 968 of file container_multihashmap.c.

970 {
971  GNUNET_free (iter);
972 }

References GNUNET_free.

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

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_get_multiple()

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

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

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

Definition at line 645 of file container_multihashmap.c.

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

References MapEntry::bme, GNUNET_assert, GNUNET_free, GNUNET_malloc_large, idx_of(), BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

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 849 of file container_multihashmap.c.

853 {
854  unsigned int off;
855  unsigned int idx;
856  union MapEntry me;
857 
858  if (0 == map->size)
859  return 0;
860  if (NULL == it)
861  return 1;
863  for (idx = 0; idx < map->map_length; idx++)
864  {
865  me = map->map[idx];
866  if (map->use_small_entries)
867  {
868  struct SmallMapEntry *sme;
869  struct SmallMapEntry *nxt;
870 
871  nxt = me.sme;
872  while (NULL != (sme = nxt))
873  {
874  nxt = sme->next;
875  if (0 == off)
876  {
877  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
878  return GNUNET_SYSERR;
879  return 1;
880  }
881  off--;
882  }
883  }
884  else
885  {
886  struct BigMapEntry *bme;
887  struct BigMapEntry *nxt;
888 
889  nxt = me.bme;
890  while (NULL != (bme = nxt))
891  {
892  nxt = bme->next;
893  if (0 == off)
894  {
895  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
896  return GNUNET_SYSERR;
897  return 1;
898  }
899  off--;
900  }
901  }
902  }
903  GNUNET_break (0);
904  return GNUNET_SYSERR;
905 }
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 379 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 map, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and MapEntry::sme.

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().

◆ 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 }

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

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 444 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_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 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 444 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 }

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 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 829 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.

◆ 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 196 of file container_multishortmap.c.

197 {
199 
200  GNUNET_assert (len > 0);
202  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
203  if (NULL == map->map)
204  {
205  GNUNET_free (map);
206  return NULL;
207  }
208  map->map_length = len;
209  map->use_small_entries = do_not_copy_keys;
210  return map;
211 }
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_cmd_end(), 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 215 of file container_multishortmap.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 }

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 284 of file container_multishortmap.c.

287 {
288  union MapEntry me;
289 
290  me = map->map[idx_of (map, key)];
291  if (map->use_small_entries)
292  {
293  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
294  if (0 == GNUNET_memcmp (key, sme->key))
295  return sme->value;
296  }
297  else
298  {
299  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
300  if (0 == GNUNET_memcmp (key, &bme->key))
301  return bme->value;
302  }
303  return NULL;
304 }
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 402 of file container_multishortmap.c.

406 {
407  union MapEntry me;
408  unsigned int i;
409 
411  i = idx_of (map, key);
412  me = map->map[i];
413  if (map->use_small_entries)
414  {
415  struct SmallMapEntry *p = NULL;
416 
417  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
418  {
419  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
420  {
421  if (NULL == p)
422  map->map[i].sme = sme->next;
423  else
424  p->next = sme->next;
425  update_next_cache_sme (map, sme);
426  GNUNET_free (sme);
427  map->size--;
428  return GNUNET_YES;
429  }
430  p = sme;
431  }
432  }
433  else
434  {
435  struct BigMapEntry *p = NULL;
436 
437  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
438  {
439  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
440  {
441  if (NULL == p)
442  map->map[i].bme = bme->next;
443  else
444  p->next = bme->next;
445  update_next_cache_bme (map, bme);
446  GNUNET_free (bme);
447  map->size--;
448  return GNUNET_YES;
449  }
450  p = bme;
451  }
452  }
453  return GNUNET_NO;
454 }
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 458 of file container_multishortmap.c.

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

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 538 of file container_multishortmap.c.

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

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 562 of file container_multishortmap.c.

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

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 592 of file container_multishortmap.c.

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

References MapEntry::bme, GNUNET_free, GNUNET_malloc_large, idx_of(), BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

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 276 of file container_multishortmap.c.

278 {
279  return map->size;
280 }

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 308 of file container_multishortmap.c.

312 {
313  int count;
314  union MapEntry me;
315  union MapEntry *ce;
316  struct GNUNET_ShortHashCode kc;
317 
318  count = 0;
319  GNUNET_assert (NULL != map);
320  ce = &map->next_cache[map->next_cache_off];
322  for (unsigned int i = 0; i < map->map_length; i++)
323  {
324  me = map->map[i];
325  if (map->use_small_entries)
326  {
327  struct SmallMapEntry *sme;
328 
329  ce->sme = me.sme;
330  while (NULL != (sme = ce->sme))
331  {
332  ce->sme = sme->next;
333  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
334  {
336  return GNUNET_SYSERR;
337  }
338  count++;
339  }
340  }
341  else
342  {
343  struct BigMapEntry *bme;
344 
345  ce->bme = me.bme;
346  while (NULL != (bme = ce->bme))
347  {
348  ce->bme = bme->next;
349  if (NULL != it)
350  {
351  kc = bme->key;
352  if (GNUNET_OK != it (it_cls, &kc, bme->value))
353  {
355  return GNUNET_SYSERR;
356  }
357  }
358  count++;
359  }
360  }
361  }
363  return count;
364 }
#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 839 of file container_multishortmap.c.

841 {
843 
845  iter->map = map;
847  iter->me = map->map[0];
848  return iter;
849 }
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 839 of file container_multishortmap.c.

857 {
858  /* make sure the map has not been modified */
860 
861  /* look for the next entry, skipping empty buckets */
862  while (1)
863  {
864  if (iter->idx >= iter->map->map_length)
865  return GNUNET_NO;
866  if (GNUNET_YES == iter->map->use_small_entries)
867  {
868  if (NULL != iter->me.sme)
869  {
870  if (NULL != key)
871  *key = *iter->me.sme->key;
872  if (NULL != value)
873  *value = iter->me.sme->value;
874  iter->me.sme = iter->me.sme->next;
875  return GNUNET_YES;
876  }
877  }
878  else
879  {
880  if (NULL != iter->me.bme)
881  {
882  if (NULL != key)
883  *key = iter->me.bme->key;
884  if (NULL != value)
885  *value = iter->me.bme->value;
886  iter->me.bme = iter->me.bme->next;
887  return GNUNET_YES;
888  }
889  }
890  iter->idx += 1;
891  if (iter->idx < iter->map->map_length)
892  iter->me = iter->map->map[iter->idx];
893  }
894 }
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.

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 898 of file container_multishortmap.c.

900 {
901  GNUNET_free (iter);
902 }

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 723 of file container_multishortmap.c.

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

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 GNUNET_PQ_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 790 of file container_multishortmap.c.

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

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 196 of file container_multiuuidmap.c.

197 {
199 
200  GNUNET_assert (len > 0);
202  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
203  if (NULL == map->map)
204  {
205  GNUNET_free (map);
206  return NULL;
207  }
208  map->map_length = len;
209  map->use_small_entries = do_not_copy_keys;
210  return map;
211 }
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 215 of file container_multiuuidmap.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 }

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 284 of file container_multiuuidmap.c.

287 {
288  union MapEntry me;
289 
290  me = map->map[idx_of (map, key)];
291  if (map->use_small_entries)
292  {
293  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
294  if (0 == GNUNET_memcmp (key, sme->key))
295  return sme->value;
296  }
297  else
298  {
299  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
300  if (0 == GNUNET_memcmp (key, &bme->key))
301  return bme->value;
302  }
303  return NULL;
304 }
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 392 of file container_multiuuidmap.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_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 map, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and MapEntry::sme.

Referenced by free_pending_acknowledgement().

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 457 of file container_multiuuidmap.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 }

◆ 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 457 of file container_multiuuidmap.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_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_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 457 of file container_multiuuidmap.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 }

◆ 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 591 of file container_multiuuidmap.c.

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

References MapEntry::bme, GNUNET_free, GNUNET_malloc_large, idx_of(), BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

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 276 of file container_multiuuidmap.c.

278 {
279  return map->size;
280 }

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

◆ GNUNET_CONTAINER_multiuuidmap_iterate()

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

Iterate over all entries in the map.

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

Definition at line 284 of file container_multiuuidmap.c.

312 {
313  int count;
314  union MapEntry me;
315  union MapEntry *ce;
316  struct GNUNET_Uuid kc;
317 
318  count = 0;
319  GNUNET_assert (NULL != map);
320  ce = &map->next_cache[map->next_cache_off];
322  for (unsigned int i = 0; i < map->map_length; i++)
323  {
324  me = map->map[i];
325  if (map->use_small_entries)
326  {
327  struct SmallMapEntry *sme;
328 
329  ce->sme = me.sme;
330  while (NULL != (sme = ce->sme))
331  {
332  ce->sme = sme->next;
333  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
334  {
336  return GNUNET_SYSERR;
337  }
338  count++;
339  }
340  }
341  else
342  {
343  struct BigMapEntry *bme;
344 
345  ce->bme = me.bme;
346  while (NULL != (bme = ce->bme))
347  {
348  ce->bme = bme->next;
349  if (NULL != it)
350  {
351  kc = bme->key;
352  if (GNUNET_OK != it (it_cls, &kc, bme->value))
353  {
355  return GNUNET_SYSERR;
356  }
357  }
358  count++;
359  }
360  }
361  }
363  return count;
364 }
#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.

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 837 of file container_multiuuidmap.c.

839 {
841 
843  iter->map = map;
845  iter->me = map->map[0];
846  return iter;
847 }
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 837 of file container_multiuuidmap.c.

855 {
856  /* make sure the map has not been modified */
858 
859  /* look for the next entry, skipping empty buckets */
860  while (1)
861  {
862  if (iter->idx >= iter->map->map_length)
863  return GNUNET_NO;
864  if (GNUNET_YES == iter->map->use_small_entries)
865  {
866  if (NULL != iter->me.sme)
867  {
868  if (NULL != key)
869  *key = *iter->me.sme->key;
870  if (NULL != value)
871  *value = iter->me.sme->value;
872  iter->me.sme = iter->me.sme->next;
873  return GNUNET_YES;
874  }
875  }
876  else
877  {
878  if (NULL != iter->me.bme)
879  {
880  if (NULL != key)
881  *key = iter->me.bme->key;
882  if (NULL != value)
883  *value = iter->me.bme->value;
884  iter->me.bme = iter->me.bme->next;
885  return GNUNET_YES;
886  }
887  }
888  iter->idx += 1;
889  if (iter->idx < iter->map->map_length)
890  iter->me = iter->map->map[iter->idx];
891  }
892 }
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...

◆ 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 896 of file container_multiuuidmap.c.

898 {
899  GNUNET_free (iter);
900 }

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 721 of file container_multiuuidmap.c.

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

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 788 of file container_multiuuidmap.c.

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

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 143 of file container_multihashmap32.c.

144 {
146 
147  GNUNET_assert (len > 0);
149  ret->map = GNUNET_malloc_large (len * sizeof(struct MapEntry *));
150  if (NULL == ret->map)
151  {
152  GNUNET_free (ret);
153  return NULL;
154  }
155  ret->map_length = len;
156  return ret;
157 }
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 167 of file container_multihashmap32.c.

169 {
170  struct MapEntry *e;
171 
172  for (unsigned int i = 0; i < map->map_length; i++)
173  {
174  while (NULL != (e = map->map[i]))
175  {
176  map->map[i] = e->next;
177  GNUNET_free (e);
178  }
179  }
180  GNUNET_free (map->map);
181  GNUNET_free (map);
182 }
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 201 of file container_multihashmap32.c.

203 {
204  return map->size;
205 }

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 209 of file container_multihashmap32.c.

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

References e, idx_of(), key, map, and GNUNET_CONTAINER_MultiPeerMap::map.

Referenced by cache_lookup(), client_get_next_ccn(), CustomPeerMap_get_peer_by_index(), CustomPeerMap_remove_peer(), find_channel(), GNUNET_MQ_assoc_get(), GNUNET_MQ_assoc_remove(), GST_connection_pool_get_handle(), handle_plaintext_channel_open(), and lookup_channel().

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

◆ GNUNET_CONTAINER_multihashmap32_iterate()

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

Iterate over all entries in the map.

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

Definition at line 227 of file container_multihashmap32.c.

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

References e, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and NEXT_CACHE_SIZE.

Referenced by _GSS_operation_destroy(), client_disconnect_cb(), free_virtual_link(), GCT_change_estate(), GCT_debug(), GCT_destroy_tunnel_now(), GCT_iterate_channels(), GNUNET_CADET_disconnect(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TRANSPORT_monitor_plugins_cancel(), GST_cache_clear(), GST_connection_pool_destroy(), handle_mq_error(), handle_union_p2p_full_done(), prepare_ibf(), rc_cleanup_operations(), reconnect_plugin_ctx(), and union_op_cancel().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_remove()

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

Remove the given key-value pair from the map.

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

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

Definition at line 271 of file container_multihashmap32.c.

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

References map, me, GNUNET_CONTAINER_MultiPeerMap::next_cache, and GNUNET_CONTAINER_MultiPeerMap::next_cache_off.

Referenced by add_entry(), cache_clear_iterator(), channel_destroy_iterator(), destroy_channel(), destroy_pooled_connection(), free_entry(), free_reassembly_context(), GCT_remove_channel(), GNUNET_TESTBED_remove_opc_(), GSC_handle_remote_channel_destroy(), handle_channel_destroy(), handle_event(), opc_free_iterator(), and remove_rcop().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_remove_all()

int GNUNET_CONTAINER_multihashmap32_remove_all ( struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

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

Definition at line 316 of file container_multihashmap32.c.

319 {
320  struct MapEntry *e;
321  struct MapEntry *p;
322  unsigned int i;
323  int ret;
324 
326 
327  ret = 0;
328  i = idx_of (map, key);
329  p = NULL;
330  e = map->map[i];
331  while (e != NULL)
332  {
333  if (key =