#include "platform.h"
#include "gnunet_container_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-container-multihashmap", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-multihashmap", __VA_ARGS__)
/**
* Maximum recursion depth for callbacks of
* Key for the entry.
*/
struct GNUNET_HashCode key;
-
};
* Key for the entry.
*/
const struct GNUNET_HashCode *key;
-
};
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiHashMap *
-GNUNET_CONTAINER_multihashmap_create (unsigned int len,
- int do_not_copy_keys)
+GNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys)
{
struct GNUNET_CONTAINER_MultiHashMap *hm;
/* application *explicitly* requested very large map, hopefully
it checks the return value... */
s = len * sizeof (union MapEntry);
- if ( (s / sizeof (union MapEntry)) != len)
+ if ((s / sizeof (union MapEntry)) != len)
return NULL; /* integer overflow on multiplication */
if (NULL == (hm->map = GNUNET_malloc_large (s)))
{
}
else
{
- hm->map = GNUNET_new_array (len,
- union MapEntry);
+ hm->map = GNUNET_new_array (len, union MapEntry);
}
hm->map_length = len;
hm->use_small_entries = do_not_copy_keys;
* @param map the map
*/
void
-GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map)
+GNUNET_CONTAINER_multihashmap_destroy (
+ struct GNUNET_CONTAINER_MultiHashMap *map)
{
GNUNET_assert (0 == map->next_cache_off);
for (unsigned int i = 0; i < map->map_length; i++)
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map)
+GNUNET_CONTAINER_multihashmap_size (
+ const struct GNUNET_CONTAINER_MultiHashMap *map)
{
return map->size;
}
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key)
+GNUNET_CONTAINER_multihashmap_get (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key)
{
union MapEntry me;
struct SmallMapEntry *sme;
for (sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_HashCode)))
- return sme->value;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return sme->value;
}
else
{
struct BigMapEntry *bme;
for (bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_HashCode)))
- return bme->value;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return bme->value;
}
return NULL;
}
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multihashmap_iterate (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls)
{
int count;
union MapEntry me;
ce->sme = me.sme;
while (NULL != (sme = ce->sme))
{
- ce->sme = sme->next;
- if (NULL != it)
- {
- if (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value))
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ ce->sme = sme->next;
+ if (NULL != it)
+ {
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
}
}
else
ce->bme = me.bme;
while (NULL != (bme = ce->bme))
{
- ce->bme = bme->next;
- if (NULL != it)
- {
- kc = bme->key;
- if (GNUNET_OK != it (it_cls,
- &kc,
- bme->value))
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ ce->bme = bme->next;
+ if (NULL != it)
+ {
+ kc = bme->key;
+ if (GNUNET_OK != it (it_cls, &kc, bme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
}
}
}
*/
static void
update_next_cache_bme (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct BigMapEntry *bme)
+ const struct BigMapEntry *bme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].bme == bme)
map->next_cache[i].bme = bme->next;
}
*/
static void
update_next_cache_sme (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct SmallMapEntry *sme)
+ const struct SmallMapEntry *sme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].sme == sme)
map->next_cache[i].sme = sme->next;
}
int
GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
const struct GNUNET_HashCode *key,
- const void *value)
+ const void *value)
{
union MapEntry me;
unsigned int i;
p = NULL;
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
{
- if ( (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_HashCode))) &&
- (value == sme->value) )
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ return GNUNET_YES;
}
p = sme;
}
p = NULL;
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
{
- if ( (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_HashCode))) &&
- (value == bme->value) )
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ return GNUNET_YES;
}
p = bme;
}
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key)
+GNUNET_CONTAINER_multihashmap_remove_all (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key)
{
union MapEntry me;
unsigned int i;
sme = me.sme;
while (NULL != sme)
{
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_HashCode)))
+ if (0 == GNUNET_memcmp (key, sme->key))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- if (NULL == p)
- sme = map->map[i].sme;
- else
- sme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ if (NULL == p)
+ sme = map->map[i].sme;
+ else
+ sme = p->next;
+ ret++;
}
else
{
- p = sme;
- sme = sme->next;
+ p = sme;
+ sme = sme->next;
}
}
}
bme = me.bme;
while (NULL != bme)
{
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_HashCode)))
+ if (0 == GNUNET_memcmp (key, &bme->key))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- if (NULL == p)
- bme = map->map[i].bme;
- else
- bme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ if (NULL == p)
+ bme = map->map[i].bme;
+ else
+ bme = p->next;
+ ret++;
}
else
{
- p = bme;
- bme = bme->next;
+ p = bme;
+ bme = bme->next;
}
}
}
* @return #GNUNET_OK (continue to iterate)
*/
static int
-remove_all (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+remove_all (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_CONTAINER_MultiHashMap *map = cls;
- GNUNET_CONTAINER_multihashmap_remove (map,
- key,
- value);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (map, key, value));
return GNUNET_OK;
}
unsigned int ret;
ret = map->size;
- GNUNET_CONTAINER_multihashmap_iterate (map,
- &remove_all,
- map);
+ GNUNET_CONTAINER_multihashmap_iterate (map, &remove_all, map);
return ret;
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap_contains (const struct
- GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key)
+GNUNET_CONTAINER_multihashmap_contains (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key)
{
union MapEntry me;
struct SmallMapEntry *sme;
for (sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_HashCode)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return GNUNET_YES;
}
else
{
struct BigMapEntry *bme;
for (bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_HashCode)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key,
- const void *value)
+GNUNET_CONTAINER_multihashmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key,
+ const void *value)
{
union MapEntry me;
struct SmallMapEntry *sme;
for (sme = me.sme; NULL != sme; sme = sme->next)
- if ( (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_HashCode))) &&
- (sme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
+ return GNUNET_YES;
}
else
{
struct BigMapEntry *bme;
for (bme = me.bme; NULL != bme; bme = bme->next)
- if ( (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_HashCode))) &&
- (bme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
new_len = old_len; /* never use 0 */
if (new_len == old_len)
return; /* nothing changed */
- new_map = GNUNET_malloc_large (new_len *
- sizeof (union MapEntry));
+ new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry));
if (NULL == new_map)
return; /* grow not possible */
map->modification_counter++;
while (NULL != (sme = old_map[i].sme))
{
- old_map[i].sme = sme->next;
- idx = idx_of (map, sme->key);
- sme->next = new_map[idx].sme;
- new_map[idx].sme = sme;
+ old_map[i].sme = sme->next;
+ idx = idx_of (map, sme->key);
+ sme->next = new_map[idx].sme;
+ new_map[idx].sme = sme;
}
}
else
while (NULL != (bme = old_map[i].bme))
{
- old_map[i].bme = bme->next;
- idx = idx_of (map, &bme->key);
- bme->next = new_map[idx].bme;
- new_map[idx].bme = bme;
+ old_map[i].bme = bme->next;
+ idx = idx_of (map, &bme->key);
+ bme->next = new_map[idx].bme;
+ new_map[idx].bme = bme;
}
}
}
int
GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
const struct GNUNET_HashCode *key,
- void *value,
+ void *value,
enum GNUNET_CONTAINER_MultiHashMapOption opt)
{
union MapEntry me;
struct SmallMapEntry *sme;
for (sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_HashCode)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- sme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, sme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ sme->value = value;
+ return GNUNET_NO;
+ }
}
else
{
struct BigMapEntry *bme;
for (bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_HashCode)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- bme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ bme->value = value;
+ return GNUNET_NO;
+ }
}
}
if (map->size / 3 >= map->map_length / 4)
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multihashmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls)
{
int count;
union MapEntry *me;
while (NULL != (sme = ce->sme))
{
ce->sme = sme->next;
- if (0 != memcmp (key,
- sme->key,
- sizeof (struct GNUNET_HashCode)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- sme->value)))
+ if (0 != GNUNET_memcmp (key, sme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
while (NULL != (bme = ce->bme))
{
ce->bme = bme->next;
- if (0 != memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_HashCode)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- bme->value)))
+ if (0 != GNUNET_memcmp (key, &bme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multihashmap_get_random (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls)
{
unsigned int off;
unsigned int idx;
return 0;
if (NULL == it)
return 1;
- off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- map->size);
+ off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size);
for (idx = 0; idx < map->map_length; idx++)
{
me = map->map[idx];
nxt = sme->next;
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value))
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
return GNUNET_SYSERR;
return 1;
}
nxt = bme->next;
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- &bme->key, bme->value))
+ if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
return GNUNET_SYSERR;
return 1;
}
* @return an iterator over the given multihashmap 'map'
*/
struct GNUNET_CONTAINER_MultiHashMapIterator *
-GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map)
+GNUNET_CONTAINER_multihashmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiHashMap *map)
{
struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
- struct GNUNET_HashCode *key,
- const void **value)
+GNUNET_CONTAINER_multihashmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
+ struct GNUNET_HashCode *key,
+ const void **value)
{
/* make sure the map has not been modified */
GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
+GNUNET_CONTAINER_multihashmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
{
GNUNET_free (iter);
}
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-container-multipeermap", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-multipeermap", __VA_ARGS__)
/**
* Maximum recursion depth for callbacks of
* Key for the entry.
*/
struct GNUNET_PeerIdentity key;
-
};
* Key for the entry.
*/
const struct GNUNET_PeerIdentity *key;
-
};
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiPeerMap *
-GNUNET_CONTAINER_multipeermap_create (unsigned int len,
- int do_not_copy_keys)
+GNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys)
{
struct GNUNET_CONTAINER_MultiPeerMap *map;
GNUNET_assert (len > 0);
map = GNUNET_new (struct GNUNET_CONTAINER_MultiPeerMap);
- map->map = GNUNET_malloc_large (len *
- sizeof (union MapEntry));
+ map->map = GNUNET_malloc_large (len * sizeof (union MapEntry));
if (NULL == map->map)
{
GNUNET_free (map);
* @param map the map
*/
void
-GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map)
+GNUNET_CONTAINER_multipeermap_destroy (
+ struct GNUNET_CONTAINER_MultiPeerMap *map)
{
GNUNET_assert (0 == map->next_cache_off);
for (unsigned int i = 0; i < map->map_length; i++)
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
unsigned int kx;
GNUNET_assert (NULL != map);
- GNUNET_memcpy (&kx,
- key,
- sizeof (kx));
+ GNUNET_memcpy (&kx, key, sizeof (kx));
return kx % map->map_length;
}
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map)
+GNUNET_CONTAINER_multipeermap_size (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map)
{
return map->size;
}
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key)
+GNUNET_CONTAINER_multipeermap_get (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_PeerIdentity)))
- return sme->value;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return sme->value;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_PeerIdentity)))
- return bme->value;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return bme->value;
}
return NULL;
}
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multipeermap_iterate (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls)
{
int count;
union MapEntry me;
ce->sme = me.sme;
while (NULL != (sme = ce->sme))
{
- ce->sme = sme->next;
- if (NULL != it)
- {
- if (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value))
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ ce->sme = sme->next;
+ if (NULL != it)
+ {
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
}
}
else
ce->bme = me.bme;
while (NULL != (bme = ce->bme))
{
- ce->bme = bme->next;
- if (NULL != it)
- {
- kc = bme->key;
- if (GNUNET_OK != it (it_cls,
- &kc,
- bme->value))
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ ce->bme = bme->next;
+ if (NULL != it)
+ {
+ kc = bme->key;
+ if (GNUNET_OK != it (it_cls, &kc, bme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
}
}
}
*/
static void
update_next_cache_bme (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct BigMapEntry *bme)
+ const struct BigMapEntry *bme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].bme == bme)
map->next_cache[i].bme = bme->next;
}
*/
static void
update_next_cache_sme (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct SmallMapEntry *sme)
+ const struct SmallMapEntry *sme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].sme == sme)
map->next_cache[i].sme = sme->next;
}
int
GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
const struct GNUNET_PeerIdentity *key,
- const void *value)
+ const void *value)
{
union MapEntry me;
unsigned int i;
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
{
- if ((0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity))) &&
- (value == sme->value))
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ return GNUNET_YES;
}
p = sme;
}
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
{
- if ((0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_PeerIdentity))) &&
- (value == bme->value))
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ return GNUNET_YES;
}
p = bme;
}
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key)
+GNUNET_CONTAINER_multipeermap_remove_all (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key)
{
union MapEntry me;
unsigned int i;
sme = me.sme;
while (NULL != sme)
{
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (key, sme->key))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- if (NULL == p)
- sme = map->map[i].sme;
- else
- sme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ if (NULL == p)
+ sme = map->map[i].sme;
+ else
+ sme = p->next;
+ ret++;
}
else
{
- p = sme;
- sme = sme->next;
+ p = sme;
+ sme = sme->next;
}
}
}
bme = me.bme;
while (NULL != bme)
{
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (key, &bme->key))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- if (NULL == p)
- bme = map->map[i].bme;
- else
- bme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ if (NULL == p)
+ bme = map->map[i].bme;
+ else
+ bme = p->next;
+ ret++;
}
else
{
- p = bme;
- bme = bme->next;
+ p = bme;
+ bme = bme->next;
}
}
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key)
+GNUNET_CONTAINER_multipeermap_contains (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return GNUNET_YES;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key,
- const void *value)
+GNUNET_CONTAINER_multipeermap_contains_value (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key,
+ const void *value)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if ( (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_PeerIdentity))) &&
- (sme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
+ return GNUNET_YES;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if ( (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_PeerIdentity))) &&
- (bme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
new_len = old_len; /* never use 0 */
if (new_len == old_len)
return; /* nothing changed */
- new_map = GNUNET_malloc_large (new_len *
- sizeof (union MapEntry));
+ new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry));
if (NULL == new_map)
return; /* grow not possible */
map->modification_counter++;
while (NULL != (sme = old_map[i].sme))
{
- old_map[i].sme = sme->next;
- idx = idx_of (map, sme->key);
- sme->next = new_map[idx].sme;
- new_map[idx].sme = sme;
+ old_map[i].sme = sme->next;
+ idx = idx_of (map, sme->key);
+ sme->next = new_map[idx].sme;
+ new_map[idx].sme = sme;
}
}
else
while (NULL != (bme = old_map[i].bme))
{
- old_map[i].bme = bme->next;
- idx = idx_of (map, &bme->key);
- bme->next = new_map[idx].bme;
- new_map[idx].bme = bme;
+ old_map[i].bme = bme->next;
+ idx = idx_of (map, &bme->key);
+ bme->next = new_map[idx].bme;
+ new_map[idx].bme = bme;
}
}
}
int
GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
const struct GNUNET_PeerIdentity *key,
- void *value,
+ void *value,
enum GNUNET_CONTAINER_MultiHashMapOption opt)
{
union MapEntry me;
struct SmallMapEntry *sme;
for (sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_PeerIdentity)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- sme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, sme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ sme->value = value;
+ return GNUNET_NO;
+ }
}
else
{
struct BigMapEntry *bme;
for (bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_PeerIdentity)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- bme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ bme->value = value;
+ return GNUNET_NO;
+ }
}
}
if (map->size / 3 >= map->map_length / 4)
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multipeermap_get_multiple (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls)
{
int count;
union MapEntry me;
while (NULL != (sme = ce->sme))
{
ce->sme = sme->next;
- if (0 != memcmp (key,
- sme->key,
- sizeof (struct GNUNET_PeerIdentity)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- sme->value)))
+ if (0 != GNUNET_memcmp (key, sme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
while (NULL != (bme = ce->bme))
{
ce->bme = bme->next;
- if (0 != memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_PeerIdentity)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- bme->value)))
+ if (0 != GNUNET_memcmp (key, &bme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multipeermap_get_random (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls)
{
unsigned int off;
union MapEntry me;
return 0;
if (NULL == it)
return 1;
- off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- map->size);
+ off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size);
for (unsigned int idx = 0; idx < map->map_length; idx++)
{
me = map->map[idx];
nxt = sme->next;
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value))
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
return GNUNET_SYSERR;
return 1;
}
nxt = bme->next;
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- &bme->key,
- bme->value))
- return GNUNET_SYSERR;
- return 1;
+ if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
+ return GNUNET_SYSERR;
+ return 1;
}
off--;
}
* @return an iterator over the given multipeermap 'map'
*/
struct GNUNET_CONTAINER_MultiPeerMapIterator *
-GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map)
+GNUNET_CONTAINER_multipeermap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map)
{
struct GNUNET_CONTAINER_MultiPeerMapIterator *iter;
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
- struct GNUNET_PeerIdentity *key, const void **value)
+GNUNET_CONTAINER_multipeermap_iterator_next (
+ struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
+ struct GNUNET_PeerIdentity *key,
+ const void **value)
{
/* make sure the map has not been modified */
GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter)
+GNUNET_CONTAINER_multipeermap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiPeerMapIterator *iter)
{
GNUNET_free (iter);
}
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-container-multishortmap", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-multishortmap", __VA_ARGS__)
/**
* Maximum recursion depth for callbacks of
* Key for the entry.
*/
struct GNUNET_ShortHashCode key;
-
};
* Key for the entry.
*/
const struct GNUNET_ShortHashCode *key;
-
};
* than #NEXT_CACHE_SIZE.
*/
unsigned int next_cache_off;
-
};
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiShortmap *
-GNUNET_CONTAINER_multishortmap_create (unsigned int len,
- int do_not_copy_keys)
+GNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys)
{
struct GNUNET_CONTAINER_MultiShortmap *map;
GNUNET_assert (len > 0);
map = GNUNET_new (struct GNUNET_CONTAINER_MultiShortmap);
- map->map = GNUNET_malloc_large (len *
- sizeof (union MapEntry));
+ map->map = GNUNET_malloc_large (len * sizeof (union MapEntry));
if (NULL == map->map)
{
GNUNET_free (map);
* @param map the map
*/
void
-GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map)
+GNUNET_CONTAINER_multishortmap_destroy (
+ struct GNUNET_CONTAINER_MultiShortmap *map)
{
GNUNET_assert (0 == map->next_cache_off);
for (unsigned int i = 0; i < map->map_length; i++)
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map)
+GNUNET_CONTAINER_multishortmap_size (
+ const struct GNUNET_CONTAINER_MultiShortmap *map)
{
return map->size;
}
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key)
+GNUNET_CONTAINER_multishortmap_get (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- return sme->value;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return sme->value;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- return bme->value;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return bme->value;
}
return NULL;
}
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multishortmap_iterate (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls)
{
int count;
union MapEntry me;
ce->sme = me.sme;
while (NULL != (sme = ce->sme))
{
- ce->sme = sme->next;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value)) )
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- count++;
+ ce->sme = sme->next;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ count++;
}
}
else
ce->bme = me.bme;
while (NULL != (bme = ce->bme))
{
- ce->bme = bme->next;
- if (NULL != it)
- {
- kc = bme->key;
- if (GNUNET_OK != it (it_cls,
- &kc,
- bme->value))
- {
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ ce->bme = bme->next;
+ if (NULL != it)
+ {
+ kc = bme->key;
+ if (GNUNET_OK != it (it_cls, &kc, bme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
}
}
}
*/
static void
update_next_cache_bme (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct BigMapEntry *bme)
+ const struct BigMapEntry *bme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].bme == bme)
map->next_cache[i].bme = bme->next;
}
*/
static void
update_next_cache_sme (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct SmallMapEntry *sme)
+ const struct SmallMapEntry *sme)
{
- for (unsigned int i=0;i<map->next_cache_off;i++)
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
if (map->next_cache[i].sme == sme)
map->next_cache[i].sme = sme->next;
}
* is not in the map
*/
int
-GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- const void *value)
+GNUNET_CONTAINER_multishortmap_remove (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ const void *value)
{
union MapEntry me;
unsigned int i;
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
{
- if ((0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode))) &&
- (value == sme->value))
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ return GNUNET_YES;
}
p = sme;
}
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
{
- if ((0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode))) &&
- (value == bme->value))
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- return GNUNET_YES;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ return GNUNET_YES;
}
p = bme;
}
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key)
+GNUNET_CONTAINER_multishortmap_remove_all (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key)
{
union MapEntry me;
unsigned int i;
sme = me.sme;
while (NULL != sme)
{
- if (0 == memcmp (key, sme->key, sizeof (struct GNUNET_ShortHashCode)))
+ if (0 == GNUNET_memcmp (key, sme->key))
{
- if (NULL == p)
- map->map[i].sme = sme->next;
- else
- p->next = sme->next;
- update_next_cache_sme (map,
- sme);
- GNUNET_free (sme);
- map->size--;
- if (NULL == p)
- sme = map->map[i].sme;
- else
- sme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ if (NULL == p)
+ sme = map->map[i].sme;
+ else
+ sme = p->next;
+ ret++;
}
else
{
- p = sme;
- sme = sme->next;
+ p = sme;
+ sme = sme->next;
}
}
}
bme = me.bme;
while (NULL != bme)
{
- if (0 == memcmp (key, &bme->key, sizeof (struct GNUNET_ShortHashCode)))
+ if (0 == GNUNET_memcmp (key, &bme->key))
{
- if (NULL == p)
- map->map[i].bme = bme->next;
- else
- p->next = bme->next;
- update_next_cache_bme (map,
- bme);
- GNUNET_free (bme);
- map->size--;
- if (NULL == p)
- bme = map->map[i].bme;
- else
- bme = p->next;
- ret++;
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ if (NULL == p)
+ bme = map->map[i].bme;
+ else
+ bme = p->next;
+ ret++;
}
else
{
- p = bme;
- bme = bme->next;
+ p = bme;
+ bme = bme->next;
}
}
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key)
+GNUNET_CONTAINER_multishortmap_contains (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return GNUNET_YES;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- return GNUNET_YES;
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- const void *value)
+GNUNET_CONTAINER_multishortmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ const void *value)
{
union MapEntry me;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if ( (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode))) &&
- (sme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
+ return GNUNET_YES;
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if ( (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode))) &&
- (bme->value == value) )
- return GNUNET_YES;
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
+ return GNUNET_YES;
}
return GNUNET_NO;
}
new_len = old_len; /* never use 0 */
if (new_len == old_len)
return; /* nothing changed */
- new_map = GNUNET_malloc_large (new_len *
- sizeof (union MapEntry));
+ new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry));
if (NULL == new_map)
return; /* grow not possible */
map->modification_counter++;
while (NULL != (sme = old_map[i].sme))
{
- old_map[i].sme = sme->next;
- idx = idx_of (map, sme->key);
- sme->next = new_map[idx].sme;
- new_map[idx].sme = sme;
+ old_map[i].sme = sme->next;
+ idx = idx_of (map, sme->key);
+ sme->next = new_map[idx].sme;
+ new_map[idx].sme = sme;
}
}
else
while (NULL != (bme = old_map[i].bme))
{
- old_map[i].bme = bme->next;
- idx = idx_of (map, &bme->key);
- bme->next = new_map[idx].bme;
- new_map[idx].bme = bme;
+ old_map[i].bme = bme->next;
+ idx = idx_of (map, &bme->key);
+ bme->next = new_map[idx].bme;
+ new_map[idx].bme = bme;
}
}
}
* value already exists
*/
int
-GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption opt)
+GNUNET_CONTAINER_multishortmap_put (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt)
{
union MapEntry me;
unsigned int i;
if (map->use_small_entries)
{
for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
- if (0 == memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- sme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, sme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ sme->value = value;
+ return GNUNET_NO;
+ }
}
else
{
for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
- if (0 == memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- bme->value = value;
- return GNUNET_NO;
- }
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ bme->value = value;
+ return GNUNET_NO;
+ }
}
}
if (map->size / 3 >= map->map_length / 4)
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multishortmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls)
{
int count;
union MapEntry me;
while (NULL != (sme = ce->sme))
{
ce->sme = sme->next;
- if (0 != memcmp (key,
- sme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- sme->value)) )
+ if (0 != GNUNET_memcmp (key, sme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
while (NULL != (bme = ce->bme))
{
ce->bme = bme->next;
- if (0 != memcmp (key,
- &bme->key,
- sizeof (struct GNUNET_ShortHashCode)))
- continue;
- if ( (NULL != it) &&
- (GNUNET_OK != it (it_cls,
- key,
- bme->value)) )
+ if (0 != GNUNET_memcmp (key, &bme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
{
- GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
- return GNUNET_SYSERR;
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
}
count++;
}
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls)
+GNUNET_CONTAINER_multishortmap_get_random (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls)
{
unsigned int off;
union MapEntry me;
return 0;
if (NULL == it)
return 1;
- off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- map->size);
+ off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size);
for (unsigned int idx = 0; idx < map->map_length; idx++)
{
me = map->map[idx];
{
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- sme->key,
- sme->value))
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
return GNUNET_SYSERR;
return 1;
}
{
if (0 == off)
{
- if (GNUNET_OK != it (it_cls,
- &bme->key, bme->value))
+ if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
return GNUNET_SYSERR;
return 1;
}
* @return an iterator over the given multishortmap 'map'
*/
struct GNUNET_CONTAINER_MultiShortmapIterator *
-GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map)
+GNUNET_CONTAINER_multishortmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiShortmap *map)
{
struct GNUNET_CONTAINER_MultiShortmapIterator *iter;
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
- struct GNUNET_ShortHashCode *key,
- const void **value)
+GNUNET_CONTAINER_multishortmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
+ struct GNUNET_ShortHashCode *key,
+ const void **value)
{
/* make sure the map has not been modified */
GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter)
+GNUNET_CONTAINER_multishortmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiShortmapIterator *iter)
{
GNUNET_free (iter);
}