[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: memcmp -> GNUNET_memcmp
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: memcmp -> GNUNET_memcmp |
Date: |
Tue, 04 Jun 2019 11:53:34 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 9ce956ea4 memcmp -> GNUNET_memcmp
9ce956ea4 is described below
commit 9ce956ea4c93f038995a21c6c1c0133eee6bff75
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jun 4 11:52:52 2019 +0200
memcmp -> GNUNET_memcmp
---
src/util/container_multihashmap.c | 388 +++++++++++++++++--------------------
src/util/container_multipeermap.c | 378 ++++++++++++++++--------------------
src/util/container_multishortmap.c | 384 +++++++++++++++++-------------------
3 files changed, 519 insertions(+), 631 deletions(-)
diff --git a/src/util/container_multihashmap.c
b/src/util/container_multihashmap.c
index 7605ea151..165f04149 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -26,7 +26,8 @@
#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
@@ -57,7 +58,6 @@ struct BigMapEntry
* Key for the entry.
*/
struct GNUNET_HashCode key;
-
};
@@ -81,7 +81,6 @@ struct SmallMapEntry
* Key for the entry.
*/
const struct GNUNET_HashCode *key;
-
};
@@ -194,8 +193,7 @@ struct GNUNET_CONTAINER_MultiHashMapIterator
* @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;
@@ -207,7 +205,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len,
/* 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)))
{
@@ -221,8 +219,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len,
}
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;
@@ -237,7 +234,8 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len,
* @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++)
@@ -253,8 +251,8 @@ GNUNET_CONTAINER_multihashmap_destroy (struct
GNUNET_CONTAINER_MultiHashMap *map
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
@@ -266,8 +264,8 @@ GNUNET_CONTAINER_multihashmap_destroy (struct
GNUNET_CONTAINER_MultiHashMap *map
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
@@ -300,7 +298,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap *map,
* @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;
}
@@ -317,8 +316,9 @@ GNUNET_CONTAINER_multihashmap_size (const struct
GNUNET_CONTAINER_MultiHashMap *
* 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;
@@ -328,20 +328,16 @@ GNUNET_CONTAINER_multihashmap_get (const struct
GNUNET_CONTAINER_MultiHashMap *m
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;
}
@@ -357,9 +353,10 @@ GNUNET_CONTAINER_multihashmap_get (const struct
GNUNET_CONTAINER_MultiHashMap *m
* #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;
@@ -380,18 +377,16 @@ GNUNET_CONTAINER_multihashmap_iterate (struct
GNUNET_CONTAINER_MultiHashMap *map
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
@@ -401,19 +396,17 @@ GNUNET_CONTAINER_multihashmap_iterate (struct
GNUNET_CONTAINER_MultiHashMap *map
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++;
}
}
}
@@ -431,9 +424,9 @@ GNUNET_CONTAINER_multihashmap_iterate (struct
GNUNET_CONTAINER_MultiHashMap *map
*/
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;
}
@@ -448,9 +441,9 @@ update_next_cache_bme (struct GNUNET_CONTAINER_MultiHashMap
*map,
*/
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;
}
@@ -470,7 +463,7 @@ update_next_cache_sme (struct GNUNET_CONTAINER_MultiHashMap
*map,
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;
@@ -486,20 +479,16 @@ GNUNET_CONTAINER_multihashmap_remove (struct
GNUNET_CONTAINER_MultiHashMap *map,
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;
}
@@ -511,20 +500,16 @@ GNUNET_CONTAINER_multihashmap_remove (struct
GNUNET_CONTAINER_MultiHashMap *map,
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;
}
@@ -542,8 +527,9 @@ GNUNET_CONTAINER_multihashmap_remove (struct
GNUNET_CONTAINER_MultiHashMap *map,
* @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;
@@ -563,28 +549,25 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct
GNUNET_CONTAINER_MultiHashMap *
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;
}
}
}
@@ -597,28 +580,25 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct
GNUNET_CONTAINER_MultiHashMap *
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;
}
}
}
@@ -635,15 +615,12 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct
GNUNET_CONTAINER_MultiHashMap *
* @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;
}
@@ -662,9 +639,7 @@ GNUNET_CONTAINER_multihashmap_clear (struct
GNUNET_CONTAINER_MultiHashMap *map)
unsigned int ret;
ret = map->size;
- GNUNET_CONTAINER_multihashmap_iterate (map,
- &remove_all,
- map);
+ GNUNET_CONTAINER_multihashmap_iterate (map, &remove_all, map);
return ret;
}
@@ -679,9 +654,9 @@ GNUNET_CONTAINER_multihashmap_clear (struct
GNUNET_CONTAINER_MultiHashMap *map)
* #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;
@@ -691,16 +666,16 @@ GNUNET_CONTAINER_multihashmap_contains (const struct
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;
}
@@ -717,9 +692,10 @@ GNUNET_CONTAINER_multihashmap_contains (const struct
* #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;
@@ -729,22 +705,16 @@ GNUNET_CONTAINER_multihashmap_contains_value (const
struct GNUNET_CONTAINER_Mult
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;
}
@@ -772,8 +742,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
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++;
@@ -787,10 +756,10 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
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
@@ -799,10 +768,10 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
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;
}
}
}
@@ -825,7 +794,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
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;
@@ -841,26 +810,26 @@ GNUNET_CONTAINER_multihashmap_put (struct
GNUNET_CONTAINER_MultiHashMap *map,
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)
@@ -904,10 +873,11 @@ GNUNET_CONTAINER_multihashmap_put (struct
GNUNET_CONTAINER_MultiHashMap *map,
* #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;
@@ -925,17 +895,12 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct
GNUNET_CONTAINER_MultiHashMap
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++;
}
@@ -948,17 +913,12 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct
GNUNET_CONTAINER_MultiHashMap
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++;
}
@@ -980,9 +940,10 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct
GNUNET_CONTAINER_MultiHashMap
* @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;
@@ -992,8 +953,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct
GNUNET_CONTAINER_MultiHas
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];
@@ -1008,9 +968,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct
GNUNET_CONTAINER_MultiHas
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;
}
@@ -1028,8 +986,7 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct
GNUNET_CONTAINER_MultiHas
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;
}
@@ -1055,7 +1012,8 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct
GNUNET_CONTAINER_MultiHas
* @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;
@@ -1082,9 +1040,10 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const
struct GNUNET_CONTAINER_Mul
* #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);
@@ -1131,7 +1090,8 @@ GNUNET_CONTAINER_multihashmap_iterator_next (struct
GNUNET_CONTAINER_MultiHashMa
* @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);
}
diff --git a/src/util/container_multipeermap.c
b/src/util/container_multipeermap.c
index 613efc0a9..d03221cb5 100644
--- a/src/util/container_multipeermap.c
+++ b/src/util/container_multipeermap.c
@@ -26,7 +26,8 @@
#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
@@ -56,7 +57,6 @@ struct BigMapEntry
* Key for the entry.
*/
struct GNUNET_PeerIdentity key;
-
};
@@ -80,7 +80,6 @@ struct SmallMapEntry
* Key for the entry.
*/
const struct GNUNET_PeerIdentity *key;
-
};
@@ -193,15 +192,13 @@ struct GNUNET_CONTAINER_MultiPeerMapIterator
* @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);
@@ -220,7 +217,8 @@ GNUNET_CONTAINER_multipeermap_create (unsigned int len,
* @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++)
@@ -236,8 +234,8 @@ GNUNET_CONTAINER_multipeermap_destroy (struct
GNUNET_CONTAINER_MultiPeerMap *map
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
@@ -249,8 +247,8 @@ GNUNET_CONTAINER_multipeermap_destroy (struct
GNUNET_CONTAINER_MultiPeerMap *map
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
@@ -274,9 +272,7 @@ idx_of (const struct GNUNET_CONTAINER_MultiPeerMap *map,
unsigned int kx;
GNUNET_assert (NULL != map);
- GNUNET_memcpy (&kx,
- key,
- sizeof (kx));
+ GNUNET_memcpy (&kx, key, sizeof (kx));
return kx % map->map_length;
}
@@ -288,7 +284,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiPeerMap *map,
* @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;
}
@@ -305,8 +302,9 @@ GNUNET_CONTAINER_multipeermap_size (const struct
GNUNET_CONTAINER_MultiPeerMap *
* 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;
@@ -314,18 +312,14 @@ GNUNET_CONTAINER_multipeermap_get (const struct
GNUNET_CONTAINER_MultiPeerMap *m
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;
}
@@ -341,9 +335,10 @@ GNUNET_CONTAINER_multipeermap_get (const struct
GNUNET_CONTAINER_MultiPeerMap *m
* #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;
@@ -364,18 +359,16 @@ GNUNET_CONTAINER_multipeermap_iterate (struct
GNUNET_CONTAINER_MultiPeerMap *map
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
@@ -385,19 +378,17 @@ GNUNET_CONTAINER_multipeermap_iterate (struct
GNUNET_CONTAINER_MultiPeerMap *map
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++;
}
}
}
@@ -415,9 +406,9 @@ GNUNET_CONTAINER_multipeermap_iterate (struct
GNUNET_CONTAINER_MultiPeerMap *map
*/
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;
}
@@ -432,9 +423,9 @@ update_next_cache_bme (struct GNUNET_CONTAINER_MultiPeerMap
*map,
*/
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;
}
@@ -454,7 +445,7 @@ update_next_cache_sme (struct GNUNET_CONTAINER_MultiPeerMap
*map,
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;
@@ -468,18 +459,16 @@ GNUNET_CONTAINER_multipeermap_remove (struct
GNUNET_CONTAINER_MultiPeerMap *map,
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;
}
@@ -490,20 +479,16 @@ GNUNET_CONTAINER_multipeermap_remove (struct
GNUNET_CONTAINER_MultiPeerMap *map,
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;
}
@@ -521,8 +506,9 @@ GNUNET_CONTAINER_multipeermap_remove (struct
GNUNET_CONTAINER_MultiPeerMap *map,
* @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;
@@ -542,28 +528,25 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct
GNUNET_CONTAINER_MultiPeerMap *
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;
}
}
}
@@ -576,28 +559,25 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct
GNUNET_CONTAINER_MultiPeerMap *
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;
}
}
}
@@ -615,8 +595,9 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct
GNUNET_CONTAINER_MultiPeerMap *
* #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;
@@ -624,14 +605,14 @@ GNUNET_CONTAINER_multipeermap_contains (const struct
GNUNET_CONTAINER_MultiPeerM
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;
}
@@ -648,9 +629,10 @@ GNUNET_CONTAINER_multipeermap_contains (const struct
GNUNET_CONTAINER_MultiPeerM
* #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;
@@ -658,20 +640,14 @@ GNUNET_CONTAINER_multipeermap_contains_value (const
struct GNUNET_CONTAINER_Mult
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;
}
@@ -699,8 +675,7 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map)
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++;
@@ -714,10 +689,10 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map)
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
@@ -726,10 +701,10 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map)
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;
}
}
}
@@ -752,7 +727,7 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map)
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;
@@ -768,26 +743,26 @@ GNUNET_CONTAINER_multipeermap_put (struct
GNUNET_CONTAINER_MultiPeerMap *map,
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)
@@ -831,10 +806,11 @@ GNUNET_CONTAINER_multipeermap_put (struct
GNUNET_CONTAINER_MultiPeerMap *map,
* #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;
@@ -852,17 +828,12 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct
GNUNET_CONTAINER_MultiPeerMap
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++;
}
@@ -875,17 +846,12 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct
GNUNET_CONTAINER_MultiPeerMap
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++;
}
@@ -907,9 +873,10 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct
GNUNET_CONTAINER_MultiPeerMap
* @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;
@@ -918,8 +885,7 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct
GNUNET_CONTAINER_MultiPee
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];
@@ -934,9 +900,7 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct
GNUNET_CONTAINER_MultiPee
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;
}
@@ -954,11 +918,9 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct
GNUNET_CONTAINER_MultiPee
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--;
}
@@ -982,7 +944,8 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct
GNUNET_CONTAINER_MultiPee
* @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;
@@ -1009,8 +972,10 @@ GNUNET_CONTAINER_multipeermap_iterator_create (const
struct GNUNET_CONTAINER_Mul
* #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);
@@ -1057,7 +1022,8 @@ GNUNET_CONTAINER_multipeermap_iterator_next (struct
GNUNET_CONTAINER_MultiPeerMa
* @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);
}
diff --git a/src/util/container_multishortmap.c
b/src/util/container_multishortmap.c
index 966e23d35..0371b0a48 100644
--- a/src/util/container_multishortmap.c
+++ b/src/util/container_multishortmap.c
@@ -26,7 +26,8 @@
#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
@@ -57,7 +58,6 @@ struct BigMapEntry
* Key for the entry.
*/
struct GNUNET_ShortHashCode key;
-
};
@@ -81,7 +81,6 @@ struct SmallMapEntry
* Key for the entry.
*/
const struct GNUNET_ShortHashCode *key;
-
};
@@ -146,7 +145,6 @@ struct GNUNET_CONTAINER_MultiShortmap
* than #NEXT_CACHE_SIZE.
*/
unsigned int next_cache_off;
-
};
@@ -195,15 +193,13 @@ struct GNUNET_CONTAINER_MultiShortmapIterator
* @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);
@@ -222,7 +218,8 @@ GNUNET_CONTAINER_multishortmap_create (unsigned int len,
* @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++)
@@ -238,8 +235,8 @@ GNUNET_CONTAINER_multishortmap_destroy (struct
GNUNET_CONTAINER_MultiShortmap *m
nxt = me.sme;
while (NULL != (sme = nxt))
{
- nxt = sme->next;
- GNUNET_free (sme);
+ nxt = sme->next;
+ GNUNET_free (sme);
}
me.sme = NULL;
}
@@ -251,8 +248,8 @@ GNUNET_CONTAINER_multishortmap_destroy (struct
GNUNET_CONTAINER_MultiShortmap *m
nxt = me.bme;
while (NULL != (bme = nxt))
{
- nxt = bme->next;
- GNUNET_free (bme);
+ nxt = bme->next;
+ GNUNET_free (bme);
}
me.bme = NULL;
}
@@ -288,7 +285,8 @@ idx_of (const struct GNUNET_CONTAINER_MultiShortmap *map,
* @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;
}
@@ -305,8 +303,9 @@ GNUNET_CONTAINER_multishortmap_size (const struct
GNUNET_CONTAINER_MultiShortmap
* 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;
@@ -314,18 +313,14 @@ GNUNET_CONTAINER_multishortmap_get (const struct
GNUNET_CONTAINER_MultiShortmap
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;
}
@@ -341,9 +336,10 @@ GNUNET_CONTAINER_multishortmap_get (const struct
GNUNET_CONTAINER_MultiShortmap
* #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;
@@ -364,16 +360,13 @@ GNUNET_CONTAINER_multishortmap_iterate (struct
GNUNET_CONTAINER_MultiShortmap *m
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
@@ -383,19 +376,17 @@ GNUNET_CONTAINER_multishortmap_iterate (struct
GNUNET_CONTAINER_MultiShortmap *m
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++;
}
}
}
@@ -413,9 +404,9 @@ GNUNET_CONTAINER_multishortmap_iterate (struct
GNUNET_CONTAINER_MultiShortmap *m
*/
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;
}
@@ -430,9 +421,9 @@ update_next_cache_bme (struct
GNUNET_CONTAINER_MultiShortmap *map,
*/
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;
}
@@ -450,9 +441,10 @@ update_next_cache_sme (struct
GNUNET_CONTAINER_MultiShortmap *map,
* 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;
@@ -466,20 +458,16 @@ GNUNET_CONTAINER_multishortmap_remove (struct
GNUNET_CONTAINER_MultiShortmap *ma
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;
}
@@ -490,20 +478,16 @@ GNUNET_CONTAINER_multishortmap_remove (struct
GNUNET_CONTAINER_MultiShortmap *ma
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;
}
@@ -521,8 +505,9 @@ GNUNET_CONTAINER_multishortmap_remove (struct
GNUNET_CONTAINER_MultiShortmap *ma
* @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;
@@ -542,26 +527,25 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct
GNUNET_CONTAINER_MultiShortmap
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;
}
}
}
@@ -574,26 +558,25 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct
GNUNET_CONTAINER_MultiShortmap
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;
}
}
}
@@ -611,8 +594,9 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct
GNUNET_CONTAINER_MultiShortmap
* #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;
@@ -620,18 +604,14 @@ GNUNET_CONTAINER_multishortmap_contains (const struct
GNUNET_CONTAINER_MultiShor
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;
}
@@ -648,9 +628,10 @@ GNUNET_CONTAINER_multishortmap_contains (const struct
GNUNET_CONTAINER_MultiShor
* #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;
@@ -658,20 +639,14 @@ GNUNET_CONTAINER_multishortmap_contains_value (const
struct GNUNET_CONTAINER_Mul
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;
}
@@ -698,8 +673,7 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
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++;
@@ -713,10 +687,10 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
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
@@ -725,10 +699,10 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
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;
}
}
}
@@ -749,10 +723,11 @@ grow (struct GNUNET_CONTAINER_MultiShortmap *map)
* 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;
@@ -765,28 +740,24 @@ GNUNET_CONTAINER_multishortmap_put (struct
GNUNET_CONTAINER_MultiShortmap *map,
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)
@@ -830,10 +801,11 @@ GNUNET_CONTAINER_multishortmap_put (struct
GNUNET_CONTAINER_MultiShortmap *map,
* #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;
@@ -851,17 +823,12 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct
GNUNET_CONTAINER_MultiShortm
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++;
}
@@ -874,17 +841,12 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct
GNUNET_CONTAINER_MultiShortm
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++;
}
@@ -906,9 +868,10 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct
GNUNET_CONTAINER_MultiShortm
* @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;
@@ -917,8 +880,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct
GNUNET_CONTAINER_MultiSh
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];
@@ -928,9 +890,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct
GNUNET_CONTAINER_MultiSh
{
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;
}
@@ -943,8 +903,7 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct
GNUNET_CONTAINER_MultiSh
{
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;
}
@@ -970,7 +929,8 @@ GNUNET_CONTAINER_multishortmap_get_random (const struct
GNUNET_CONTAINER_MultiSh
* @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;
@@ -997,9 +957,10 @@ GNUNET_CONTAINER_multishortmap_iterator_create (const
struct GNUNET_CONTAINER_Mu
* #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);
@@ -1046,7 +1007,8 @@ GNUNET_CONTAINER_multishortmap_iterator_next (struct
GNUNET_CONTAINER_MultiShort
* @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);
}
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: memcmp -> GNUNET_memcmp,
gnunet <=