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

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

Typedefs

typedef int(* GNUNET_CONTAINER_HashMapIterator) (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_MultiUuidmapIterator) (void *cls, const struct GNUNET_Uuid *key, void *value)
 Iterator over uuid map entries. More...
 
typedef int(* GNUNET_CONTAINER_HashMapIterator32) (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_HashMapIterator 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_HashMapIterator 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_HashMapIterator 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_MultiUuidmapIterator 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_MultiUuidmapIterator 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_MultiUuidmapIterator 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_HashMapIterator32 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_HashMapIterator32 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_HashMapIterator

typedef int(* GNUNET_CONTAINER_HashMapIterator) (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 771 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 1054 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 1333 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiUuidmapIterator

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

◆ GNUNET_CONTAINER_HashMapIterator32

typedef int(* GNUNET_CONTAINER_HashMapIterator32) (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 1912 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 723 of file gnunet_container_lib.h.

724 {
725 
733 
739 
746 
757 };
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 196 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().

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

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

322 {
323  union MapEntry me;
324 
325  me = map->map[idx_of (map, key)];
326  if (map->use_small_entries)
327  {
328  struct SmallMapEntry *sme;
329 
330  for (sme = me.sme; NULL != sme; sme = sme->next)
331  if (0 == GNUNET_memcmp (key, sme->key))
332  return sme->value;
333  }
334  else
335  {
336  struct BigMapEntry *bme;
337 
338  for (bme = me.bme; NULL != bme; bme = bme->next)
339  if (0 == GNUNET_memcmp (key, &bme->key))
340  return bme->value;
341  }
342  return NULL;
343 }
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 464 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().

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

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

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

638 {
639  unsigned int ret;
640 
641  ret = map->size;
643  return ret;
644 }
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 657 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().

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

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

799 {
800  union MapEntry me;
801  unsigned int i;
802 
803  i = idx_of (map, key);
806  {
807  me = map->map[i];
808  if (map->use_small_entries)
809  {
810  struct SmallMapEntry *sme;
811 
812  for (sme = me.sme; NULL != sme; sme = sme->next)
813  if (0 == GNUNET_memcmp (key, sme->key))
814  {
816  return GNUNET_SYSERR;
817  sme->value = value;
818  return GNUNET_NO;
819  }
820  }
821  else
822  {
823  struct BigMapEntry *bme;
824 
825  for (bme = me.bme; NULL != bme; bme = bme->next)
826  if (0 == GNUNET_memcmp (key, &bme->key))
827  {
829  return GNUNET_SYSERR;
830  bme->value = value;
831  return GNUNET_NO;
832  }
833  }
834  }
835  if (map->size / 3 >= map->map_length / 4)
836  {
837  grow (map);
838  i = idx_of (map, key);
839  }
840  if (map->use_small_entries)
841  {
842  struct SmallMapEntry *sme;
843 
844  sme = GNUNET_new (struct SmallMapEntry);
845  sme->key = key;
846  sme->value = value;
847  sme->next = map->map[i].sme;
848  map->map[i].sme = sme;
849  }
850  else
851  {
852  struct BigMapEntry *bme;
853 
854  bme = GNUNET_new (struct BigMapEntry);
855  bme->key = *key;
856  bme->value = value;
857  bme->next = map->map[i].bme;
858  map->map[i].bme = bme;
859  }
860  map->size++;
861  return GNUNET_OK;
862 }
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:81
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
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_HashMapIterator  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 356 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().

360 {
361  int count;
362  union MapEntry me;
363  union MapEntry *ce;
364  struct GNUNET_HashCode kc;
365 
366  GNUNET_assert (NULL != map);
367  ce = &map->next_cache[map->next_cache_off];
369  count = 0;
370  for (unsigned i = 0; i < map->map_length; i++)
371  {
372  me = map->map[i];
373  if (map->use_small_entries)
374  {
375  struct SmallMapEntry *sme;
376 
377  ce->sme = me.sme;
378  while (NULL != (sme = ce->sme))
379  {
380  ce->sme = sme->next;
381  if (NULL != it)
382  {
383  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
384  {
386  return GNUNET_SYSERR;
387  }
388  }
389  count++;
390  }
391  }
392  else
393  {
394  struct BigMapEntry *bme;
395 
396  ce->bme = me.bme;
397  while (NULL != (bme = ce->bme))
398  {
399  ce->bme = bme->next;
400  if (NULL != it)
401  {
402  kc = bme->key;
403  if (GNUNET_OK != it (it_cls, &kc, bme->value))
404  {
406  return GNUNET_SYSERR;
407  }
408  }
409  count++;
410  }
411  }
412  }
414  return count;
415 }
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:78
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:79
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 1015 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().

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

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

1095 {
1096  GNUNET_free (iter);
1097 }
#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_HashMapIterator  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 876 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().

881 {
882  int count;
883  union MapEntry *me;
884  union MapEntry *ce;
885 
886  ce = &map->next_cache[map->next_cache_off];
888  count = 0;
889  me = &map->map[idx_of (map, key)];
890  if (map->use_small_entries)
891  {
892  struct SmallMapEntry *sme;
893 
894  ce->sme = me->sme;
895  while (NULL != (sme = ce->sme))
896  {
897  ce->sme = sme->next;
898  if (0 != GNUNET_memcmp (key, sme->key))
899  continue;
900  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
901  {
903  return GNUNET_SYSERR;
904  }
905  count++;
906  }
907  }
908  else
909  {
910  struct BigMapEntry *bme;
911 
912  ce->bme = me->bme;
913  while (NULL != (bme = ce->bme))
914  {
915  ce->bme = bme->next;
916  if (0 != GNUNET_memcmp (key, &bme->key))
917  continue;
918  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
919  {
921  return GNUNET_SYSERR;
922  }
923  count++;
924  }
925  }
927  return count;
928 }
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:78
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:79
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_HashMapIterator  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 943 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().

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

196 {
198 
199  GNUNET_assert (len > 0);
201  map->map = GNUNET_malloc_large (len * sizeof (union MapEntry));
202  if (NULL == map->map)
203  {
204  GNUNET_free (map);
205  return NULL;
206  }
207  map->map_length = len;
208  map->use_small_entries = do_not_copy_keys;
209  return map;
210 }
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 220 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().

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

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

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

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

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

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

732 {
733  union MapEntry me;
734  unsigned int i;
735 
736  i = idx_of (map, key);
739  {
740  me = map->map[i];
741  if (map->use_small_entries)
742  {
743  struct SmallMapEntry *sme;
744 
745  for (sme = me.sme; NULL != sme; sme = sme->next)
746  if (0 == GNUNET_memcmp (key, sme->key))
747  {
749  return GNUNET_SYSERR;
750  sme->value = value;
751  return GNUNET_NO;
752  }
753  }
754  else
755  {
756  struct BigMapEntry *bme;
757 
758  for (bme = me.bme; NULL != bme; bme = bme->next)
759  if (0 == GNUNET_memcmp (key, &bme->key))
760  {
762  return GNUNET_SYSERR;
763  bme->value = value;
764  return GNUNET_NO;
765  }
766  }
767  }
768  if (map->size / 3 >= map->map_length / 4)
769  {
770  grow (map);
771  i = idx_of (map, key);
772  }
773  if (map->use_small_entries)
774  {
775  struct SmallMapEntry *sme;
776 
777  sme = GNUNET_new (struct SmallMapEntry);
778  sme->key = key;
779  sme->value = value;
780  sme->next = map->map[i].sme;
781  map->map[i].sme = sme;
782  }
783  else
784  {
785  struct BigMapEntry *bme;
786 
787  bme = GNUNET_new (struct BigMapEntry);
788  bme->key = *key;
789  bme->value = value;
790  bme->next = map->map[i].bme;
791  map->map[i].bme = bme;
792  }
793  map->size++;
794  return GNUNET_OK;
795 }
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:81
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
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 287 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().

289 {
290  return map->size;
291 }
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 338 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().

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

949 {
951 
953  iter->map = map;
955  iter->me = map->map[0];
956  return iter;
957 }
#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 975 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.

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

References GNUNET_free.

1027 {
1028  GNUNET_free (iter);
1029 }
#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 809 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().

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

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

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

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

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

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

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

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

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

731 {
732  union MapEntry me;
733  unsigned int i;
734 
735  i = idx_of (map, key);
738  {
739  me = map->map[i];
740  if (map->use_small_entries)
741  {
742  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
743  if (0 == GNUNET_memcmp (key, sme->key))
744  {
746  return GNUNET_SYSERR;
747  sme->value = value;
748  return GNUNET_NO;
749  }
750  }
751  else
752  {
753  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
754  if (0 == GNUNET_memcmp (key, &bme->key))
755  {
757  return GNUNET_SYSERR;
758  bme->value = value;
759  return GNUNET_NO;
760  }
761  }
762  }
763  if (map->size / 3 >= map->map_length / 4)
764  {
765  grow (map);
766  i = idx_of (map, key);
767  }
768  if (map->use_small_entries)
769  {
770  struct SmallMapEntry *sme;
771 
772  sme = GNUNET_new (struct SmallMapEntry);
773  sme->key = key;
774  sme->value = value;
775  sme->next = map->map[i].sme;
776  map->map[i].sme = sme;
777  }
778  else
779  {
780  struct BigMapEntry *bme;
781 
782  bme = GNUNET_new (struct BigMapEntry);
783  bme->key = *key;
784  bme->value = value;
785  bme->next = map->map[i].bme;
786  map->map[i].bme = bme;
787  }
788  map->size++;
789  return GNUNET_OK;
790 }
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:81
void * value
Value of the entry.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
#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 288 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().

290 {
291  return map->size;
292 }
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 339 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.

343 {
344  int count;
345  union MapEntry me;
346  union MapEntry *ce;
347  struct GNUNET_ShortHashCode kc;
348 
349  count = 0;
350  GNUNET_assert (NULL != map);
351  ce = &map->next_cache[map->next_cache_off];
353  for (unsigned int i = 0; i < map->map_length; i++)
354  {
355  me = map->map[i];
356  if (map->use_small_entries)
357  {
358  struct SmallMapEntry *sme;
359 
360  ce->sme = me.sme;
361  while (NULL != (sme = ce->sme))
362  {
363  ce->sme = sme->next;
364  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
365  {
367  return GNUNET_SYSERR;
368  }
369  count++;
370  }
371  }
372  else
373  {
374  struct BigMapEntry *bme;
375 
376  ce->bme = me.bme;
377  while (NULL != (bme = ce->bme))
378  {
379  ce->bme = bme->next;
380  if (NULL != it)
381  {
382  kc = bme->key;
383  if (GNUNET_OK != it (it_cls, &kc, bme->value))
384  {
386  return GNUNET_SYSERR;
387  }
388  }
389  count++;
390  }
391  }
392  }
394  return count;
395 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.
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: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.
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:79
#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 932 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.

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

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

References GNUNET_free.

1012 {
1013  GNUNET_free (iter);
1014 }
#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 804 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.

809 {
810  int count;
811  union MapEntry me;
812  union MapEntry *ce;
813 
814  ce = &map->next_cache[map->next_cache_off];
816  count = 0;
817  me = map->map[idx_of (map, key)];
818  if (map->use_small_entries)
819  {
820  struct SmallMapEntry *sme;
821 
822  ce->sme = me.sme;
823  while (NULL != (sme = ce->sme))
824  {
825  ce->sme = sme->next;
826  if (0 != GNUNET_memcmp (key, sme->key))
827  continue;
828  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
829  {
831  return GNUNET_SYSERR;
832  }
833  count++;
834  }
835  }
836  else
837  {
838  struct BigMapEntry *bme;
839 
840  ce->bme = me.bme;
841  while (NULL != (bme = ce->bme))
842  {
843  ce->bme = bme->next;
844  if (0 != GNUNET_memcmp (key, &bme->key))
845  continue;
846  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
847  {
849  return GNUNET_SYSERR;
850  }
851  count++;
852  }
853  }
855  return count;
856 }
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: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...
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:79
#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 871 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.

875 {
876  unsigned int off;
877  union MapEntry me;
878 
879  if (0 == map->size)
880  return 0;
881  if (NULL == it)
882  return 1;
884  for (unsigned int idx = 0; idx < map->map_length; idx++)
885  {
886  me = map->map[idx];
887  if (map->use_small_entries)
888  {
889  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
890  {
891  if (0 == off)
892  {
893  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
894  return GNUNET_SYSERR;
895  return 1;
896  }
897  off--;
898  }
899  }
900  else
901  {
902  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
903  {
904  if (0 == off)
905  {
906  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
907  return GNUNET_SYSERR;
908  return 1;
909  }
910  off--;
911  }
912  }
913  }
914  GNUNET_break (0);
915  return GNUNET_SYSERR;
916 }
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:78
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:79
An entry in the hash map with just a pointer to the key.
An entry in the hash map with the full key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.
struct GNUNET_HashCode key
Key for the entry.
union MapEntry * map
All of our buckets.
Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_create()

struct GNUNET_CONTAINER_MultiUuidmap* GNUNET_CONTAINER_multiuuidmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

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

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNU