GNUnet  0.10.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 765 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 1048 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 1327 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 1610 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 1906 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 719 of file gnunet_container_lib.h.

719  {
727 
733 
740 
751 };
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 189 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().

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

232 {
233  GNUNET_assert(0 == map->next_cache_off);
234  for (unsigned int i = 0; i < map->map_length; i++)
235  {
236  union MapEntry me;
237 
238  me = map->map[i];
239  if (map->use_small_entries)
240  {
241  struct SmallMapEntry *sme;
242  struct SmallMapEntry *nxt;
243 
244  nxt = me.sme;
245  while (NULL != (sme = nxt))
246  {
247  nxt = sme->next;
248  GNUNET_free(sme);
249  }
250  me.sme = NULL;
251  }
252  else
253  {
254  struct BigMapEntry *bme;
255  struct BigMapEntry *nxt;
256 
257  nxt = me.bme;
258  while (NULL != (bme = nxt))
259  {
260  nxt = bme->next;
261  GNUNET_free(bme);
262  }
263  me.bme = NULL;
264  }
265  }
266  GNUNET_free(map->map);
267  GNUNET_free(map);
268 }
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 312 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(), collect_cred_cont(), 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_cred_issuer_cb(), 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(), userinfo_endpoint(), and verify_cred_cont().

315 {
316  union MapEntry me;
317 
318  me = map->map[idx_of(map, key)];
319  if (map->use_small_entries)
320  {
321  struct SmallMapEntry *sme;
322 
323  for (sme = me.sme; NULL != sme; sme = sme->next)
324  if (0 == GNUNET_memcmp(key, sme->key))
325  return sme->value;
326  }
327  else
328  {
329  struct BigMapEntry *bme;
330 
331  for (bme = me.bme; NULL != bme; bme = bme->next)
332  if (0 == GNUNET_memcmp(key, &bme->key))
333  return bme->value;
334  }
335  return NULL;
336 }
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:

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

460 {
461  union MapEntry me;
462  unsigned int i;
463 
464  map->modification_counter++;
465 
466  i = idx_of(map, key);
467  me = map->map[i];
468  if (map->use_small_entries)
469  {
470  struct SmallMapEntry *p;
471 
472  p = NULL;
473  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
474  {
475  if ((0 == GNUNET_memcmp(key, sme->key)) && (value == sme->value))
476  {
477  if (NULL == p)
478  map->map[i].sme = sme->next;
479  else
480  p->next = sme->next;
481  update_next_cache_sme(map, sme);
482  GNUNET_free(sme);
483  map->size--;
484  return GNUNET_YES;
485  }
486  p = sme;
487  }
488  }
489  else
490  {
491  struct BigMapEntry *p;
492 
493  p = NULL;
494  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
495  {
496  if ((0 == GNUNET_memcmp(key, &bme->key)) && (value == bme->value))
497  {
498  if (NULL == p)
499  map->map[i].bme = bme->next;
500  else
501  p->next = bme->next;
502  update_next_cache_bme(map, bme);
503  GNUNET_free(bme);
504  map->size--;
505  return GNUNET_YES;
506  }
507  p = bme;
508  }
509  }
510  return GNUNET_NO;
511 }
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 523 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().

526 {
527  union MapEntry me;
528  unsigned int i;
529  int ret;
530 
531  map->modification_counter++;
532 
533  ret = 0;
534  i = idx_of(map, key);
535  me = map->map[i];
536  if (map->use_small_entries)
537  {
538  struct SmallMapEntry *sme;
539  struct SmallMapEntry *p;
540 
541  p = NULL;
542  sme = me.sme;
543  while (NULL != sme)
544  {
545  if (0 == GNUNET_memcmp(key, sme->key))
546  {
547  if (NULL == p)
548  map->map[i].sme = sme->next;
549  else
550  p->next = sme->next;
551  update_next_cache_sme(map, sme);
552  GNUNET_free(sme);
553  map->size--;
554  if (NULL == p)
555  sme = map->map[i].sme;
556  else
557  sme = p->next;
558  ret++;
559  }
560  else
561  {
562  p = sme;
563  sme = sme->next;
564  }
565  }
566  }
567  else
568  {
569  struct BigMapEntry *bme;
570  struct BigMapEntry *p;
571 
572  p = NULL;
573  bme = me.bme;
574  while (NULL != bme)
575  {
576  if (0 == GNUNET_memcmp(key, &bme->key))
577  {
578  if (NULL == p)
579  map->map[i].bme = bme->next;
580  else
581  p->next = bme->next;
582  update_next_cache_bme(map, bme);
583  GNUNET_free(bme);
584  map->size--;
585  if (NULL == p)
586  bme = map->map[i].bme;
587  else
588  bme = p->next;
589  ret++;
590  }
591  else
592  {
593  p = bme;
594  bme = bme->next;
595  }
596  }
597  }
598  return ret;
599 }
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...
const struct GNUNET_HashCode * key
Key for the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 630 of file container_multihashmap.c.

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

631 {
632  unsigned int ret;
633 
634  ret = map->size;
636  return ret;
637 }
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
Final status code.
Definition: gnunet-arm.c:89
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 650 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(), collect_cred_cont(), collector(), cookie_identity_interpretation(), get_cred_issuer_cb(), 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(), userinfo_endpoint(), and verify_cred_cont().

653 {
654  union MapEntry me;
655 
656  me = map->map[idx_of(map, key)];
657  if (map->use_small_entries)
658  {
659  struct SmallMapEntry *sme;
660 
661  for (sme = me.sme; NULL != sme; sme = sme->next)
662  if (0 == GNUNET_memcmp(key, sme->key))
663  return GNUNET_YES;
664  }
665  else
666  {
667  struct BigMapEntry *bme;
668 
669  for (bme = me.bme; NULL != bme; bme = bme->next)
670  if (0 == GNUNET_memcmp(key, &bme->key))
671  return GNUNET_YES;
672  }
673  return GNUNET_NO;
674 }
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 688 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().

692 {
693  union MapEntry me;
694 
695  me = map->map[idx_of(map, key)];
696  if (map->use_small_entries)
697  {
698  struct SmallMapEntry *sme;
699 
700  for (sme = me.sme; NULL != sme; sme = sme->next)
701  if ((0 == GNUNET_memcmp(key, sme->key)) && (sme->value == value))
702  return GNUNET_YES;
703  }
704  else
705  {
706  struct BigMapEntry *bme;
707 
708  for (bme = me.bme; NULL != bme; bme = bme->next)
709  if ((0 == GNUNET_memcmp(key, &bme->key)) && (bme->value == value))
710  return GNUNET_YES;
711  }
712  return GNUNET_NO;
713 }
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 788 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().

792 {
793  union MapEntry me;
794  unsigned int i;
795 
796  i = idx_of(map, key);
799  {
800  me = map->map[i];
801  if (map->use_small_entries)
802  {
803  struct SmallMapEntry *sme;
804 
805  for (sme = me.sme; NULL != sme; sme = sme->next)
806  if (0 == GNUNET_memcmp(key, sme->key))
807  {
809  return GNUNET_SYSERR;
810  sme->value = value;
811  return GNUNET_NO;
812  }
813  }
814  else
815  {
816  struct BigMapEntry *bme;
817 
818  for (bme = me.bme; NULL != bme; bme = bme->next)
819  if (0 == GNUNET_memcmp(key, &bme->key))
820  {
822  return GNUNET_SYSERR;
823  bme->value = value;
824  return GNUNET_NO;
825  }
826  }
827  }
828  if (map->size / 3 >= map->map_length / 4)
829  {
830  grow(map);
831  i = idx_of(map, key);
832  }
833  if (map->use_small_entries)
834  {
835  struct SmallMapEntry *sme;
836 
837  sme = GNUNET_new(struct SmallMapEntry);
838  sme->key = key;
839  sme->value = value;
840  sme->next = map->map[i].sme;
841  map->map[i].sme = sme;
842  }
843  else
844  {
845  struct BigMapEntry *bme;
846 
847  bme = GNUNET_new(struct BigMapEntry);
848  bme->key = *key;
849  bme->value = value;
850  bme->next = map->map[i].bme;
851  map->map[i].bme = bme;
852  }
853  map->size++;
854  return GNUNET_OK;
855 }
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 349 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().

353 {
354  int count;
355  union MapEntry me;
356  union MapEntry *ce;
357  struct GNUNET_HashCode kc;
358 
359  GNUNET_assert(NULL != map);
360  ce = &map->next_cache[map->next_cache_off];
362  count = 0;
363  for (unsigned i = 0; i < map->map_length; i++)
364  {
365  me = map->map[i];
366  if (map->use_small_entries)
367  {
368  struct SmallMapEntry *sme;
369 
370  ce->sme = me.sme;
371  while (NULL != (sme = ce->sme))
372  {
373  ce->sme = sme->next;
374  if (NULL != it)
375  {
376  if (GNUNET_OK != it(it_cls, sme->key, sme->value))
377  {
379  return GNUNET_SYSERR;
380  }
381  }
382  count++;
383  }
384  }
385  else
386  {
387  struct BigMapEntry *bme;
388 
389  ce->bme = me.bme;
390  while (NULL != (bme = ce->bme))
391  {
392  ce->bme = bme->next;
393  if (NULL != it)
394  {
395  kc = bme->key;
396  if (GNUNET_OK != it(it_cls, &kc, bme->value))
397  {
399  return GNUNET_SYSERR;
400  }
401  }
402  count++;
403  }
404  }
405  }
407  return count;
408 }
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 1008 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().

1010 {
1012 
1014  iter->map = map;
1016  iter->me = map->map[0];
1017  return iter;
1018 }
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 1036 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().

1040 {
1041  /* make sure the map has not been modified */
1043 
1044  /* look for the next entry, skipping empty buckets */
1045  while (1)
1046  {
1047  if (iter->idx >= iter->map->map_length)
1048  return GNUNET_NO;
1049  if (GNUNET_YES == iter->map->use_small_entries)
1050  {
1051  if (NULL != iter->me.sme)
1052  {
1053  if (NULL != key)
1054  *key = *iter->me.sme->key;
1055  if (NULL != value)
1056  *value = iter->me.sme->value;
1057  iter->me.sme = iter->me.sme->next;
1058  return GNUNET_YES;
1059  }
1060  }
1061  else
1062  {
1063  if (NULL != iter->me.bme)
1064  {
1065  if (NULL != key)
1066  *key = iter->me.bme->key;
1067  if (NULL != value)
1068  *value = iter->me.bme->value;
1069  iter->me.bme = iter->me.bme->next;
1070  return GNUNET_YES;
1071  }
1072  }
1073  iter->idx += 1;
1074  if (iter->idx < iter->map->map_length)
1075  iter->me = iter->map->map[iter->idx];
1076  }
1077 }
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 1086 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().

1088 {
1089  GNUNET_free(iter);
1090 }
#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 869 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().

874 {
875  int count;
876  union MapEntry *me;
877  union MapEntry *ce;
878 
879  ce = &map->next_cache[map->next_cache_off];
881  count = 0;
882  me = &map->map[idx_of(map, key)];
883  if (map->use_small_entries)
884  {
885  struct SmallMapEntry *sme;
886 
887  ce->sme = me->sme;
888  while (NULL != (sme = ce->sme))
889  {
890  ce->sme = sme->next;
891  if (0 != GNUNET_memcmp(key, sme->key))
892  continue;
893  if ((NULL != it) && (GNUNET_OK != it(it_cls, key, sme->value)))
894  {
896  return GNUNET_SYSERR;
897  }
898  count++;
899  }
900  }
901  else
902  {
903  struct BigMapEntry *bme;
904 
905  ce->bme = me->bme;
906  while (NULL != (bme = ce->bme))
907  {
908  ce->bme = bme->next;
909  if (0 != GNUNET_memcmp(key, &bme->key))
910  continue;
911  if ((NULL != it) && (GNUNET_OK != it(it_cls, key, bme->value)))
912  {
914  return GNUNET_SYSERR;
915  }
916  count++;
917  }
918  }
920  return count;
921 }
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 936 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().

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

189 {
191 
192  GNUNET_assert(len > 0);
194  map->map = GNUNET_malloc_large(len * sizeof(union MapEntry));
195  if (NULL == map->map)
196  {
197  GNUNET_free(map);
198  return NULL;
199  }
200  map->map_length = len;
201  map->use_small_entries = do_not_copy_keys;
202  return map;
203 }
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 213 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_application_done(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), GNUNET_ATS_transport_done(), 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_ats2_simple_done(), libgnunet_plugin_ats_mlp_done(), 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().

215 {
216  GNUNET_assert(0 == map->next_cache_off);
217  for (unsigned int i = 0; i < map->map_length; i++)
218  {
219  union MapEntry me;
220 
221  me = map->map[i];
222  if (map->use_small_entries)
223  {
224  struct SmallMapEntry *sme;
225  struct SmallMapEntry *nxt;
226 
227  nxt = me.sme;
228  while (NULL != (sme = nxt))
229  {
230  nxt = sme->next;
231  GNUNET_free(sme);
232  }
233  me.sme = NULL;
234  }
235  else
236  {
237  struct BigMapEntry *bme;
238  struct BigMapEntry *nxt;
239 
240  nxt = me.bme;
241  while (NULL != (bme = nxt))
242  {
243  nxt = bme->next;
244  GNUNET_free(bme);
245  }
246  me.bme = NULL;
247  }
248  }
249  GNUNET_free(map->map);
250  GNUNET_free(map);
251 }
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 298 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_mlp_address_add(), GAS_mlp_address_change_preference(), GAS_mlp_address_delete(), GAS_mlp_address_property_changed(), GAS_mlp_get_preferred_address(), GAS_mlp_stop_get_preferred_address(), 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_peer(), lookup_virtual_link(), mlp_create_problem_add_address_information(), 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().

301 {
302  union MapEntry me;
303 
304  me = map->map[idx_of(map, key)];
305  if (map->use_small_entries)
306  {
307  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
308  if (0 == GNUNET_memcmp(key, sme->key))
309  return sme->value;
310  }
311  else
312  {
313  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
314  if (0 == GNUNET_memcmp(key, &bme->key))
315  return bme->value;
316  }
317  return NULL;
318 }
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 439 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_mlp_stop_get_preferred_address(), GAS_reservations_set_bandwidth(), GNUNET_ATS_application_suggest_cancel(), 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(), mlp_free_peers(), neighbour_delete(), peer_free(), queue_destroy(), receiver_destroy(), sender_destroy(), server_delete_session(), stop_peer_request(), tcp_plugin_disconnect_session(), udp_disconnect_session(), and unix_plugin_session_disconnect().

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

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

505 {
506  union MapEntry me;
507  unsigned int i;
508  int ret;
509 
510  map->modification_counter++;
511 
512  ret = 0;
513  i = idx_of(map, key);
514  me = map->map[i];
515  if (map->use_small_entries)
516  {
517  struct SmallMapEntry *sme;
518  struct SmallMapEntry *p;
519 
520  p = NULL;
521  sme = me.sme;
522  while (NULL != sme)
523  {
524  if (0 == GNUNET_memcmp(key, sme->key))
525  {
526  if (NULL == p)
527  map->map[i].sme = sme->next;
528  else
529  p->next = sme->next;
530  update_next_cache_sme(map, sme);
531  GNUNET_free(sme);
532  map->size--;
533  if (NULL == p)
534  sme = map->map[i].sme;
535  else
536  sme = p->next;
537  ret++;
538  }
539  else
540  {
541  p = sme;
542  sme = sme->next;
543  }
544  }
545  }
546  else
547  {
548  struct BigMapEntry *bme;
549  struct BigMapEntry *p;
550 
551  p = NULL;
552  bme = me.bme;
553  while (NULL != bme)
554  {
555  if (0 == GNUNET_memcmp(key, &bme->key))
556  {
557  if (NULL == p)
558  map->map[i].bme = bme->next;
559  else
560  p->next = bme->next;
561  update_next_cache_bme(map, bme);
562  GNUNET_free(bme);
563  map->size--;
564  if (NULL == p)
565  bme = map->map[i].bme;
566  else
567  bme = p->next;
568  ret++;
569  }
570  else
571  {
572  p = bme;
573  bme = bme->next;
574  }
575  }
576  }
577  return ret;
578 }
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...
const struct GNUNET_HashCode * key
Key for the entry.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 591 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(), GAS_mlp_get_preferred_address(), 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(), mlp_create_problem_add_address_information(), mlp_create_problem_count_addresses_it(), mlp_create_problem_count_peers_it(), mlp_propagate_results(), mq_notify_sent_cb(), send_pull_request(), send_push(), tcp_plugin_get_session(), try_connect(), View_clear(), and View_contains_peer().

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

629 {
630  union MapEntry me;
631 
632  me = map->map[idx_of(map, key)];
633  if (map->use_small_entries)
634  {
635  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
636  if ((0 == GNUNET_memcmp(key, sme->key)) && (sme->value == value))
637  return GNUNET_YES;
638  }
639  else
640  {
641  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
642  if ((0 == GNUNET_memcmp(key, &bme->key)) && (bme->value == value))
643  return GNUNET_YES;
644  }
645  return GNUNET_NO;
646 }
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 721 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_mlp_get_preferred_address(), GAS_reservations_set_bandwidth(), GCP_get(), get_cadet(), GNUNET_ATS_application_suggest(), GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_session_add(), 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_add(), 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().

725 {
726  union MapEntry me;
727  unsigned int i;
728 
729  i = idx_of(map, key);
732  {
733  me = map->map[i];
734  if (map->use_small_entries)
735  {
736  struct SmallMapEntry *sme;
737 
738  for (sme = me.sme; NULL != sme; sme = sme->next)
739  if (0 == GNUNET_memcmp(key, sme->key))
740  {
742  return GNUNET_SYSERR;
743  sme->value = value;
744  return GNUNET_NO;
745  }
746  }
747  else
748  {
749  struct BigMapEntry *bme;
750 
751  for (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.
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 280 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(), GAS_mlp_solve_problem(), 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(), libgnunet_plugin_ats2_simple_done(), 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().

282 {
283  return map->size;
284 }
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 331 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_mlp_solve_problem(), 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_application_done(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), GNUNET_ATS_transport_done(), 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_ats_mlp_done(), 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(), mlp_create_problem(), mlp_create_problem_count_addresses(), mlp_create_problem_count_peers(), mlp_delete_problem(), 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(), update_connect_preferences(), update_flood_message(), update_preference(), and utilization_transmission().

335 {
336  int count;
337  union MapEntry me;
338  union MapEntry *ce;
339  struct GNUNET_PeerIdentity kc;
340 
341  count = 0;
342  GNUNET_assert(NULL != map);
343  ce = &map->next_cache[map->next_cache_off];
345  for (unsigned int i = 0; i < map->map_length; i++)
346  {
347  me = map->map[i];
348  if (map->use_small_entries)
349  {
350  struct SmallMapEntry *sme;
351 
352  ce->sme = me.sme;
353  while (NULL != (sme = ce->sme))
354  {
355  ce->sme = sme->next;
356  if (NULL != it)
357  {
358  if (GNUNET_OK != it(it_cls, sme->key, sme->value))
359  {
361  return GNUNET_SYSERR;
362  }
363  }
364  count++;
365  }
366  }
367  else
368  {
369  struct BigMapEntry *bme;
370 
371  ce->bme = me.bme;
372  while (NULL != (bme = ce->bme))
373  {
374  ce->bme = bme->next;
375  if (NULL != it)
376  {
377  kc = bme->key;
378  if (GNUNET_OK != it(it_cls, &kc, bme->value))
379  {
381  return GNUNET_SYSERR;
382  }
383  }
384  count++;
385  }
386  }
387  }
389  return count;
390 }
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 940 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.

942 {
944 
946  iter->map = map;
948  iter->me = map->map[0];
949  return iter;
950 }
#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 968 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.

972 {
973  /* make sure the map has not been modified */
975 
976  /* look for the next entry, skipping empty buckets */
977  while (1)
978  {
979  if (iter->idx >= iter->map->map_length)
980  return GNUNET_NO;
981  if (GNUNET_YES == iter->map->use_small_entries)
982  {
983  if (NULL != iter->me.sme)
984  {
985  if (NULL != key)
986  *key = *iter->me.sme->key;
987  if (NULL != value)
988  *value = iter->me.sme->value;
989  iter->me.sme = iter->me.sme->next;
990  return GNUNET_YES;
991  }
992  }
993  else
994  {
995  if (NULL != iter->me.bme)
996  {
997  if (NULL != key)
998  *key = iter->me.bme->key;
999  if (NULL != value)
1000  *value = iter->me.bme->value;
1001  iter->me.bme = iter->me.bme->next;
1002  return GNUNET_YES;
1003  }
1004  }
1005  iter->idx += 1;
1006  if (iter->idx < iter->map->map_length)
1007  iter->me = iter->map->map[iter->idx];
1008  }
1009 }
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 1018 of file container_multipeermap.c.

References GNUNET_free.

1020 {
1021  GNUNET_free(iter);
1022 }
#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 802 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_session(), find_validation_entry(), GAS_addresses_get_peer_info(), GAS_handle_request_address_cancel(), GAS_mlp_address_delete(), GAS_mlp_get_preferred_address(), 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().

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

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  struct SmallMapEntry *sme;
888  struct SmallMapEntry *nxt;
889 
890  nxt = me.sme;
891  while (NULL != (sme = nxt))
892  {
893  nxt = sme->next;
894  if (0 == off)
895  {
896  if (GNUNET_OK != it(it_cls, sme->key, sme->value))
897  return GNUNET_SYSERR;
898  return 1;
899  }
900  off--;
901  }
902  }
903  else
904  {
905  struct BigMapEntry *bme;
906  struct BigMapEntry *nxt;
907 
908  nxt = me.bme;
909  while (NULL != (bme = nxt))
910  {
911  nxt = bme->next;
912  if (0 == off)
913  {
914  if (GNUNET_OK != it(it_cls, &bme->key, bme->value))
915  return GNUNET_SYSERR;
916  return 1;
917  }
918  off--;
919  }
920  }
921  }
922  GNUNET_break(0);
923  return GNUNET_SYSERR;
924 }
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 189 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().

190 {
192 
193  GNUNET_assert(len > 0);
195  map->map = GNUNET_malloc_large(len * sizeof(union MapEntry));
196  if (NULL == map->map)
197  {
198  GNUNET_free(map);
199  return NULL;
200  }
201  map->map_length = len;
202  map->use_small_entries = do_not_copy_keys;
203  return map;
204 }
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 214 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().

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

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

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

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

593 {
594  union MapEntry me;
595 
596  me = map->map[idx_of(map, key)];
597  if (map->use_small_entries)
598  {
599  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
600  if (0 == GNUNET_memcmp(key, sme->key))
601  return GNUNET_YES;
602  }
603  else
604  {
605  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
606  if (0 == GNUNET_memcmp(key, &bme->key))
607  return GNUNET_YES;
608  }
609  return GNUNET_NO;
610 }
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 624 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.

628 {
629  union MapEntry me;
630 
631  me = map->map[idx_of(map, key)];
632  if (map->use_small_entries)
633  {
634  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
635  if ((0 == GNUNET_memcmp(key, sme->key)) && (sme->value == value))
636  return GNUNET_YES;
637  }
638  else
639  {
640  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
641  if ((0 == GNUNET_memcmp(key, &bme->key)) && (bme->value == value))
642  return GNUNET_YES;
643  }
644  return GNUNET_NO;
645 }
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 719 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().

724 {
725  union MapEntry me;
726  unsigned int i;
727 
728  i = idx_of(map, key);
731  {
732  me = map->map[i];
733  if (map->use_small_entries)
734  {
735  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
736  if (0 == GNUNET_memcmp(key, sme->key))
737  {
739  return GNUNET_SYSERR;
740  sme->value = value;
741  return GNUNET_NO;
742  }
743  }
744  else
745  {
746  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
747  if (0 == GNUNET_memcmp(key, &bme->key))
748  {
750  return GNUNET_SYSERR;
751  bme->value = value;
752  return GNUNET_NO;
753  }
754  }
755  }
756  if (map->size / 3 >= map->map_length / 4)
757  {
758  grow(map);
759  i = idx_of(map, key);
760  }
761  if (map->use_small_entries)
762  {
763  struct SmallMapEntry *sme;
764 
765  sme = GNUNET_new(struct SmallMapEntry);
766  sme->key = key;
767  sme->value = value;
768  sme->next = map->map[i].sme;
769  map->map[i].sme = sme;
770  }
771  else
772  {
773  struct BigMapEntry *bme;
774 
775  bme = GNUNET_new(struct BigMapEntry);
776  bme->key = *key;
777  bme->value = value;
778  bme->next = map->map[i].bme;
779  map->map[i].bme = bme;
780  }
781  map->size++;
782  return GNUNET_OK;
783 }
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 281 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().

283 {
284  return map->size;
285 }
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 332 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.

336 {
337  int count;
338  union MapEntry me;
339  union MapEntry *ce;
340  struct GNUNET_ShortHashCode kc;
341 
342  count = 0;
343  GNUNET_assert(NULL != map);
344  ce = &map->next_cache[map->next_cache_off];
346  for (unsigned int i = 0; i < map->map_length; i++)
347  {
348  me = map->map[i];
349  if (map->use_small_entries)
350  {
351  struct SmallMapEntry *sme;
352 
353  ce->sme = me.sme;
354  while (NULL != (sme = ce->sme))
355  {
356  ce->sme = sme->next;
357  if ((NULL != it) && (GNUNET_OK != it(it_cls, sme->key, sme->value)))
358  {
360  return GNUNET_SYSERR;
361  }
362  count++;
363  }
364  }
365  else
366  {
367  struct BigMapEntry *bme;
368 
369  ce->bme = me.bme;
370  while (NULL != (bme = ce->bme))
371  {
372  ce->bme = bme->next;
373  if (NULL != it)
374  {
375  kc = bme->key;
376  if (GNUNET_OK != it(it_cls, &kc, bme->value))
377  {
379  return GNUNET_SYSERR;
380  }
381  }
382  count++;
383  }
384  }
385  }
387  return count;
388 }
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 925 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.

927 {
929 
931  iter->map = map;
933  iter->me = map->map[0];
934  return iter;
935 }
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 953 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.

957 {
958  /* make sure the map has not been modified */
960 
961  /* look for the next entry, skipping empty buckets */
962  while (1)
963  {
964  if (iter->idx >= iter->map->map_length)
965  return GNUNET_NO;
966  if (GNUNET_YES == iter->map->use_small_entries)
967  {
968  if (NULL != iter->me.sme)
969  {
970  if (NULL != key)
971  *key = *iter->me.sme->key;
972  if (NULL != value)
973  *value = iter->me.sme->value;
974  iter->me.sme = iter->me.sme->next;
975  return GNUNET_YES;
976  }
977  }
978  else
979  {
980  if (NULL != iter->me.bme)
981  {
982  if (NULL != key)
983  *key = iter->me.bme->key;
984  if (NULL != value)
985  *value = iter->me.bme->value;
986  iter->me.bme = iter->me.bme->next;
987  return GNUNET_YES;
988  }
989  }
990  iter->idx += 1;
991  if (iter->idx < iter->map->map_length)
992  iter->me = iter->map->map[iter->idx];
993  }
994 }
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 1003 of file container_multishortmap.c.

References GNUNET_free.

1005 {
1006  GNUNET_free(iter);
1007 }
#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 797 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.

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

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