GNUnet  0.11.x
Typedefs | Enumerations | Enumerator | Functions
Container library: MultiHashMap

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

Typedefs

typedef int(* GNUNET_CONTAINER_MulitHashMapIteratorCallback) (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef int(* GNUNET_CONTAINER_PeerMapIterator) (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
typedef int(* GNUNET_CONTAINER_ShortmapIterator) (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef int(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback) (void *cls, const struct GNUNET_Uuid *key, void *value)
 Iterator over uuid map entries. More...
 
typedef int(* GNUNET_CONTAINER_MulitHashMapIterator32Callback) (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...
 
int 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...
 
int 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...
 
int 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...
 
int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback 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...
 
int GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, struct GNUNET_HashCode *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
 Destroy a multihashmap iterator. More...
 
int GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MulitHashMapIteratorCallback 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_MulitHashMapIteratorCallback 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int 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...
 
int GNUNET_CONTAINER_multiuuidmap_put (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multiuuidmap_size (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multiuuidmap_iterate (struct GNUNET_CONTAINER_MultiUuidmap *map, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiUuidmapIteratorGNUNET_CONTAINER_multiuuidmap_iterator_create (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Create an iterator for a multihashmap. More...
 
int 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_MulitHashMapIterator32Callback it, void *it_cls)
 Iterate over all entries in the map. More...
 
int 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...
 
int 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...
 
int 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...
 
int 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_MulitHashMapIterator32Callback 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_MulitHashMapIteratorCallback

typedef int(* GNUNET_CONTAINER_MulitHashMapIteratorCallback) (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 769 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_PeerMapIterator

typedef int(* 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 1053 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_ShortmapIterator

typedef int(* 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 1332 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiUuidmapIteratorCallback

typedef int(* 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 1615 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MulitHashMapIterator32Callback

typedef int(* GNUNET_CONTAINER_MulitHashMapIterator32Callback) (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 1911 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 722 of file gnunet_container_lib.h.

723 {
731 
737 
744 
755 };
@ 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 194 of file container_multihashmap.c.

195 {
197 
198  GNUNET_assert (len > 0);
200  if (len * sizeof(union MapEntry) > GNUNET_MAX_MALLOC_CHECKED)
201  {
202  size_t s;
203  /* application *explicitly* requested very large map, hopefully
204  it checks the return value... */
205  s = len * sizeof(union MapEntry);
206  if ((s / sizeof(union MapEntry)) != len)
207  return NULL; /* integer overflow on multiplication */
208  if (NULL == (hm->map = GNUNET_malloc_large (s)))
209  {
210  /* out of memory */
212  "Out of memory allocating large hash map (%u entries)\n",
213  len);
214  GNUNET_free (hm);
215  return NULL;
216  }
217  }
218  else
219  {
220  hm->map = GNUNET_new_array (len, union MapEntry);
221  }
222  hm->map_length = len;
223  hm->use_small_entries = do_not_copy_keys;
224  return hm;
225 }
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(), 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 235 of file container_multihashmap.c.

237 {
239  for (unsigned int i = 0; i < map->map_length; i++)
240  {
241  union MapEntry me;
242 
243  me = map->map[i];
244  if (map->use_small_entries)
245  {
246  struct SmallMapEntry *sme;
247  struct SmallMapEntry *nxt;
248 
249  nxt = me.sme;
250  while (NULL != (sme = nxt))
251  {
252  nxt = sme->next;
253  GNUNET_free (sme);
254  }
255  me.sme = NULL;
256  }
257  else
258  {
259  struct BigMapEntry *bme;
260  struct BigMapEntry *nxt;
261 
262  nxt = me.bme;
263  while (NULL != (bme = nxt))
264  {
265  nxt = bme->next;
266  GNUNET_free (bme);
267  }
268  me.bme = NULL;
269  }
270  }
271  GNUNET_free (map->map);
272  GNUNET_free (map);
273 }
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_member_session_completion(), 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(), 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_IDENTITY_disconnect(), 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_datastore_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 317 of file container_multihashmap.c.

320 {
321  union MapEntry me;
322 
323  me = map->map[idx_of (map, key)];
324  if (map->use_small_entries)
325  {
326  struct SmallMapEntry *sme;
327 
328  for (sme = me.sme; NULL != sme; sme = sme->next)
329  if (0 == GNUNET_memcmp (key, sme->key))
330  return sme->value;
331  }
332  else
333  {
334  struct BigMapEntry *bme;
335 
336  for (bme = me.bme; NULL != bme; bme = bme->next)
337  if (0 == GNUNET_memcmp (key, &bme->key))
338  return bme->value;
339  }
340  return NULL;
341 }
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_rename(), cancel_store_operation(), cb_intersection_element_removed(), change_handle_member_id(), check_member_session_history(), close_handle_room(), code_redirect(), collector(), consume_timeout(), cookie_identity_interpretation(), create_response(), diff_insert(), entry_handle_room_at(), execute_add(), execute_remove(), find_port(), find_target(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_CLIENTS_handle_reply(), get_file_handle(), get_gns_cont(), get_handle_contact(), get_handle_member_id(), get_member_session(), get_redirect_state(), get_room_message(), get_room_sender(), get_service_room(), 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_set_default(), 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_store_ego(), lookup_task(), mark_as_reachable(), message_token(), namecache_lookup_block(), namestore_flat_lookup_records(), namestore_get(), ns_lookup_result_cb(), open_handle_room(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), post_data_iter(), queue_destroy(), remove_high_frequency_keywords(), rfn_vote(), route_packet(), token_endpoint(), update_message_control_flow(), update_store_ego(), use_store_operation(), and userinfo_endpoint().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove()

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

465 {
466  union MapEntry me;
467  unsigned int i;
468 
470 
471  i = idx_of (map, key);
472  me = map->map[i];
473  if (map->use_small_entries)
474  {
475  struct SmallMapEntry *p;
476 
477  p = NULL;
478  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
479  {
480  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
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  return GNUNET_YES;
490  }
491  p = sme;
492  }
493  }
494  else
495  {
496  struct BigMapEntry *p;
497 
498  p = NULL;
499  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
500  {
501  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
502  {
503  if (NULL == p)
504  map->map[i].bme = bme->next;
505  else
506  p->next = bme->next;
507  update_next_cache_bme (map, bme);
508  GNUNET_free (bme);
509  map->size--;
510  return GNUNET_YES;
511  }
512  p = bme;
513  }
514  }
515  return GNUNET_NO;
516 }
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-qr.c:59
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
unsigned int size
Number of entries in the map.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.

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

Referenced by add_file(), bind_loose_channel(), callback_ego_rename(), cancel_store_operation(), cb_intersection_element_removed(), clean_channel(), clean_request(), client_disconnect_it(), client_release_ports(), close_handle_room(), close_service_room(), create_target(), delete_entries(), 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(), heap_plugin_del(), iterator_bf_reduce(), libgnunet_plugin_datacache_heap_done(), migrate_and_drop_keywords(), migrate_and_drop_metadata(), move_to_pending(), ns_lookup_result_cb(), process_result_with_request(), reconstruct_cb(), reghost_free_iterator(), remove_all(), remove_barrier(), remove_client_record(), remove_iterator(), remove_member_session(), remove_store_contact(), setup_state_record(), and update_store_contact().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove_all()

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

Remove all entries for the given key from the map.

Note that the values would not be "freed".

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

Definition at line 528 of file container_multihashmap.c.

531 {
532  union MapEntry me;
533  unsigned int i;
534  int ret;
535 
537 
538  ret = 0;
539  i = idx_of (map, key);
540  me = map->map[i];
541  if (map->use_small_entries)
542  {
543  struct SmallMapEntry *sme;
544  struct SmallMapEntry *p;
545 
546  p = NULL;
547  sme = me.sme;
548  while (NULL != sme)
549  {
550  if (0 == GNUNET_memcmp (key, sme->key))
551  {
552  if (NULL == p)
553  map->map[i].sme = sme->next;
554  else
555  p->next = sme->next;
556  update_next_cache_sme (map, sme);
557  GNUNET_free (sme);
558  map->size--;
559  if (NULL == p)
560  sme = map->map[i].sme;
561  else
562  sme = p->next;
563  ret++;
564  }
565  else
566  {
567  p = sme;
568  sme = sme->next;
569  }
570  }
571  }
572  else
573  {
574  struct BigMapEntry *bme;
575  struct BigMapEntry *p;
576 
577  p = NULL;
578  bme = me.bme;
579  while (NULL != bme)
580  {
581  if (0 == GNUNET_memcmp (key, &bme->key))
582  {
583  if (NULL == p)
584  map->map[i].bme = bme->next;
585  else
586  p->next = bme->next;
587  update_next_cache_bme (map, bme);
588  GNUNET_free (bme);
589  map->size--;
590  if (NULL == p)
591  bme = map->map[i].bme;
592  else
593  bme = p->next;
594  ret++;
595  }
596  else
597  {
598  p = bme;
599  bme = bme->next;
600  }
601  }
602  }
603  return ret;
604 }
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 635 of file container_multihashmap.c.

636 {
637  unsigned int ret;
638 
639  ret = map->size;
641  return ret;
642 }
static int remove_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Callback used to remove all entries from the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback 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.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_contains()

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

658 {
659  union MapEntry me;
660 
661  me = map->map[idx_of (map, key)];
662  if (map->use_small_entries)
663  {
664  struct SmallMapEntry *sme;
665 
666  for (sme = me.sme; NULL != sme; sme = sme->next)
667  if (0 == GNUNET_memcmp (key, sme->key))
668  return GNUNET_YES;
669  }
670  else
671  {
672  struct BigMapEntry *bme;
673 
674  for (bme = me.bme; NULL != bme; bme = bme->next)
675  if (0 == GNUNET_memcmp (key, &bme->key))
676  return GNUNET_YES;
677  }
678  return GNUNET_NO;
679 }

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

Referenced by allocate_v4_address(), allocate_v6_address(), build_authz_response(), check_member_session_history(), code_redirect(), collector(), contains_store_message(), cookie_identity_interpretation(), ego_get_all(), ego_get_response(), forward_about_members(), get_gns_cont(), get_url_parameter_copy(), GNUNET_TESTBED_barrier_init_(), handle_barrier_cancel(), handle_barrier_init(), handle_query_message(), handle_room_message(), handle_union_p2p_offer(), iterate_save_messages(), load_message_store_entries(), load_message_store_links(), namestore_get(), notify_about_members(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), publicize_rm(), regex_next_edge(), register_host(), run(), and userinfo_endpoint().

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

◆ GNUNET_CONTAINER_multihashmap_contains_value()

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

697 {
698  union MapEntry me;
699 
700  me = map->map[idx_of (map, key)];
701  if (map->use_small_entries)
702  {
703  struct SmallMapEntry *sme;
704 
705  for (sme = me.sme; NULL != sme; sme = sme->next)
706  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
707  return GNUNET_YES;
708  }
709  else
710  {
711  struct BigMapEntry *bme;
712 
713  for (bme = me.bme; NULL != bme; bme = bme->next)
714  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
715  return GNUNET_YES;
716  }
717  return GNUNET_NO;
718 }

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

Referenced by plan(), and schedule_block_download().

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

◆ GNUNET_CONTAINER_multihashmap_put()

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

797 {
798  union MapEntry me;
799  unsigned int i;
800 
801  i = idx_of (map, key);
804  {
805  me = map->map[i];
806  if (map->use_small_entries)
807  {
808  struct SmallMapEntry *sme;
809 
810  for (sme = me.sme; NULL != sme; sme = sme->next)
811  if (0 == GNUNET_memcmp (key, sme->key))
812  {
814  return GNUNET_SYSERR;
815  sme->value = value;
816  return GNUNET_NO;
817  }
818  }
819  else
820  {
821  struct BigMapEntry *bme;
822 
823  for (bme = me.bme; NULL != bme; bme = bme->next)
824  if (0 == GNUNET_memcmp (key, &bme->key))
825  {
827  return GNUNET_SYSERR;
828  bme->value = value;
829  return GNUNET_NO;
830  }
831  }
832  }
833  if (map->size / 3 >= map->map_length / 4)
834  {
835  grow (map);
836  i = idx_of (map, key);
837  }
838  if (map->use_small_entries)
839  {
840  struct SmallMapEntry *sme;
841 
842  sme = GNUNET_new (struct SmallMapEntry);
843  sme->key = key;
844  sme->value = value;
845  sme->next = map->map[i].sme;
846  map->map[i].sme = sme;
847  }
848  else
849  {
850  struct BigMapEntry *bme;
851 
852  bme = GNUNET_new (struct BigMapEntry);
853  bme->key = *key;
854  bme->value = value;
855  bme->next = map->map[i].bme;
856  map->map[i].bme = bme;
857  }
858  map->size++;
859  return GNUNET_OK;
860 }
static void grow(struct GNUNET_CONTAINER_MultiHashMap *map)
Grow the given map to a more appropriate size.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

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

Referenced by add_link(), add_member_session(), add_to_keyword_counter(), add_to_meta_counter(), callback_ego_rename(), callback_scan_for_operations(), change_handle_member_id(), check_unique(), collector(), create_handle_member_id(), create_randomized_element_iterator(), database_setup(), decode_and_send(), deserialize_search_result(), dht_get_string_handler(), diff_insert(), entry_service_room(), execute_add(), filtered_map_initialization(), find_target(), forward_about_members(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_ROUTING_add(), get_file_handle(), get_store_contact(), get_store_message(), GNUNET_CADET_open_port(), GNUNET_DHT_get_start(), GNUNET_FS_add_to_index(), GNUNET_FS_namespace_list_updateable(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), 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_dht_local_get(), 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(), 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(), publicize_rm(), put_diff(), put_rfn(), put_set(), put_store_message(), put_task(), queue(), read_index_list(), regex_find_path(), REGEX_INTERNAL_search(), regex_next_edge(), register_hashcode(), register_host(), rfn_vote(), route_packet(), run(), schedule_block_download(), set_result_cb(), setup_state_record(), store_all_states(), store_service(), token_endpoint(), transmit_pending(), update_member_chain_history(), update_message_control_flow(), update_sre_result_maps(), update_store_contact(), update_store_ego(), url_iterator(), and use_store_operation().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_size()

unsigned int GNUNET_CONTAINER_multihashmap_size ( const struct GNUNET_CONTAINER_MultiHashMap map)

◆ GNUNET_CONTAINER_multihashmap_iterate()

int GNUNET_CONTAINER_multihashmap_iterate ( struct GNUNET_CONTAINER_MultiHashMap map,
GNUNET_CONTAINER_MulitHashMapIteratorCallback  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 354 of file container_multihashmap.c.

358 {
359  int count;
360  union MapEntry me;
361  union MapEntry *ce;
362  struct GNUNET_HashCode kc;
363 
364  GNUNET_assert (NULL != map);
365  ce = &map->next_cache[map->next_cache_off];
367  count = 0;
368  for (unsigned i = 0; i < map->map_length; i++)
369  {
370  me = map->map[i];
371  if (map->use_small_entries)
372  {
373  struct SmallMapEntry *sme;
374 
375  ce->sme = me.sme;
376  while (NULL != (sme = ce->sme))
377  {
378  ce->sme = sme->next;
379  if (NULL != it)
380  {
381  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
382  {
384  return GNUNET_SYSERR;
385  }
386  }
387  count++;
388  }
389  }
390  else
391  {
392  struct BigMapEntry *bme;
393 
394  ce->bme = me.bme;
395  while (NULL != (bme = ce->bme))
396  {
397  ce->bme = bme->next;
398  if (NULL != it)
399  {
400  kc = bme->key;
401  if (GNUNET_OK != it (it_cls, &kc, bme->value))
402  {
404  return GNUNET_SYSERR;
405  }
406  }
407  count++;
408  }
409  }
410  }
412  return count;
413 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
A 512-bit hashcode.

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

Referenced by begin_bf_exchange(), callback_mq_error(), callback_reconnect(), callback_set_handle_name(), check_all_done(), 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(), 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_IDENTITY_disconnect(), 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_datastore_heap_done(), 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_handle_configuration(), save_member(), save_member_session_history(), save_message_store(), save_state(), schedule_transmit_search_request(), send_alices_cryptodata_message(), send_bloomfilter(), send_full_set(), set_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

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

1015 {
1017 
1019  iter->map = map;
1021  iter->me = map->map[0];
1022  return iter;
1023 }
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()

int 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

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

1045 {
1046  /* make sure the map has not been modified */
1048 
1049  /* look for the next entry, skipping empty buckets */
1050  while (1)
1051  {
1052  if (iter->idx >= iter->map->map_length)
1053  return GNUNET_NO;
1054  if (GNUNET_YES == iter->map->use_small_entries)
1055  {
1056  if (NULL != iter->me.sme)
1057  {
1058  if (NULL != key)
1059  *key = *iter->me.sme->key;
1060  if (NULL != value)
1061  *value = iter->me.sme->value;
1062  iter->me.sme = iter->me.sme->next;
1063  return GNUNET_YES;
1064  }
1065  }
1066  else
1067  {
1068  if (NULL != iter->me.bme)
1069  {
1070  if (NULL != key)
1071  *key = iter->me.bme->key;
1072  if (NULL != value)
1073  *value = iter->me.bme->value;
1074  iter->me.bme = iter->me.bme->next;
1075  return GNUNET_YES;
1076  }
1077  }
1078  iter->idx += 1;
1079  if (iter->idx < iter->map->map_length)
1080  iter->me = iter->map->map[iter->idx];
1081  }
1082 }
unsigned int idx
Current bucket index.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...

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

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

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_iterator_destroy()

void GNUNET_CONTAINER_multihashmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiHashMapIterator iter)

Destroy a multihashmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 1091 of file container_multihashmap.c.

1093 {
1094  GNUNET_free (iter);
1095 }

References GNUNET_free.

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

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_get_multiple()

int GNUNET_CONTAINER_multihashmap_get_multiple ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
GNUNET_CONTAINER_MulitHashMapIteratorCallback  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
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 874 of file container_multihashmap.c.

879 {
880  int count;
881  union MapEntry *me;
882  union MapEntry *ce;
883 
884  ce = &map->next_cache[map->next_cache_off];
886  count = 0;
887  me = &map->map[idx_of (map, key)];
888  if (map->use_small_entries)
889  {
890  struct SmallMapEntry *sme;
891 
892  ce->sme = me->sme;
893  while (NULL != (sme = ce->sme))
894  {
895  ce->sme = sme->next;
896  if (0 != GNUNET_memcmp (key, sme->key))
897  continue;
898  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
899  {
901  return GNUNET_SYSERR;
902  }
903  count++;
904  }
905  }
906  else
907  {
908  struct BigMapEntry *bme;
909 
910  ce->bme = me->bme;
911  while (NULL != (bme = ce->bme))
912  {
913  ce->bme = bme->next;
914  if (0 != GNUNET_memcmp (key, &bme->key))
915  continue;
916  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
917  {
919  return GNUNET_SYSERR;
920  }
921  count++;
922  }
923  }
925  return count;
926 }

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 find_trees(), GDS_CLIENTS_handle_reply(), GDS_ROUTING_add(), GDS_ROUTING_process(), GNUNET_FS_namespace_list_updateable(), GSF_plan_add_(), handle_client_result(), handle_dht_local_get_result_seen(), handle_dht_local_get_stop(), handle_p2p_get(), handle_p2p_put(), handle_port_open(), handle_put(), handle_reply(), heap_plugin_get(), heap_plugin_get_key(), heap_plugin_put(), heap_plugin_remove_key(), iter_hashcodes(), 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_MulitHashMapIteratorCallback  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 941 of file container_multihashmap.c.

945 {
946  unsigned int off;
947  unsigned int idx;
948  union MapEntry me;
949 
950  if (0 == map->size)
951  return 0;
952  if (NULL == it)
953  return 1;
955  for (idx = 0; idx < map->map_length; idx++)
956  {
957  me = map->map[idx];
958  if (map->use_small_entries)
959  {
960  struct SmallMapEntry *sme;
961  struct SmallMapEntry *nxt;
962 
963  nxt = me.sme;
964  while (NULL != (sme = nxt))
965  {
966  nxt = sme->next;
967  if (0 == off)
968  {
969  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
970  return GNUNET_SYSERR;
971  return 1;
972  }
973  off--;
974  }
975  }
976  else
977  {
978  struct BigMapEntry *bme;
979  struct BigMapEntry *nxt;
980 
981  nxt = me.bme;
982  while (NULL != (bme = nxt))
983  {
984  nxt = bme->next;
985  if (0 == off)
986  {
987  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
988  return GNUNET_SYSERR;
989  return 1;
990  }
991  off--;
992  }
993  }
994  }
995  GNUNET_break (0);
996  return GNUNET_SYSERR;
997 }
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.

Referenced by heap_plugin_get_random().

Here is the call graph for this function:
Here is the caller 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

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 193 of file container_multipeermap.c.

195 {
197 
198  GNUNET_assert (len > 0);
200  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
201  if (NULL == map->map)
202  {
203  GNUNET_free (map);
204  return NULL;
205  }
206  map->map_length = len;
207  map->use_small_entries = do_not_copy_keys;
208  return map;
209 }
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_room(), CustomPeerMap_create(), GAS_addresses_init(), GAS_connectivity_init(), GAS_preference_init(), GAS_reservations_init(), GDS_HELLO_init(), GDS_NEIGHBOURS_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 219 of file container_multipeermap.c.

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

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_room(), destroy_sub(), do_shutdown(), end(), GAS_addresses_done(), GAS_connectivity_done(), GAS_preference_client_disconnect(), GAS_preference_done(), GAS_reservations_done(), GDS_HELLO_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 304 of file container_multipeermap.c.

307 {
308  union MapEntry me;
309 
310  me = map->map[idx_of (map, key)];
311  if (map->use_small_entries)
312  {
313  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
314  if (0 == GNUNET_memcmp (key, sme->key))
315  return sme->value;
316  }
317  else
318  {
319  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
320  if (0 == GNUNET_memcmp (key, &bme->key))
321  return bme->value;
322  }
323  return NULL;
324 }
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_room_at(), find_session(), free_preference(), GAS_preference_get_by_peer(), GAS_reservations_set_bandwidth(), GCP_get(), GDS_HELLO_get(), GDS_NEIGHBOURS_handle_reply(), get_cadet(), get_peer_ctx(), get_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_hello(), process_peer(), process_peer_monitoring_cb(), profiler_reply_handle(), profiler_reply_handle_info(), rebuild_room_basement_structure(), reservations_reserve(), try_connect(), 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()

int 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 445 of file container_multipeermap.c.

448 {
449  union MapEntry me;
450  unsigned int i;
451 
453  i = idx_of (map, key);
454  me = map->map[i];
455  if (map->use_small_entries)
456  {
457  struct SmallMapEntry *p = NULL;
458 
459  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
460  {
461  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
462  {
463  if (NULL == p)
464  map->map[i].sme = sme->next;
465  else
466  p->next = sme->next;
467  update_next_cache_sme (map, sme);
468  GNUNET_free (sme);
469  map->size--;
470  return GNUNET_YES;
471  }
472  p = sme;
473  }
474  }
475  else
476  {
477  struct BigMapEntry *p = NULL;
478 
479  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
480  {
481  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
482  {
483  if (NULL == p)
484  map->map[i].bme = bme->next;
485  else
486  p->next = bme->next;
487  update_next_cache_bme (map, bme);
488  GNUNET_free (bme);
489  map->size--;
490  return GNUNET_YES;
491  }
492  p = bme;
493  }
494  }
495  return GNUNET_NO;
496 }
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

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

Referenced by ats_perf_mon_cb(), callback_room_connect(), callback_room_disconnect(), cleanup_validation_entry(), client_delete_session(), destroy_ack_cummulator(), destroy_active_client_request(), destroy_ai(), destroy_it(), destroy_peer(), disconnect_and_free_peer_entry(), disconnect_cb(), enforce_del_address(), enter_room_at(), free_addr_it(), free_address(), free_all_it(), free_backtalker(), free_connect_info(), 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(), GNUNET_PEER_change_rc(), GNUNET_PEER_decrement_rcs(), GNUNET_TRANSPORT_application_suggest_cancel(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_reject_request(), GSC_SESSIONS_end(), GSF_peer_disconnect_handler(), GSF_plan_notify_peer_disconnect_(), handle_client_send(), handle_core_disconnect(), handle_send_transmit_continuation(), handle_tcp_nat_probe(), iterator(), neighbour_delete(), queue_destroy(), receiver_destroy(), sender_destroy(), server_delete_session(), stop_peer_request(), tcp_plugin_disconnect_session(), udp_disconnect_session(), and unix_plugin_session_disconnect().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove_all()

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

Remove all entries for the given key from the map.

Note that the values would not be "freed".

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

Definition at line 508 of file container_multipeermap.c.

511 {
512  union MapEntry me;
513  unsigned int i;
514  int ret;
515 
517 
518  ret = 0;
519  i = idx_of (map, key);
520  me = map->map[i];
521  if (map->use_small_entries)
522  {
523  struct SmallMapEntry *sme;
524  struct SmallMapEntry *p;
525 
526  p = NULL;
527  sme = me.sme;
528  while (NULL != sme)
529  {
530  if (0 == GNUNET_memcmp (key, sme->key))
531  {
532  if (NULL == p)
533  map->map[i].sme = sme->next;
534  else
535  p->next = sme->next;
536  update_next_cache_sme (map, sme);
537  GNUNET_free (sme);
538  map->size--;
539  if (NULL == p)
540  sme = map->map[i].sme;
541  else
542  sme = p->next;
543  ret++;
544  }
545  else
546  {
547  p = sme;
548  sme = sme->next;
549  }
550  }
551  }
552  else
553  {
554  struct BigMapEntry *bme;
555  struct BigMapEntry *p;
556 
557  p = NULL;
558  bme = me.bme;
559  while (NULL != bme)
560  {
561  if (0 == GNUNET_memcmp (key, &bme->key))
562  {
563  if (NULL == p)
564  map->map[i].bme = bme->next;
565  else
566  p->next = bme->next;
567  update_next_cache_bme (map, bme);
568  GNUNET_free (bme);
569  map->size--;
570  if (NULL == p)
571  bme = map->map[i].bme;
572  else
573  bme = p->next;
574  ret++;
575  }
576  else
577  {
578  p = bme;
579  bme = bme->next;
580  }
581  }
582  }
583  return ret;
584 }

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

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

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

◆ GNUNET_CONTAINER_multipeermap_contains()

int 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 597 of file container_multipeermap.c.

600 {
601  union MapEntry me;
602 
603  me = map->map[idx_of (map, key)];
604  if (map->use_small_entries)
605  {
606  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
607  if (0 == GNUNET_memcmp (key, sme->key))
608  return GNUNET_YES;
609  }
610  else
611  {
612  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
613  if (0 == GNUNET_memcmp (key, &bme->key))
614  return GNUNET_YES;
615  }
616  return GNUNET_NO;
617 }

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

Referenced by addr_info_cb(), callback_room_disconnect(), check_access(), check_peer_known(), check_peer_valid(), check_removable(), clean_peer(), compute_rand_delay(), CustomPeerMap_contains_peer(), CustomPeerMap_put(), destroy_peer(), GAS_connectivity_has_peer(), get_peer_ctx(), GSC_CLIENTS_deliver_message(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_solicit_request(), handle_client_send_request(), handle_dv_learn(), handle_feedback(), handle_peer_pull_request(), handle_peer_push(), mq_notify_sent_cb(), send_pull_request(), send_push(), tcp_plugin_get_session(), try_connect(), 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()

int 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 631 of file container_multipeermap.c.

635 {
636  union MapEntry me;
637 
638  me = map->map[idx_of (map, key)];
639  if (map->use_small_entries)
640  {
641  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
642  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
643  return GNUNET_YES;
644  }
645  else
646  {
647  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
648  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
649  return GNUNET_YES;
650  }
651  return GNUNET_NO;
652 }

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

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

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

◆ GNUNET_CONTAINER_multipeermap_put()

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

Store a key-value pair in the map.

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

Definition at line 727 of file container_multipeermap.c.

731 {
732  union MapEntry me;
733  unsigned int i;
734 
735  i = idx_of (map, key);
738  {
739  me = map->map[i];
740  if (map->use_small_entries)
741  {
742  struct SmallMapEntry *sme;
743 
744  for (sme = me.sme; NULL != sme; sme = sme->next)
745  if (0 == GNUNET_memcmp (key, sme->key))
746  {
748  return GNUNET_SYSERR;
749  sme->value = value;
750  return GNUNET_NO;
751  }
752  }
753  else
754  {
755  struct BigMapEntry *bme;
756 
757  for (bme = me.bme; NULL != bme; bme = bme->next)
758  if (0 == GNUNET_memcmp (key, &bme->key))
759  {
761  return GNUNET_SYSERR;
762  bme->value = value;
763  return GNUNET_NO;
764  }
765  }
766  }
767  if (map->size / 3 >= map->map_length / 4)
768  {
769  grow (map);
770  i = idx_of (map, key);
771  }
772  if (map->use_small_entries)
773  {
774  struct SmallMapEntry *sme;
775 
776  sme = GNUNET_new (struct SmallMapEntry);
777  sme->key = key;
778  sme->value = value;
779  sme->next = map->map[i].sme;
780  map->map[i].sme = sme;
781  }
782  else
783  {
784  struct BigMapEntry *bme;
785 
786  bme = GNUNET_new (struct BigMapEntry);
787  bme->key = *key;
788  bme->value = value;
789  bme->next = map->map[i].bme;
790  map->map[i].bme = bme;
791  }
792  map->size++;
793  return GNUNET_OK;
794 }
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_room_at(), find_validation_entry(), GAS_addresses_add(), GAS_handle_request_address(), GAS_reservations_set_bandwidth(), GCP_get(), 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_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_hello(), process_peer_monitoring_cb(), run(), server_lookup_connection(), setup_ac(), setup_neighbour(), setup_queue(), setup_sender(), start_address_validation(), tcp_plugin_get_session(), try_connect(), 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 337 of file container_multipeermap.c.

341 {
342  int count;
343  union MapEntry me;
344  union MapEntry *ce;
345  struct GNUNET_PeerIdentity kc;
346 
347  count = 0;
348  GNUNET_assert (NULL != map);
349  ce = &map->next_cache[map->next_cache_off];
351  for (unsigned int i = 0; i < map->map_length; i++)
352  {
353  me = map->map[i];
354  if (map->use_small_entries)
355  {
356  struct SmallMapEntry *sme;
357 
358  ce->sme = me.sme;
359  while (NULL != (sme = ce->sme))
360  {
361  ce->sme = sme->next;
362  if (NULL != it)
363  {
364  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
365  {
367  return GNUNET_SYSERR;
368  }
369  }
370  count++;
371  }
372  }
373  else
374  {
375  struct BigMapEntry *bme;
376 
377  ce->bme = me.bme;
378  while (NULL != (bme = ce->bme))
379  {
380  ce->bme = bme->next;
381  if (NULL != it)
382  {
383  kc = bme->key;
384  if (GNUNET_OK != it (it_cls, &kc, bme->value))
385  {
387  return GNUNET_SYSERR;
388  }
389  }
390  count++;
391  }
392  }
393  }
395  return count;
396 }
#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(), cleaning_task(), cleanup_map(), client_disconnect_cb(), client_lookup_session(), consider_for_advertising(), cron_flush_respect(), destroy_room(), disconnect(), disconnect_and_schedule_reconnect(), do_shutdown(), end(), forward_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(), GDS_HELLO_done(), GDS_NEIGHBOURS_done(), 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(), publicize_rm(), recalculate_relative_preferences(), reconnect(), reconnect_later(), schedule_next_hello(), send_find_peer_message(), send_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_connect_preferences(), update_flood_message(), 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

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multipeermap 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 multipeermap 'map'

Definition at line 946 of file container_multipeermap.c.

948 {
950 
952  iter->map = map;
954  iter->me = map->map[0];
955  return iter;
956 }
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()

int 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

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 multipeermap 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 974 of file container_multipeermap.c.

978 {
979  /* make sure the map has not been modified */
981 
982  /* look for the next entry, skipping empty buckets */
983  while (1)
984  {
985  if (iter->idx >= iter->map->map_length)
986  return GNUNET_NO;
987  if (GNUNET_YES == iter->map->use_small_entries)
988  {
989  if (NULL != iter->me.sme)
990  {
991  if (NULL != key)
992  *key = *iter->me.sme->key;
993  if (NULL != value)
994  *value = iter->me.sme->value;
995  iter->me.sme = iter->me.sme->next;
996  return GNUNET_YES;
997  }
998  }
999  else
1000  {
1001  if (NULL != iter->me.bme)
1002  {
1003  if (NULL != key)
1004  *key = iter->me.bme->key;
1005  if (NULL != value)
1006  *value = iter->me.bme->value;
1007  iter->me.bme = iter->me.bme->next;
1008  return GNUNET_YES;
1009  }
1010  }
1011  iter->idx += 1;
1012  if (iter->idx < iter->map->map_length)
1013  iter->me = iter->map->map[iter->idx];
1014  }
1015 }
unsigned int idx
Current bucket index.

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

◆ GNUNET_CONTAINER_multipeermap_iterator_destroy()

void GNUNET_CONTAINER_multipeermap_iterator_destroy ( struct GNUNET_CONTAINER_MultiPeerMapIterator iter)

Destroy a multipeermap iterator.

Parameters
iterthe iterator to destroy

Definition at line 1024 of file container_multipeermap.c.

1026 {
1027  GNUNET_free (iter);
1028 }

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
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 808 of file container_multipeermap.c.

813 {
814  int count;
815  union MapEntry me;
816  union MapEntry *ce;
817 
818  ce = &map->next_cache[map->next_cache_off];
820  count = 0;
821  me = map->map[idx_of (map, key)];
822  if (map->use_small_entries)
823  {
824  struct SmallMapEntry *sme;
825 
826  ce->sme = me.sme;
827  while (NULL != (sme = ce->sme))
828  {
829  ce->sme = sme->next;
830  if (0 != GNUNET_memcmp (key, sme->key))
831  continue;
832  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
833  {
835  return GNUNET_SYSERR;
836  }
837  count++;
838  }
839  }
840  else
841  {
842  struct BigMapEntry *bme;
843 
844  ce->bme = me.bme;
845  while (NULL != (bme = ce->bme))
846  {
847  ce->bme = bme->next;
848  if (0 != GNUNET_memcmp (key, &bme->key))
849  continue;
850  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
851  {
853  return GNUNET_SYSERR;
854  }
855  count++;
856  }
857  }
859  return count;
860 }

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 875 of file container_multipeermap.c.

879 {
880  unsigned int off;
881  union MapEntry me;
882 
883  if (0 == map->size)
884  return 0;
885  if (NULL == it)
886  return 1;
888  for (unsigned int idx = 0; idx < map->map_length; idx++)
889  {
890  me = map->map[idx];
891  if (map->use_small_entries)
892  {
893  struct SmallMapEntry *sme;
894  struct SmallMapEntry *nxt;
895 
896  nxt = me.sme;
897  while (NULL != (sme = nxt))
898  {
899  nxt = sme->next;
900  if (0 == off)
901  {
902  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
903  return GNUNET_SYSERR;
904  return 1;
905  }
906  off--;
907  }
908  }
909  else
910  {
911  struct BigMapEntry *bme;
912  struct BigMapEntry *nxt;
913 
914  nxt = me.bme;
915  while (NULL != (bme = nxt))
916  {
917  nxt = bme->next;
918  if (0 == off)
919  {
920  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
921  return GNUNET_SYSERR;
922  return 1;
923  }
924  off--;
925  }
926  }
927  }
928  GNUNET_break (0);
929  return GNUNET_SYSERR;
930 }

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

195 {
197 
198  GNUNET_assert (len > 0);
200  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
201  if (NULL == map->map)
202  {
203  GNUNET_free (map);
204  return NULL;
205  }
206  map->map_length = len;
207  map->use_small_entries = do_not_copy_keys;
208  return map;
209 }
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 apply_patch(), create_room(), GCO_init(), GCP_get(), GNUNET_TESTING_get_topo_from_file(), init_member_store(), and run().

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

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

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(), GCO_shutdown(), GNUNET_PQ_disconnect(), and shutdown_rest().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_get()

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

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

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

Definition at line 304 of file container_multishortmap.c.

307 {
308  union MapEntry me;
309 
310  me = map->map[idx_of (map, key)];
311  if (map->use_small_entries)
312  {
313  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
314  if (0 == GNUNET_memcmp (key, sme->key))
315  return sme->value;
316  }
317  else
318  {
319  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
320  if (0 == GNUNET_memcmp (key, &bme->key))
321  return bme->value;
322  }
323  return NULL;
324 }
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_connections(), get_route(), get_store_member(), GNUNET_TESTING_get_topo_from_file(), send_simple_run(), sock_read(), and start_helper().

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

◆ GNUNET_CONTAINER_multishortmap_remove()

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

Remove the given key-value pair from the map.

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

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

Definition at line 442 of file container_multishortmap.c.

446 {
447  union MapEntry me;
448  unsigned int i;
449 
451  i = idx_of (map, key);
452  me = map->map[i];
453  if (map->use_small_entries)
454  {
455  struct SmallMapEntry *p = NULL;
456 
457  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
458  {
459  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
460  {
461  if (NULL == p)
462  map->map[i].sme = sme->next;
463  else
464  p->next = sme->next;
465  update_next_cache_sme (map, sme);
466  GNUNET_free (sme);
467  map->size--;
468  return GNUNET_YES;
469  }
470  p = sme;
471  }
472  }
473  else
474  {
475  struct BigMapEntry *p = NULL;
476 
477  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
478  {
479  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
480  {
481  if (NULL == p)
482  map->map[i].bme = bme->next;
483  else
484  p->next = bme->next;
485  update_next_cache_bme (map, bme);
486  GNUNET_free (bme);
487  map->size--;
488  return GNUNET_YES;
489  }
490  p = bme;
491  }
492  }
493  return GNUNET_NO;
494 }
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(), 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 506 of file container_multishortmap.c.

509 {
510  union MapEntry me;
511  unsigned int i;
512  int ret;
513 
515 
516  ret = 0;
517  i = idx_of (map, key);
518  me = map->map[i];
519  if (map->use_small_entries)
520  {
521  struct SmallMapEntry *sme;
522  struct SmallMapEntry *p;
523 
524  p = NULL;
525  sme = me.sme;
526  while (NULL != sme)
527  {
528  if (0 == GNUNET_memcmp (key, sme->key))
529  {
530  if (NULL == p)
531  map->map[i].sme = sme->next;
532  else
533  p->next = sme->next;
534  update_next_cache_sme (map, sme);
535  GNUNET_free (sme);
536  map->size--;
537  if (NULL == p)
538  sme = map->map[i].sme;
539  else
540  sme = p->next;
541  ret++;
542  }
543  else
544  {
545  p = sme;
546  sme = sme->next;
547  }
548  }
549  }
550  else
551  {
552  struct BigMapEntry *bme;
553  struct BigMapEntry *p;
554 
555  p = NULL;
556  bme = me.bme;
557  while (NULL != bme)
558  {
559  if (0 == GNUNET_memcmp (key, &bme->key))
560  {
561  if (NULL == p)
562  map->map[i].bme = bme->next;
563  else
564  p->next = bme->next;
565  update_next_cache_bme (map, bme);
566  GNUNET_free (bme);
567  map->size--;
568  if (NULL == p)
569  bme = map->map[i].bme;
570  else
571  bme = p->next;
572  ret++;
573  }
574  else
575  {
576  p = bme;
577  bme = bme->next;
578  }
579  }
580  }
581  return ret;
582 }

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

598 {
599  union MapEntry me;
600 
601  me = map->map[idx_of (map, key)];
602  if (map->use_small_entries)
603  {
604  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
605  if (0 == GNUNET_memcmp (key, sme->key))
606  return GNUNET_YES;
607  }
608  else
609  {
610  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
611  if (0 == GNUNET_memcmp (key, &bme->key))
612  return GNUNET_YES;
613  }
614  return GNUNET_NO;
615 }

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_file(), 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 629 of file container_multishortmap.c.

633 {
634  union MapEntry me;
635 
636  me = map->map[idx_of (map, key)];
637  if (map->use_small_entries)
638  {
639  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
640  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
641  return GNUNET_YES;
642  }
643  else
644  {
645  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
646  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
647  return GNUNET_YES;
648  }
649  return GNUNET_NO;
650 }

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

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

729 {
730  union MapEntry me;
731  unsigned int i;
732 
733  i = idx_of (map, key);
736  {
737  me = map->map[i];
738  if (map->use_small_entries)
739  {
740  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
741  if (0 == GNUNET_memcmp (key, sme->key))
742  {
744  return GNUNET_SYSERR;
745  sme->value = value;
746  return GNUNET_NO;
747  }
748  }
749  else
750  {
751  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
752  if (0 == GNUNET_memcmp (key, &bme->key))
753  {
755  return GNUNET_SYSERR;
756  bme->value = value;
757  return GNUNET_NO;
758  }
759  }
760  }
761  if (map->size / 3 >= map->map_length / 4)
762  {
763  grow (map);
764  i = idx_of (map, key);
765  }
766  if (map->use_small_entries)
767  {
768  struct SmallMapEntry *sme;
769 
770  sme = GNUNET_new (struct SmallMapEntry);
771  sme->key = key;
772  sme->value = value;
773  sme->next = map->map[i].sme;
774  map->map[i].sme = sme;
775  }
776  else
777  {
778  struct BigMapEntry *bme;
779 
780  bme = GNUNET_new (struct BigMapEntry);
781  bme->key = *key;
782  bme->value = value;
783  bme->next = map->map[i].bme;
784  map->map[i].bme = bme;
785  }
786  map->size++;
787  return GNUNET_OK;
788 }
static void grow(struct GNUNET_CONTAINER_MultiShortmap *map)
Grow the given map to a more appropriate size.

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

Referenced by add_store_member(), connection_create(), GCP_add_connection(), GNUNET_PQ_event_listen(), GNUNET_TESTING_get_topo_from_file(), handle_connection_create(), handle_id_message(), handle_join_message(), kce_generate(), notify_connect(), and start_dv_learn().

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

288 {
289  return map->size;
290 }

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

341 {
342  int count;
343  union MapEntry me;
344  union MapEntry *ce;
345  struct GNUNET_ShortHashCode kc;
346 
347  count = 0;
348  GNUNET_assert (NULL != map);
349  ce = &map->next_cache[map->next_cache_off];
351  for (unsigned int i = 0; i < map->map_length; i++)
352  {
353  me = map->map[i];
354  if (map->use_small_entries)
355  {
356  struct SmallMapEntry *sme;
357 
358  ce->sme = me.sme;
359  while (NULL != (sme = ce->sme))
360  {
361  ce->sme = sme->next;
362  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
363  {
365  return GNUNET_SYSERR;
366  }
367  count++;
368  }
369  }
370  else
371  {
372  struct BigMapEntry *bme;
373 
374  ce->bme = me.bme;
375  while (NULL != (bme = ce->bme))
376  {
377  ce->bme = bme->next;
378  if (NULL != it)
379  {
380  kc = bme->key;
381  if (GNUNET_OK != it (it_cls, &kc, bme->value))
382  {
384  return GNUNET_SYSERR;
385  }
386  }
387  count++;
388  }
389  }
390  }
392  return count;
393 }
#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(), GNUNET_PQ_event_reconnect_(), iterate_room_members(), iterate_store_members(), load_member_store(), log_namespaces(), log_topo(), and save_member_store().

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

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multishortmap 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 multishortmap 'map'

Definition at line 930 of file container_multishortmap.c.

932 {
934 
936  iter->map = map;
938  iter->me = map->map[0];
939  return iter;
940 }
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.

◆ GNUNET_CONTAINER_multishortmap_iterator_next()

int 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

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

962 {
963  /* make sure the map has not been modified */
965 
966  /* look for the next entry, skipping empty buckets */
967  while (1)
968  {
969  if (iter->idx >= iter->map->map_length)
970  return GNUNET_NO;
971  if (GNUNET_YES == iter->map->use_small_entries)
972  {
973  if (NULL != iter->me.sme)
974  {
975  if (NULL != key)
976  *key = *iter->me.sme->key;
977  if (NULL != value)
978  *value = iter->me.sme->value;
979  iter->me.sme = iter->me.sme->next;
980  return GNUNET_YES;
981  }
982  }
983  else
984  {
985  if (NULL != iter->me.bme)
986  {
987  if (NULL != key)
988  *key = iter->me.bme->key;
989  if (NULL != value)
990  *value = iter->me.bme->value;
991  iter->me.bme = iter->me.bme->next;
992  return GNUNET_YES;
993  }
994  }
995  iter->idx += 1;
996  if (iter->idx < iter->map->map_length)
997  iter->me = iter->map->map[iter->idx];
998  }
999 }
unsigned int idx
Current bucket index.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry * map
All of our buckets.

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

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

1010 {
1011  GNUNET_free (iter);
1012 }

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

807 {
808  int count;
809  union MapEntry me;
810  union MapEntry *ce;
811 
812  ce = &map->next_cache[map->next_cache_off];
814  count = 0;
815  me = map->map[idx_of (map, key)];
816  if (map->use_small_entries)
817  {
818  struct SmallMapEntry *sme;
819 
820  ce->sme = me.sme;
821  while (NULL != (sme = ce->sme))
822  {
823  ce->sme = sme->next;
824  if (0 != GNUNET_memcmp (key, sme->key))
825  continue;
826  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
827  {
829  return GNUNET_SYSERR;
830  }
831  count++;
832  }
833  }
834  else
835  {
836  struct BigMapEntry *bme;
837 
838  ce->bme = me.bme;
839  while (NULL != (bme = ce->bme))
840  {
841  ce->bme = bme->next;
842  if (0 != GNUNET_memcmp (key, &bme->key))
843  continue;
844  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
845  {
847  return GNUNET_SYSERR;
848  }
849  count++;
850  }
851  }
853  return count;
854 }

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

Referenced by event_do_poll().

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

◆ GNUNET_CONTAINER_multishortmap_get_random()

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

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

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

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

Definition at line 869 of file container_multishortmap.c.

873 {
874  unsigned int off;
875  union MapEntry me;
876 
877  if (0 == map->size)
878  return 0;
879  if (NULL == it)
880  return 1;
882  for (unsigned int idx = 0; idx < map->map_length; idx++)
883  {
884  me = map->map[idx];
885  if (map->use_small_entries)
886  {
887  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
888  {
889  if (0 == off)
890  {
891  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
892  return GNUNET_SYSERR;
893  return 1;
894  }
895  off--;
896  }
897  }
898  else
899  {
900  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
901  {
902  if (0 == off)
903  {
904  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
905  return GNUNET_SYSERR;
906  return 1;
907  }
908  off--;
909  }
910  }
911  }
912  GNUNET_break (0);
913  return GNUNET_SYSERR;
914 }

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

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

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

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

307 {
308  union MapEntry me;
309 
310  me = map->map[idx_of (map, key)];
311  if (map->use_small_entries)
312  {
313  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
314  if (0 == GNUNET_memcmp (key, sme->key))
315  return sme->value;
316  }
317  else
318  {
319  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
320  if (0 == GNUNET_memcmp (key, &bme->key))
321  return bme->value;
322  }
323  return NULL;
324 }
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()

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

445 {
446  union MapEntry me;
447  unsigned int i;
448 
450  i = idx_of (map, key);
451  me = map->map[i];
452  if (map->use_small_entries)
453  {
454  struct SmallMapEntry *p = NULL;
455 
456  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
457  {
458  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
459  {
460  if (NULL == p)
461  map->map[i].sme = sme->next;
462  else
463  p->next = sme->next;
464  update_next_cache_sme (map, sme);
465  GNUNET_free (sme);
466  map->size--;
467  return GNUNET_YES;
468  }
469  p = sme;
470  }
471  }
472  else
473  {
474  struct BigMapEntry *p = NULL;
475 
476  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
477  {
478  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
479  {
480  if (NULL == p)
481  map->map[i].bme = bme->next;
482  else
483  p->next = bme->next;
484  update_next_cache_bme (map, bme);
485  GNUNET_free (bme);
486  map->size--;
487  return GNUNET_YES;
488  }
489  p = bme;
490  }
491  }
492  return GNUNET_NO;
493 }
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

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

Referenced by free_pending_acknowledgement().

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

◆ GNUNET_CONTAINER_multiuuidmap_remove_all()

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

Remove all entries for the given key from the map.

Note that the values would not be "freed".

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

Definition at line 505 of file container_multiuuidmap.c.

508 {
509  union MapEntry me;
510  unsigned int i;
511  int ret;
512 
514 
515  ret = 0;
516  i = idx_of (map, key);
517  me = map->map[i];
518  if (map->use_small_entries)
519  {
520  struct SmallMapEntry *sme;
521  struct SmallMapEntry *p;
522 
523  p = NULL;
524  sme = me.sme;
525  while (NULL != sme)
526  {
527  if (0 == GNUNET_memcmp (key, sme->key))
528  {
529  if (NULL == p)
530  map->map[i].sme = sme->next;
531  else
532  p->next = sme->next;
533  update_next_cache_sme (map, sme);
534  GNUNET_free (sme);
535  map->size--;
536  if (NULL == p)
537  sme = map->map[i].sme;
538  else
539  sme = p->next;
540  ret++;
541  }
542  else
543  {
544  p = sme;
545  sme = sme->next;
546  }
547  }
548  }
549  else
550  {
551  struct BigMapEntry *bme;
552  struct BigMapEntry *p;
553 
554  p = NULL;
555  bme = me.bme;
556  while (NULL != bme)
557  {
558  if (0 == GNUNET_memcmp (key, &bme->key))
559  {
560  if (NULL == p)
561  map->map[i].bme = bme->next;
562  else
563  p->next = bme->next;
564  update_next_cache_bme (map, bme);
565  GNUNET_free (bme);
566  map->size--;
567  if (NULL == p)
568  bme = map->map[i].bme;
569  else
570  bme = p->next;
571  ret++;
572  }
573  else
574  {
575  p = bme;
576  bme = bme->next;
577  }
578  }
579  }
580  return ret;
581 }

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

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

597 {
598  union MapEntry me;
599 
600  me = map->map[idx_of (map, key)];
601  if (map->use_small_entries)
602  {
603  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
604  if (0 == GNUNET_memcmp (key, sme->key))
605  return GNUNET_YES;
606  }
607  else
608  {
609  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
610  if (0 == GNUNET_memcmp (key, &bme->key))
611  return GNUNET_YES;
612  }
613  return GNUNET_NO;
614 }

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

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_contains_value()

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

632 {
633  union MapEntry me;
634 
635  me = map->map[idx_of (map, key)];
636  if (map->use_small_entries)
637  {
638  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
639  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
640  return GNUNET_YES;
641  }
642  else
643  {
644  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
645  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
646  return GNUNET_YES;
647  }
648  return GNUNET_NO;
649 }

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

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_put()

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

727 {
728  union MapEntry me;
729  unsigned int i;
730 
731  i = idx_of (map, key);
734  {
735  me = map->map[i];
736  if (map->use_small_entries)
737  {
738  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
739  if (0 == GNUNET_memcmp (key, sme->key))
740  {
742  return GNUNET_SYSERR;
743  sme->value = value;
744  return GNUNET_NO;
745  }
746  }
747  else
748  {
749  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
750  if (0 == GNUNET_memcmp (key, &bme->key))
751  {
753  return GNUNET_SYSERR;
754  bme->value = value;
755  return GNUNET_NO;
756  }
757  }
758  }
759  if (map->size / 3 >= map->map_length / 4)
760  {
761  grow (map);
762  i = idx_of (map, key);
763  }
764  if (map->use_small_entries)
765  {
766  struct SmallMapEntry *sme;
767 
768  sme = GNUNET_new (struct SmallMapEntry);
769  sme->key = key;
770  sme->value = value;
771  sme->next = map->map[i].sme;
772  map->map[i].sme = sme;
773  }
774  else
775  {
776  struct BigMapEntry *bme;
777 
778  bme = GNUNET_new (struct BigMapEntry);
779  bme->key = *key;
780  bme->value = value;
781  bme->next = map->map[i].bme;
782  map->map[i].bme = bme;
783  }
784  map->size++;
785  return GNUNET_OK;
786 }
static void grow(struct GNUNET_CONTAINER_MultiUuidmap *map)
Grow the given map to a more appropriate size.

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

Referenced by prepare_pending_acknowledgement().

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

◆ GNUNET_CONTAINER_multiuuidmap_size()

unsigned int GNUNET_CONTAINER_multiuuidmap_size ( const struct GNUNET_CONTAINER_MultiUuidmap map)

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

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 286 of file container_multiuuidmap.c.

288 {
289  return map->size;
290 }

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

◆ GNUNET_CONTAINER_multiuuidmap_iterate()

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

Iterate over all entries in the map.

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

Definition at line 337 of file container_multiuuidmap.c.

341 {
342  int count;
343  union MapEntry me;
344  union MapEntry *ce;
345  struct GNUNET_Uuid kc;
346 
347  count = 0;
348  GNUNET_assert (NULL != map);
349  ce = &map->next_cache[map->next_cache_off];
351  for (unsigned int i = 0; i < map->map_length; i++)
352  {
353  me = map->map[i];
354  if (map->use_small_entries)
355  {
356  struct SmallMapEntry *sme;
357 
358  ce->sme = me.sme;
359  while (NULL != (sme = ce->sme))
360  {
361  ce->sme = sme->next;
362  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
363  {
365  return GNUNET_SYSERR;
366  }
367  count++;
368  }
369  }
370  else
371  {
372  struct BigMapEntry *bme;
373 
374  ce->bme = me.bme;
375  while (NULL != (bme = ce->bme))
376  {
377  ce->bme = bme->next;
378  if (NULL != it)
379  {
380  kc = bme->key;
381  if (GNUNET_OK != it (it_cls, &kc, bme->value))
382  {
384  return GNUNET_SYSERR;
385  }
386  }
387  count++;
388  }
389  }
390  }
392  return count;
393 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
A UUID, a 128 bit "random" value.

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

Referenced by do_shutdown().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_iterator_create()

struct GNUNET_CONTAINER_MultiUuidmapIterator* GNUNET_CONTAINER_multiuuidmap_iterator_create ( const struct GNUNET_CONTAINER_MultiUuidmap map)

Create an iterator for a multihashmap.

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

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

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multiuuidmap 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 multiuuidmap 'map'

Definition at line 928 of file container_multiuuidmap.c.

930 {
932 
934  iter->map = map;
936  iter->me = map->map[0];
937  return iter;
938 }
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()

int 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

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

960 {
961  /* make sure the map has not been modified */
963 
964  /* look for the next entry, skipping empty buckets */
965  while (1)
966  {
967  if (iter->idx >= iter->map->map_length)
968  return GNUNET_NO;
969  if (GNUNET_YES == iter->map->use_small_entries)
970  {
971  if (NULL != iter->me.sme)
972  {
973  if (NULL != key)
974  *key = *iter->me.sme->key;
975  if (NULL != value)
976  *value = iter->me.sme->value;
977  iter->me.sme = iter->me.sme->next;
978  return GNUNET_YES;
979  }
980  }
981  else
982  {
983  if (NULL != iter->me.bme)
984  {
985  if (NULL != key)
986  *key = iter->me.bme->key;
987  if (NULL != value)
988  *value = iter->me.bme->value;
989  iter->me.bme = iter->me.bme->next;
990  return GNUNET_YES;
991  }
992  }
993  iter->idx += 1;
994  if (iter->idx < iter->map->map_length)
995  iter->me = iter->map->map[iter->idx];
996  }
997 }
unsigned int idx
Current bucket index.
union MapEntry * map
All of our buckets.
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...

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

◆ GNUNET_CONTAINER_multiuuidmap_iterator_destroy()

void GNUNET_CONTAINER_multiuuidmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiUuidmapIterator iter)

Destroy a multiuuidmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 1006 of file container_multiuuidmap.c.

1008 {
1009  GNUNET_free (iter);
1010 }

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

805 {
806  int count;
807  union MapEntry me;
808  union MapEntry *ce;
809 
810  ce = &map->next_cache[map->next_cache_off];
812  count = 0;
813  me = map->map[idx_of (map, key)];
814  if (map->use_small_entries)
815  {
816  struct SmallMapEntry *sme;
817 
818  ce->sme = me.sme;
819  while (NULL != (sme = ce->sme))
820  {
821  ce->sme = sme->next;
822  if (0 != GNUNET_memcmp (key, sme->key))
823  continue;
824  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
825  {
827  return GNUNET_SYSERR;
828  }
829  count++;
830  }
831  }
832  else
833  {
834  struct BigMapEntry *bme;
835 
836  ce->bme = me.bme;
837  while (NULL != (bme = ce->bme))
838  {
839  ce->bme = bme->next;
840  if (0 != GNUNET_memcmp (key, &bme->key))
841  continue;
842  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
843  {
845  return GNUNET_SYSERR;
846  }
847  count++;
848  }
849  }
851  return count;
852 }

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

871 {
872  unsigned int off;
873  union MapEntry me;
874 
875  if (0 == map->size)
876  return 0;
877  if (NULL == it)
878  return 1;
880  for (unsigned int idx = 0; idx < map->map_length; idx++)
881  {
882  me = map->map[idx];
883  if (map->use_small_entries)
884  {
885  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
886  {
887  if (0 == off)
888  {
889  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
890  return GNUNET_SYSERR;
891  return 1;
892  }
893  off--;
894  }
895  }
896  else
897  {
898  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
899  {
900  if (0 == off)
901  {
902  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
903  return GNUNET_SYSERR;
904  return 1;
905  }
906  off--;
907  }
908  }
909  }
910  GNUNET_break (0);
911  return GNUNET_SYSERR;
912 }

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

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

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

207 {
208  return map->size;
209 }

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

226 {
227  struct MapEntry *e;
228 
229  e = map->map[idx_of (map, key)];
230  while (NULL != e)
231  {
232  if (key == e->key)
233  return e->value;
234  e = e->next;
235  }
236  return NULL;
237 }
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: