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 1052 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 1331 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 1614 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 1910 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 };
If a value with the given key exists, replace it.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
There must only be one value per key; storing a value should fail if a value under the same key alrea...
Allow multiple values with the same key.

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

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_response(), 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_create_set(), handle_client_join(), handle_link_controllers(), handle_port_open(), intersection_accept(), intersection_evaluate(), libgnunet_plugin_datacache_heap_init(), libgnunet_plugin_datastore_heap_init(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search(), rest_identity_process_request(), rfn_create(), run(), search_start(), union_accept(), and union_evaluate().

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 }
union MapEntry * map
All of our buckets.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
Internal representation of the hash map.
unsigned int map_length
Length of the "map" array.
Entry in the map.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

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

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

Referenced by __attribute__(), check_unique(), clean_node(), cleanup(), cleanup_handle(), client_disconnect_cb(), close_all_files(), database_shutdown(), destroy_service_session(), disconnect_cb(), do_shutdown(), fail_intersection_operation(), free_download_context(), free_search_context(), free_update_information_graph(), GDS_ROUTING_done(), GNUNET_CADET_disconnect(), GNUNET_DHT_disconnect(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_indexing_done(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_stop(), GNUNET_FS_share_tree_trim(), GNUNET_IDENTITY_disconnect(), GNUNET_PEERSTORE_disconnect(), GNUNET_TESTBED_barrier_remove_(), GSF_peer_disconnect_handler(), GSF_pending_request_done_(), GSF_plan_notify_peer_disconnect_(), GST_barriers_destroy(), intersection_op_cancel(), iterate_zones(), kill_slave(), libgnunet_plugin_datacache_heap_done(), libgnunet_plugin_datastore_heap_done(), libgnunet_plugin_rest_openid_connect_done(), main(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), rfn_create(), search_start(), shutdown_rest(), shutdown_task(), and union_op_cancel().

237 {
238  GNUNET_assert (0 == map->next_cache_off);
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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * 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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

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

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

Referenced by add_file(), add_to_keyword_counter(), add_to_meta_counter(), cb_intersection_element_removed(), check_authorization(), code_redirect(), collector(), cookie_identity_interpretation(), create_response(), diff_insert(), execute_add(), execute_remove(), find_port(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_CLIENTS_handle_reply(), get_file_handle(), get_gns_cont(), get_redirect_state(), get_url_parameter_copy(), GNUNET_FS_add_to_index(), GNUNET_FS_handle_on_demand_block(), handle_barrier_cancel(), handle_barrier_status(), handle_barrier_wait(), handle_identity_set_default(), handle_identity_update(), handle_port_close(), handle_union_p2p_demand(), handle_union_p2p_offer(), handle_watch_record(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), mark_as_reachable(), message_token(), namecache_lookup_block(), namestore_delete(), namestore_flat_lookup_records(), ns_lookup_result_cb(), peerinfo_get(), remove_high_frequency_keywords(), rfn_vote(), route_packet(), and userinfo_endpoint().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct GNUNET_HashCode key
Key for the entry.
Here is the call graph for this function:
Here is the caller 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.

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

Referenced by add_file(), bind_loose_channel(), cb_intersection_element_removed(), clean_channel(), clean_request(), client_disconnect_it(), client_release_ports(), 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(), 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_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(), and setup_state_record().

465 {
466  union MapEntry me;
467  unsigned int i;
468 
469  map->modification_counter++;
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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
unsigned int size
Number of entries in the map.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
#define GNUNET_NO
Definition: gnunet_common.h:78
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
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 struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
Entry in the map.
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...
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller 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.

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

Referenced by expire_blocks(), map_remove_iterator(), namecache_cache_block(), and namestore_flat_store_records().

531 {
532  union MapEntry me;
533  unsigned int i;
534  int ret;
535 
536  map->modification_counter++;
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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
unsigned int size
Number of entries in the map.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
const struct GNUNET_HashCode * key
Key for the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
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 struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Entry in the map.
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...
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_HashCode key
Key for the entry.
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.

References GNUNET_CONTAINER_multihashmap_iterate(), remove_all(), ret, and GNUNET_CONTAINER_MultiHashMap::size.

636 {
637  unsigned int ret;
638 
639  ret = map->size;
641  return ret;
642 }
unsigned int size
Number of entries in the map.
static int remove_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Callback used to remove all entries from the map.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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.

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

Referenced by allocate_v4_address(), allocate_v6_address(), build_authz_response(), check_authorization(), code_redirect(), collector(), cookie_identity_interpretation(), get_gns_cont(), get_url_parameter_copy(), GNUNET_TESTBED_barrier_init_(), handle_barrier_cancel(), handle_barrier_init(), handle_query_message(), handle_union_p2p_offer(), namestore_delete(), peerinfo_get(), publicize_rm(), regex_next_edge(), register_host(), run(), and userinfo_endpoint().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_HashCode key
Key for the entry.
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.

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

Referenced by plan(), and schedule_block_download().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_HashCode key
Key for the entry.
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.

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(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiHashMap::map, GNUNET_CONTAINER_MultiHashMap::map_length, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiHashMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiHashMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_to_keyword_counter(), add_to_meta_counter(), check_unique(), collector(), database_setup(), deserialize_search_result(), dht_get_string_handler(), diff_insert(), execute_add(), filtered_map_initialization(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_ROUTING_add(), get_file_handle(), GNUNET_CADET_open_port(), GNUNET_DHT_get_start(), GNUNET_FS_add_to_index(), GNUNET_FS_namespace_list_updateable(), 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_dht_local_get(), handle_identity_update(), handle_p2p_get(), handle_port_open(), handle_union_p2p_offer(), handle_watch(), header_iterator(), heap_plugin_put(), initialize_map_unfiltered(), load_plugin(), load_state(), login_cont(), maint_child_death(), namecache_cache_block(), namestore_flat_store_records(), peerstore_flat_store_record(), persist_access_token(), post_data_iter(), process_ksk_result(), process_sks_result(), publicize_rm(), put_diff(), put_rfn(), put_set(), 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(), transmit_pending(), update_sre_result_maps(), and url_iterator().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
unsigned int size
Number of entries in the map.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static char * value
Value of the record to add/remove.
unsigned int map_length
Length of the "map" array.
Entry in the map.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
static void grow(struct GNUNET_CONTAINER_MultiHashMap *map)
Grow the given map to a more appropriate size.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
Allow multiple values with the same key.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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.

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

Referenced by begin_bf_exchange(), check_all_done(), cleanup(), cleanup_handle(), client_disconnect_cb(), close_all_files(), collect_generation_garbage(), database_shutdown(), destroy_service_session(), disconnect_cb(), do_reconnect(), do_shutdown(), free_search_context(), 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_PEERSTORE_disconnect(), GSF_iterate_pending_requests_(), GSF_peer_disconnect_handler(), GSF_pending_request_done_(), GST_barriers_destroy(), GST_link_notify_disconnect(), handle_alices_cryptodata_message(), handle_intersection_p2p_done(), heap_get_keys(), heap_plugin_get_closest(), heap_plugin_get_key(), initialize_key_to_element(), iterate_zones(), kill_slave(), libgnunet_plugin_datastore_heap_done(), main(), 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_state(), schedule_transmit_search_request(), send_alices_cryptodata_message(), send_bloomfilter(), send_full_set(), share_tree_trim(), shutdown_task(), signal_search_resume(), transmit_cryptographic_reply(), and try_reconnect().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
unsigned int map_length
Length of the "map" array.
Entry in the map.
A 512-bit hashcode.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.

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

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

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

1015 {
1017 
1019  iter->map = map;
1021  iter->me = map->map[0];
1022  return iter;
1023 }
union MapEntry * map
All of our buckets.
union MapEntry me
Position in the bucket idx.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
const struct GNUNET_CONTAINER_MultiHashMap * map
Map that we are iterating over.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
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.

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiHashMapIterator::idx, 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, BigMapEntry::value, and SmallMapEntry::value.

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

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 }
union MapEntry * map
All of our buckets.
union MapEntry me
Position in the bucket idx.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
const struct GNUNET_CONTAINER_MultiHashMap * map
Map that we are iterating over.
void * value
Value of the entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
unsigned int map_length
Length of the "map" array.
unsigned int idx
Current bucket index.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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.

References GNUNET_free.

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

1093 {
1094  GNUNET_free (iter);
1095 }
#define GNUNET_free(ptr)
Wrapper around free.
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.

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiHashMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiHashMap::next_cache, GNUNET_CONTAINER_MultiHashMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiHashMap::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().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
Entry in the map.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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.

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

Referenced by heap_plugin_get_random().

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 }
union MapEntry * map
All of our buckets.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
unsigned int size
Number of entries in the map.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
Entry in the map.
Randomness for IVs etc.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct GNUNET_HashCode key
Key for the entry.
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 recipie 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 recipie 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.

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(), 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(), GNUNET_TRANSPORT_core_get_mq(), 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(), libgnunet_plugin_transport_http_client_init(), libgnunet_plugin_transport_http_server_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_init(), main(), new_sub(), run(), send_push(), setup_ac(), update_preference(), View_change_len(), and View_create().

194 {
196 
197  GNUNET_assert (len > 0);
199  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
200  if (NULL == map->map)
201  {
202  GNUNET_free (map);
203  return NULL;
204  }
205  map->map_length = len;
206  map->use_small_entries = do_not_copy_keys;
207  return map;
208 }
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
Entry in the map.
union MapEntry * map
All of our buckets.
Internal representation of the hash map.
unsigned int map_length
Length of the "map" array.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 218 of file container_multipeermap.c.

References GNUNET_assert, GNUNET_free, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, 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_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(), GNUNET_TRANSPORT_core_get_mq(), GSC_SESSIONS_done(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_plan_done(), GST_ats_done(), GST_manipulation_stop(), GST_neighbours_stop(), GST_validation_stop(), handle_connection_create(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_http_server_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_done(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_done(), main(), peers_terminate(), shutdown_rest(), shutdown_task(), View_change_len(), and View_destroy().

220 {
221  GNUNET_assert (0 == map->next_cache_off);
222  for (unsigned int i = 0; i < map->map_length; i++)
223  {
224  union MapEntry me;
225 
226  me = map->map[i];
227  if (map->use_small_entries)
228  {
229  struct SmallMapEntry *sme;
230  struct SmallMapEntry *nxt;
231 
232  nxt = me.sme;
233  while (NULL != (sme = nxt))
234  {
235  nxt = sme->next;
236  GNUNET_free (sme);
237  }
238  me.sme = NULL;
239  }
240  else
241  {
242  struct BigMapEntry *bme;
243  struct BigMapEntry *nxt;
244 
245  nxt = me.bme;
246  while (NULL != (bme = nxt))
247  {
248  nxt = bme->next;
249  GNUNET_free (bme);
250  }
251  me.bme = NULL;
252  }
253  }
254  GNUNET_free (map->map);
255  GNUNET_free (map);
256 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
union MapEntry * map
All of our buckets.
An entry in the hash map with just a pointer to the key.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
An entry in the hash map with the full key.
unsigned int map_length
Length of the "map" array.
#define GNUNET_free(ptr)
Wrapper around free.
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 303 of file container_multipeermap.c.

References MapEntry::bme, GNUNET_memcmp, idx_of(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, 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(), 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(), 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_recv(), 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(), reservations_reserve(), route_control_message_without_fc(), try_connect(), update_hello(), update_preference(), update_relative_values_for_peer(), View_change_len(), View_clear(), and View_remove_peer().

306 {
307  union MapEntry me;
308 
309  me = map->map[idx_of (map, key)];
310  if (map->use_small_entries)
311  {
312  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
313  if (0 == GNUNET_memcmp (key, sme->key))
314  return sme->value;
315  }
316  else
317  {
318  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
319  if (0 == GNUNET_memcmp (key, &bme->key))
320  return bme->value;
321  }
322  return NULL;
323 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
union MapEntry * map
All of our buckets.
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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 444 of file container_multipeermap.c.

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

Referenced by ats_perf_mon_cb(), 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(), 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_ATS_connectivity_suggest_cancel(), 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().

447 {
448  union MapEntry me;
449  unsigned int i;
450 
451  map->modification_counter++;
452  i = idx_of (map, key);
453  me = map->map[i];
454  if (map->use_small_entries)
455  {
456  struct SmallMapEntry *p = NULL;
457 
458  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
459  {
460  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
461  {
462  if (NULL == p)
463  map->map[i].sme = sme->next;
464  else
465  p->next = sme->next;
466  update_next_cache_sme (map, sme);
467  GNUNET_free (sme);
468  map->size--;
469  return GNUNET_YES;
470  }
471  p = sme;
472  }
473  }
474  else
475  {
476  struct BigMapEntry *p = NULL;
477 
478  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
479  {
480  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
481  {
482  if (NULL == p)
483  map->map[i].bme = bme->next;
484  else
485  p->next = bme->next;
486  update_next_cache_bme (map, bme);
487  GNUNET_free (bme);
488  map->size--;
489  return GNUNET_YES;
490  }
491  p = bme;
492  }
493  }
494  return GNUNET_NO;
495 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
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...
unsigned int size
Number of entries in the map.
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...
#define GNUNET_NO
Definition: gnunet_common.h:78
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
Entry in the map.
union MapEntry * map
All of our buckets.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove_all()

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

Remove all entries for the given key from the map.

Note that the values would not be "freed".

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

Definition at line 507 of file container_multipeermap.c.

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

510 {
511  union MapEntry me;
512  unsigned int i;
513  int ret;
514 
515  map->modification_counter++;
516 
517  ret = 0;
518  i = idx_of (map, key);
519  me = map->map[i];
520  if (map->use_small_entries)
521  {
522  struct SmallMapEntry *sme;
523  struct SmallMapEntry *p;
524 
525  p = NULL;
526  sme = me.sme;
527  while (NULL != sme)
528  {
529  if (0 == GNUNET_memcmp (key, sme->key))
530  {
531  if (NULL == p)
532  map->map[i].sme = sme->next;
533  else
534  p->next = sme->next;
535  update_next_cache_sme (map, sme);
536  GNUNET_free (sme);
537  map->size--;
538  if (NULL == p)
539  sme = map->map[i].sme;
540  else
541  sme = p->next;
542  ret++;
543  }
544  else
545  {
546  p = sme;
547  sme = sme->next;
548  }
549  }
550  }
551  else
552  {
553  struct BigMapEntry *bme;
554  struct BigMapEntry *p;
555 
556  p = NULL;
557  bme = me.bme;
558  while (NULL != bme)
559  {
560  if (0 == GNUNET_memcmp (key, &bme->key))
561  {
562  if (NULL == p)
563  map->map[i].bme = bme->next;
564  else
565  p->next = bme->next;
566  update_next_cache_bme (map, bme);
567  GNUNET_free (bme);
568  map->size--;
569  if (NULL == p)
570  bme = map->map[i].bme;
571  else
572  bme = p->next;
573  ret++;
574  }
575  else
576  {
577  p = bme;
578  bme = bme->next;
579  }
580  }
581  }
582  return ret;
583 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
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...
unsigned int size
Number of entries in the map.
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 int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
const struct GNUNET_HashCode * key
Key for the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Entry in the map.
union MapEntry * map
All of our buckets.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_HashCode key
Key for the entry.
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 596 of file container_multipeermap.c.

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

Referenced by addr_info_cb(), check_access(), check_peer_known(), check_peer_valid(), check_removable(), clean_peer(), 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_reply(), 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().

599 {
600  union MapEntry me;
601 
602  me = map->map[idx_of (map, key)];
603  if (map->use_small_entries)
604  {
605  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
606  if (0 == GNUNET_memcmp (key, sme->key))
607  return GNUNET_YES;
608  }
609  else
610  {
611  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
612  if (0 == GNUNET_memcmp (key, &bme->key))
613  return GNUNET_YES;
614  }
615  return GNUNET_NO;
616 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
union MapEntry * map
All of our buckets.
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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 630 of file container_multipeermap.c.

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, 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().

634 {
635  union MapEntry me;
636 
637  me = map->map[idx_of (map, key)];
638  if (map->use_small_entries)
639  {
640  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
641  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
642  return GNUNET_YES;
643  }
644  else
645  {
646  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
647  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
648  return GNUNET_YES;
649  }
650  return GNUNET_NO;
651 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
Entry in the map.
union MapEntry * map
All of our buckets.
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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 726 of file container_multipeermap.c.

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(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by activate_core_visible_dv_path(), add_host_to_known_hosts(), add_peer_array_to_set(), add_valid_peer(), addr_info_cb(), ats_perf_mon_cb(), boot_queue(), connect_peer(), core_connects(), create_peer_ctx(), cummulative_ack(), CustomPeerMap_put(), enforce_add_address(), 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().

730 {
731  union MapEntry me;
732  unsigned int i;
733 
734  i = idx_of (map, key);
737  {
738  me = map->map[i];
739  if (map->use_small_entries)
740  {
741  struct SmallMapEntry *sme;
742 
743  for (sme = me.sme; NULL != sme; sme = sme->next)
744  if (0 == GNUNET_memcmp (key, sme->key))
745  {
747  return GNUNET_SYSERR;
748  sme->value = value;
749  return GNUNET_NO;
750  }
751  }
752  else
753  {
754  struct BigMapEntry *bme;
755 
756  for (bme = me.bme; NULL != bme; bme = bme->next)
757  if (0 == GNUNET_memcmp (key, &bme->key))
758  {
760  return GNUNET_SYSERR;
761  bme->value = value;
762  return GNUNET_NO;
763  }
764  }
765  }
766  if (map->size / 3 >= map->map_length / 4)
767  {
768  grow (map);
769  i = idx_of (map, key);
770  }
771  if (map->use_small_entries)
772  {
773  struct SmallMapEntry *sme;
774 
775  sme = GNUNET_new (struct SmallMapEntry);
776  sme->key = key;
777  sme->value = value;
778  sme->next = map->map[i].sme;
779  map->map[i].sme = sme;
780  }
781  else
782  {
783  struct BigMapEntry *bme;
784 
785  bme = GNUNET_new (struct BigMapEntry);
786  bme->key = *key;
787  bme->value = value;
788  bme->next = map->map[i].bme;
789  map->map[i].bme = bme;
790  }
791  map->size++;
792  return GNUNET_OK;
793 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
static void grow(struct GNUNET_CONTAINER_MultiPeerMap *map)
Grow the given map to a more appropriate size.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int size
Number of entries in the map.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static char * value
Value of the record to add/remove.
Entry in the map.
union MapEntry * map
All of our buckets.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Allow multiple values with the same key.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
unsigned int map_length
Length of the "map" array.
struct GNUNET_HashCode key
Key for the entry.
Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_size()

unsigned int GNUNET_CONTAINER_multipeermap_size ( const struct GNUNET_CONTAINER_MultiPeerMap map)

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

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 285 of file container_multipeermap.c.

References GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by add_peer_array_to_set(), add_valid_peer(), boot_queue(), create_peer_ctx(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), CustomPeerMap_remove_peer_by_index(), CustomPeerMap_size(), destroy_peer(), do_shutdown(), GAS_addresses_destroy_all(), GAS_addresses_get_peer_info(), GDS_NEIGHBOURS_done(), get_random_peer_from_peermap(), get_target_peers(), GSC_SESSIONS_create(), GSC_SESSIONS_end(), GSF_peer_connect_handler(), GSF_peer_disconnect_handler(), GSF_plan_done(), handle_core_connect(), handle_core_disconnect(), handle_dv_learn(), insert_in_sampler(), mq_init(), publish_p2a_stat_update(), publish_ve_stat_update(), queue_destroy(), receiver_destroy(), restore_valid_peers(), sender_destroy(), setup_estimate_message(), setup_queue(), setup_sender(), shutdown_task(), start_dv_learn(), store_valid_peers(), udp_disconnect_session(), udp_plugin_create_session(), unix_plugin_get_session(), unix_plugin_session_disconnect(), update_addresses_stat(), View_change_len(), View_get_peer_by_index(), and View_size().

287 {
288  return map->size;
289 }
unsigned int size
Number of entries in the map.
Here is the caller graph for this function:

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

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, 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(), disconnect(), disconnect_and_schedule_reconnect(), do_shutdown(), end(), 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_manipulation_stop(), GST_neighbours_iterate(), GST_neighbours_stop(), 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_http_server_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_udp_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(), 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().

340 {
341  int count;
342  union MapEntry me;
343  union MapEntry *ce;
344  struct GNUNET_PeerIdentity kc;
345 
346  count = 0;
347  GNUNET_assert (NULL != map);
348  ce = &map->next_cache[map->next_cache_off];
350  for (unsigned int i = 0; i < map->map_length; i++)
351  {
352  me = map->map[i];
353  if (map->use_small_entries)
354  {
355  struct SmallMapEntry *sme;
356 
357  ce->sme = me.sme;
358  while (NULL != (sme = ce->sme))
359  {
360  ce->sme = sme->next;
361  if (NULL != it)
362  {
363  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
364  {
366  return GNUNET_SYSERR;
367  }
368  }
369  count++;
370  }
371  }
372  else
373  {
374  struct BigMapEntry *bme;
375 
376  ce->bme = me.bme;
377  while (NULL != (bme = ce->bme))
378  {
379  ce->bme = bme->next;
380  if (NULL != it)
381  {
382  kc = bme->key;
383  if (GNUNET_OK != it (it_cls, &kc, bme->value))
384  {
386  return GNUNET_SYSERR;
387  }
388  }
389  count++;
390  }
391  }
392  }
394  return count;
395 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
Entry in the map.
union MapEntry * map
All of our buckets.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
The identity of the host (wraps the signing key of the peer).
An entry in the hash map with just a pointer to the key.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
unsigned int map_length
Length of the "map" array.
struct GNUNET_HashCode key
Key for the entry.

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

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.

947 {
949 
951  iter->map = map;
953  iter->me = map->map[0];
954  return iter;
955 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
union MapEntry * map
All of our buckets.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry me
Position in the bucket &#39;idx&#39;.
const struct GNUNET_CONTAINER_MultiPeerMap * map
Map that we are iterating over.

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

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiPeerMapIterator::idx, 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, BigMapEntry::value, and SmallMapEntry::value.

977 {
978  /* make sure the map has not been modified */
980 
981  /* look for the next entry, skipping empty buckets */
982  while (1)
983  {
984  if (iter->idx >= iter->map->map_length)
985  return GNUNET_NO;
986  if (GNUNET_YES == iter->map->use_small_entries)
987  {
988  if (NULL != iter->me.sme)
989  {
990  if (NULL != key)
991  *key = *iter->me.sme->key;
992  if (NULL != value)
993  *value = iter->me.sme->value;
994  iter->me.sme = iter->me.sme->next;
995  return GNUNET_YES;
996  }
997  }
998  else
999  {
1000  if (NULL != iter->me.bme)
1001  {
1002  if (NULL != key)
1003  *key = iter->me.bme->key;
1004  if (NULL != value)
1005  *value = iter->me.bme->value;
1006  iter->me.bme = iter->me.bme->next;
1007  return GNUNET_YES;
1008  }
1009  }
1010  iter->idx += 1;
1011  if (iter->idx < iter->map->map_length)
1012  iter->me = iter->map->map[iter->idx];
1013  }
1014 }
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
unsigned int idx
Current bucket index.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
union MapEntry * map
All of our buckets.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry me
Position in the bucket &#39;idx&#39;.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
unsigned int map_length
Length of the "map" array.
struct GNUNET_HashCode key
Key for the entry.
const struct GNUNET_CONTAINER_MultiPeerMap * map
Map that we are iterating over.

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

References GNUNET_free.

1025 {
1026  GNUNET_free (iter);
1027 }
#define GNUNET_free(ptr)
Wrapper around 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 807 of file container_multipeermap.c.

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, 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().

812 {
813  int count;
814  union MapEntry me;
815  union MapEntry *ce;
816 
817  ce = &map->next_cache[map->next_cache_off];
819  count = 0;
820  me = map->map[idx_of (map, key)];
821  if (map->use_small_entries)
822  {
823  struct SmallMapEntry *sme;
824 
825  ce->sme = me.sme;
826  while (NULL != (sme = ce->sme))
827  {
828  ce->sme = sme->next;
829  if (0 != GNUNET_memcmp (key, sme->key))
830  continue;
831  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
832  {
834  return GNUNET_SYSERR;
835  }
836  count++;
837  }
838  }
839  else
840  {
841  struct BigMapEntry *bme;
842 
843  ce->bme = me.bme;
844  while (NULL != (bme = ce->bme))
845  {
846  ce->bme = bme->next;
847  if (0 != GNUNET_memcmp (key, &bme->key))
848  continue;
849  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
850  {
852  return GNUNET_SYSERR;
853  }
854  count++;
855  }
856  }
858  return count;
859 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
Entry in the map.
union MapEntry * map
All of our buckets.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
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 874 of file container_multipeermap.c.

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

878 {
879  unsigned int off;
880  union MapEntry me;
881 
882  if (0 == map->size)
883  return 0;
884  if (NULL == it)
885  return 1;
887  for (unsigned int idx = 0; idx < map->map_length; idx++)
888  {
889  me = map->map[idx];
890  if (map->use_small_entries)
891  {
892  struct SmallMapEntry *sme;
893  struct SmallMapEntry *nxt;
894 
895  nxt = me.sme;
896  while (NULL != (sme = nxt))
897  {
898  nxt = sme->next;
899  if (0 == off)
900  {
901  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
902  return GNUNET_SYSERR;
903  return 1;
904  }
905  off--;
906  }
907  }
908  else
909  {
910  struct BigMapEntry *bme;
911  struct BigMapEntry *nxt;
912 
913  nxt = me.bme;
914  while (NULL != (bme = nxt))
915  {
916  nxt = bme->next;
917  if (0 == off)
918  {
919  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
920  return GNUNET_SYSERR;
921  return 1;
922  }
923  off--;
924  }
925  }
926  }
927  GNUNET_break (0);
928  return GNUNET_SYSERR;
929 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
unsigned int size
Number of entries in the map.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
union MapEntry * map
All of our buckets.
Randomness for IVs etc.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
unsigned int map_length
Length of the "map" array.
struct GNUNET_HashCode key
Key for the entry.
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 recipie 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 recipie 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.

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

Referenced by GCO_init(), GCP_get(), and run().

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 }
unsigned int map_length
Length of the "map" array.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
Internal representation of the hash map.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
union MapEntry * map
All of our buckets.
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.

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

Referenced by destroy_peer(), do_shutdown(), GCO_shutdown(), and shutdown_rest().

221 {
222  GNUNET_assert (0 == map->next_cache_off);
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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_free(ptr)
Wrapper around free.
union MapEntry * map
All of our buckets.
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.

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

Referenced by GCC_lookup(), get_route(), and sock_read().

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 GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
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.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
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.

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

Referenced by destroy_route(), GCC_destroy(), GCP_remove_connection(), kce_destroy(), and start_dv_learn().

446 {
447  union MapEntry me;
448  unsigned int i;
449 
450  map->modification_counter++;
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 GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
#define GNUNET_NO
Definition: gnunet_common.h:78
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...
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
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.
Entry in the map.
unsigned int size
Number of entries in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
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...
#define GNUNET_free(ptr)
Wrapper around free.
union MapEntry * map
All of our buckets.
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.

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

509 {
510  union MapEntry me;
511  unsigned int i;
512  int ret;
513 
514  map->modification_counter++;
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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
const struct GNUNET_HashCode * key
Key for the entry.
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...
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
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.
Entry in the map.
unsigned int size
Number of entries in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
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...
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
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.

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

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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
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.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
Here is the call 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.

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

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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
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.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
Here is the call 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.

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(), BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiShortmap::map, GNUNET_CONTAINER_MultiShortmap::map_length, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiShortmap::size, MapEntry::sme, GNUNET_CONTAINER_MultiShortmap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by connection_create(), GCP_add_connection(), handle_connection_create(), kce_generate(), and start_dv_learn().

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 GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static char * value
Value of the record to add/remove.
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.
Entry in the map.
unsigned int size
Number of entries in the map.
static void grow(struct GNUNET_CONTAINER_MultiShortmap *map)
Grow the given map to a more appropriate size.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Allow multiple values with the same key.
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
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.

References GNUNET_CONTAINER_MultiShortmap::size.

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

288 {
289  return map->size;
290 }
unsigned int size
Number of entries in the map.
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.

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

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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
void * value
Value of the entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
A 256-bit hashcode.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
An entry in the hash map with just a pointer to the key.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.

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

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

932 {
934 
936  iter->map = map;
938  iter->me = map->map[0];
939  return iter;
940 }
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
union MapEntry me
Position in the bucket &#39;idx&#39;.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const struct GNUNET_CONTAINER_MultiShortmap * map
Map that we are iterating over.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
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.

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

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiShortmapIterator::idx, 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, BigMapEntry::value, and SmallMapEntry::value.

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 }
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
void * value
Value of the entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
union MapEntry me
Position in the bucket &#39;idx&#39;.
unsigned int idx
Current bucket index.
const struct GNUNET_HashCode * key
Key for the entry.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * value
Value of the entry.
const struct GNUNET_CONTAINER_MultiShortmap * map
Map that we are iterating over.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
static char * value
Value of the record to add/remove.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
#define GNUNET_YES
Definition: gnunet_common.h:77
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.

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

References GNUNET_free.

1010 {
1011  GNUNET_free (iter);
1012 }
#define GNUNET_free(ptr)
Wrapper around 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.

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

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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
void * value
Value of the entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
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.
Entry in the map.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselve s aga...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
An entry in the hash map with just a pointer to the key.
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
Here is the call 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.

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

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 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int map_length
Length of the "map" array.
void * value
Value of the entry.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
const struct GNUNET_HashCode * key
Key for the entry.
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
Entry in the map.
unsigned int size
Number of entries in the map.
Randomness for IVs etc.
int use_small_entries
GNUNET_NO if the map entries are of type &#39;struct BigMapEntry&#39;, GNUNET_YES if the map entries are of t...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
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 recipie 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 recipie 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.

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

Referenced by run().

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;