summaryrefslogtreecommitdiff
path: root/src/util/container_multihashmap32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/container_multihashmap32.c')
-rw-r--r--src/util/container_multihashmap32.c333
1 files changed, 164 insertions, 169 deletions
diff --git a/src/util/container_multihashmap32.c b/src/util/container_multihashmap32.c
index 0956ada67..82d908555 100644
--- a/src/util/container_multihashmap32.c
+++ b/src/util/container_multihashmap32.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file util/container_multihashmap32.c 21 * @file util/container_multihashmap32.c
22 * @brief a version of hash map implemented in container_multihashmap.c but with 22 * @brief a version of hash map implemented in container_multihashmap.c but with
@@ -29,7 +29,7 @@
29#include "gnunet_container_lib.h" 29#include "gnunet_container_lib.h"
30 30
31#define LOG(kind, ...) \ 31#define LOG(kind, ...) \
32 GNUNET_log_from (kind, "util-container-multihashmap32", __VA_ARGS__) 32 GNUNET_log_from(kind, "util-container-multihashmap32", __VA_ARGS__)
33 33
34 34
35/** 35/**
@@ -43,9 +43,7 @@
43/** 43/**
44 * An entry in the hash map. 44 * An entry in the hash map.
45 */ 45 */
46struct MapEntry 46struct MapEntry {
47{
48
49 /** 47 /**
50 * Key for the entry. 48 * Key for the entry.
51 */ 49 */
@@ -65,9 +63,7 @@ struct MapEntry
65/** 63/**
66 * Internal representation of the hash map. 64 * Internal representation of the hash map.
67 */ 65 */
68struct GNUNET_CONTAINER_MultiHashMap32 66struct GNUNET_CONTAINER_MultiHashMap32 {
69{
70
71 /** 67 /**
72 * All of our buckets. 68 * All of our buckets.
73 */ 69 */
@@ -108,8 +104,7 @@ struct GNUNET_CONTAINER_MultiHashMap32
108 * Cursor into a multihashmap. 104 * Cursor into a multihashmap.
109 * Allows to enumerate elements asynchronously. 105 * Allows to enumerate elements asynchronously.
110 */ 106 */
111struct GNUNET_CONTAINER_MultiHashMap32Iterator 107struct GNUNET_CONTAINER_MultiHashMap32Iterator {
112{
113 /** 108 /**
114 * Position in the bucket @e idx 109 * Position in the bucket @e idx
115 */ 110 */
@@ -140,18 +135,18 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator
140 * @return NULL on error 135 * @return NULL on error
141 */ 136 */
142struct GNUNET_CONTAINER_MultiHashMap32 * 137struct GNUNET_CONTAINER_MultiHashMap32 *
143GNUNET_CONTAINER_multihashmap32_create (unsigned int len) 138GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
144{ 139{
145 struct GNUNET_CONTAINER_MultiHashMap32 *ret; 140 struct GNUNET_CONTAINER_MultiHashMap32 *ret;
146 141
147 GNUNET_assert (len > 0); 142 GNUNET_assert(len > 0);
148 ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32); 143 ret = GNUNET_new(struct GNUNET_CONTAINER_MultiHashMap32);
149 ret->map = GNUNET_malloc_large (len * sizeof (struct MapEntry *)); 144 ret->map = GNUNET_malloc_large(len * sizeof(struct MapEntry *));
150 if (NULL == ret->map) 145 if (NULL == ret->map)
151 { 146 {
152 GNUNET_free (ret); 147 GNUNET_free(ret);
153 return NULL; 148 return NULL;
154 } 149 }
155 ret->map_length = len; 150 ret->map_length = len;
156 return ret; 151 return ret;
157} 152}
@@ -164,21 +159,21 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
164 * @param map the map 159 * @param map the map
165 */ 160 */
166void 161void
167GNUNET_CONTAINER_multihashmap32_destroy ( 162GNUNET_CONTAINER_multihashmap32_destroy(
168 struct GNUNET_CONTAINER_MultiHashMap32 *map) 163 struct GNUNET_CONTAINER_MultiHashMap32 *map)
169{ 164{
170 struct MapEntry *e; 165 struct MapEntry *e;
171 166
172 for (unsigned int i = 0; i < map->map_length; i++) 167 for (unsigned int i = 0; i < map->map_length; i++)
173 {
174 while (NULL != (e = map->map[i]))
175 { 168 {
176 map->map[i] = e->next; 169 while (NULL != (e = map->map[i]))
177 GNUNET_free (e); 170 {
171 map->map[i] = e->next;
172 GNUNET_free(e);
173 }
178 } 174 }
179 } 175 GNUNET_free(map->map);
180 GNUNET_free (map->map); 176 GNUNET_free(map);
181 GNUNET_free (map);
182} 177}
183 178
184 179
@@ -190,10 +185,10 @@ GNUNET_CONTAINER_multihashmap32_destroy (
190 * @return offset into the "map" array of "m" 185 * @return offset into the "map" array of "m"
191 */ 186 */
192static unsigned int 187static unsigned int
193idx_of (const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key) 188idx_of(const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key)
194{ 189{
195 GNUNET_assert (NULL != m); 190 GNUNET_assert(NULL != m);
196 return ((unsigned int) key) % m->map_length; 191 return ((unsigned int)key) % m->map_length;
197} 192}
198 193
199 194
@@ -204,7 +199,7 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key)
204 * @return the number of key value pairs 199 * @return the number of key value pairs
205 */ 200 */
206unsigned int 201unsigned int
207GNUNET_CONTAINER_multihashmap32_size ( 202GNUNET_CONTAINER_multihashmap32_size(
208 const struct GNUNET_CONTAINER_MultiHashMap32 *map) 203 const struct GNUNET_CONTAINER_MultiHashMap32 *map)
209{ 204{
210 return map->size; 205 return map->size;
@@ -222,19 +217,19 @@ GNUNET_CONTAINER_multihashmap32_size (
222 * key-value pairs with value NULL 217 * key-value pairs with value NULL
223 */ 218 */
224void * 219void *
225GNUNET_CONTAINER_multihashmap32_get ( 220GNUNET_CONTAINER_multihashmap32_get(
226 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 221 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
227 uint32_t key) 222 uint32_t key)
228{ 223{
229 struct MapEntry *e; 224 struct MapEntry *e;
230 225
231 e = map->map[idx_of (map, key)]; 226 e = map->map[idx_of(map, key)];
232 while (NULL != e) 227 while (NULL != e)
233 { 228 {
234 if (key == e->key) 229 if (key == e->key)
235 return e->value; 230 return e->value;
236 e = e->next; 231 e = e->next;
237 } 232 }
238 return NULL; 233 return NULL;
239} 234}
240 235
@@ -249,7 +244,7 @@ GNUNET_CONTAINER_multihashmap32_get (
249 * #GNUNET_SYSERR if it aborted iteration 244 * #GNUNET_SYSERR if it aborted iteration
250 */ 245 */
251int 246int
252GNUNET_CONTAINER_multihashmap32_iterate ( 247GNUNET_CONTAINER_multihashmap32_iterate(
253 struct GNUNET_CONTAINER_MultiHashMap32 *map, 248 struct GNUNET_CONTAINER_MultiHashMap32 *map,
254 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 249 GNUNET_CONTAINER_MulitHashMapIterator32Callback it,
255 void *it_cls) 250 void *it_cls)
@@ -258,29 +253,29 @@ GNUNET_CONTAINER_multihashmap32_iterate (
258 struct MapEntry **ce; 253 struct MapEntry **ce;
259 254
260 count = 0; 255 count = 0;
261 GNUNET_assert (NULL != map); 256 GNUNET_assert(NULL != map);
262 ce = &map->next_cache[map->next_cache_off]; 257 ce = &map->next_cache[map->next_cache_off];
263 GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); 258 GNUNET_assert(++map->next_cache_off < NEXT_CACHE_SIZE);
264 for (unsigned int i = 0; i < map->map_length; i++) 259 for (unsigned int i = 0; i < map->map_length; i++)
265 {
266 struct MapEntry *e;
267
268 *ce = map->map[i];
269 while (NULL != (e = *ce))
270 { 260 {
271 *ce = e->next; 261 struct MapEntry *e;
272 if (NULL != it) 262
273 { 263 *ce = map->map[i];
274 if (GNUNET_OK != it (it_cls, e->key, e->value)) 264 while (NULL != (e = *ce))
275 { 265 {
276 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 266 *ce = e->next;
277 return GNUNET_SYSERR; 267 if (NULL != it)
268 {
269 if (GNUNET_OK != it(it_cls, e->key, e->value))
270 {
271 GNUNET_assert(--map->next_cache_off < NEXT_CACHE_SIZE);
272 return GNUNET_SYSERR;
273 }
274 }
275 count++;
278 } 276 }
279 }
280 count++;
281 } 277 }
282 } 278 GNUNET_assert(--map->next_cache_off < NEXT_CACHE_SIZE);
283 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
284 return count; 279 return count;
285} 280}
286 281
@@ -293,8 +288,8 @@ GNUNET_CONTAINER_multihashmap32_iterate (
293 * @param bme the entry that is about to be free'd 288 * @param bme the entry that is about to be free'd
294 */ 289 */
295static void 290static void
296update_next_cache (struct GNUNET_CONTAINER_MultiHashMap32 *map, 291update_next_cache(struct GNUNET_CONTAINER_MultiHashMap32 *map,
297 const struct MapEntry *me) 292 const struct MapEntry *me)
298{ 293{
299 for (unsigned int i = 0; i < map->next_cache_off; i++) 294 for (unsigned int i = 0; i < map->next_cache_off; i++)
300 if (map->next_cache[i] == me) 295 if (map->next_cache[i] == me)
@@ -314,7 +309,7 @@ update_next_cache (struct GNUNET_CONTAINER_MultiHashMap32 *map,
314 * is not in the map 309 * is not in the map
315 */ 310 */
316int 311int
317GNUNET_CONTAINER_multihashmap32_remove ( 312GNUNET_CONTAINER_multihashmap32_remove(
318 struct GNUNET_CONTAINER_MultiHashMap32 *map, 313 struct GNUNET_CONTAINER_MultiHashMap32 *map,
319 uint32_t key, 314 uint32_t key,
320 const void *value) 315 const void *value)
@@ -325,25 +320,25 @@ GNUNET_CONTAINER_multihashmap32_remove (
325 320
326 map->modification_counter++; 321 map->modification_counter++;
327 322
328 i = idx_of (map, key); 323 i = idx_of(map, key);
329 p = NULL; 324 p = NULL;
330 e = map->map[i]; 325 e = map->map[i];
331 while (e != NULL) 326 while (e != NULL)
332 {
333 if ((key == e->key) && (value == e->value))
334 { 327 {
335 if (p == NULL) 328 if ((key == e->key) && (value == e->value))
336 map->map[i] = e->next; 329 {
337 else 330 if (p == NULL)
338 p->next = e->next; 331 map->map[i] = e->next;
339 update_next_cache (map, e); 332 else
340 GNUNET_free (e); 333 p->next = e->next;
341 map->size--; 334 update_next_cache(map, e);
342 return GNUNET_YES; 335 GNUNET_free(e);
336 map->size--;
337 return GNUNET_YES;
338 }
339 p = e;
340 e = e->next;
343 } 341 }
344 p = e;
345 e = e->next;
346 }
347 return GNUNET_NO; 342 return GNUNET_NO;
348} 343}
349 344
@@ -357,7 +352,7 @@ GNUNET_CONTAINER_multihashmap32_remove (
357 * @return number of values removed 352 * @return number of values removed
358 */ 353 */
359int 354int
360GNUNET_CONTAINER_multihashmap32_remove_all ( 355GNUNET_CONTAINER_multihashmap32_remove_all(
361 struct GNUNET_CONTAINER_MultiHashMap32 *map, 356 struct GNUNET_CONTAINER_MultiHashMap32 *map,
362 uint32_t key) 357 uint32_t key)
363{ 358{
@@ -369,32 +364,32 @@ GNUNET_CONTAINER_multihashmap32_remove_all (
369 map->modification_counter++; 364 map->modification_counter++;
370 365
371 ret = 0; 366 ret = 0;
372 i = idx_of (map, key); 367 i = idx_of(map, key);
373 p = NULL; 368 p = NULL;
374 e = map->map[i]; 369 e = map->map[i];
375 while (e != NULL) 370 while (e != NULL)
376 {
377 if (key == e->key)
378 { 371 {
379 if (p == NULL) 372 if (key == e->key)
380 map->map[i] = e->next; 373 {
381 else 374 if (p == NULL)
382 p->next = e->next; 375 map->map[i] = e->next;
383 update_next_cache (map, e); 376 else
384 GNUNET_free (e); 377 p->next = e->next;
385 map->size--; 378 update_next_cache(map, e);
386 if (p == NULL) 379 GNUNET_free(e);
387 e = map->map[i]; 380 map->size--;
381 if (p == NULL)
382 e = map->map[i];
383 else
384 e = p->next;
385 ret++;
386 }
388 else 387 else
389 e = p->next; 388 {
390 ret++; 389 p = e;
391 } 390 e = e->next;
392 else 391 }
393 {
394 p = e;
395 e = e->next;
396 } 392 }
397 }
398 return ret; 393 return ret;
399} 394}
400 395
@@ -409,19 +404,19 @@ GNUNET_CONTAINER_multihashmap32_remove_all (
409 * #GNUNET_NO if not 404 * #GNUNET_NO if not
410 */ 405 */
411int 406int
412GNUNET_CONTAINER_multihashmap32_contains ( 407GNUNET_CONTAINER_multihashmap32_contains(
413 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 408 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
414 uint32_t key) 409 uint32_t key)
415{ 410{
416 struct MapEntry *e; 411 struct MapEntry *e;
417 412
418 e = map->map[idx_of (map, key)]; 413 e = map->map[idx_of(map, key)];
419 while (e != NULL) 414 while (e != NULL)
420 { 415 {
421 if (key == e->key) 416 if (key == e->key)
422 return GNUNET_YES; 417 return GNUNET_YES;
423 e = e->next; 418 e = e->next;
424 } 419 }
425 return GNUNET_NO; 420 return GNUNET_NO;
426} 421}
427 422
@@ -437,20 +432,20 @@ GNUNET_CONTAINER_multihashmap32_contains (
437 * #GNUNET_NO if not 432 * #GNUNET_NO if not
438 */ 433 */
439int 434int
440GNUNET_CONTAINER_multihashmap32_contains_value ( 435GNUNET_CONTAINER_multihashmap32_contains_value(
441 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 436 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
442 uint32_t key, 437 uint32_t key,
443 const void *value) 438 const void *value)
444{ 439{
445 struct MapEntry *e; 440 struct MapEntry *e;
446 441
447 e = map->map[idx_of (map, key)]; 442 e = map->map[idx_of(map, key)];
448 while (e != NULL) 443 while (e != NULL)
449 { 444 {
450 if ((key == e->key) && (e->value == value)) 445 if ((key == e->key) && (e->value == value))
451 return GNUNET_YES; 446 return GNUNET_YES;
452 e = e->next; 447 e = e->next;
453 } 448 }
454 return GNUNET_NO; 449 return GNUNET_NO;
455} 450}
456 451
@@ -461,7 +456,7 @@ GNUNET_CONTAINER_multihashmap32_contains_value (
461 * @param map the hash map to grow 456 * @param map the hash map to grow
462 */ 457 */
463static void 458static void
464grow (struct GNUNET_CONTAINER_MultiHashMap32 *map) 459grow(struct GNUNET_CONTAINER_MultiHashMap32 *map)
465{ 460{
466 struct MapEntry **old_map; 461 struct MapEntry **old_map;
467 struct MapEntry **new_map; 462 struct MapEntry **new_map;
@@ -477,23 +472,23 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map)
477 new_len = old_len; /* never use 0 */ 472 new_len = old_len; /* never use 0 */
478 if (new_len == old_len) 473 if (new_len == old_len)
479 return; /* nothing changed */ 474 return; /* nothing changed */
480 new_map = GNUNET_malloc_large (new_len * sizeof (struct MapEntry *)); 475 new_map = GNUNET_malloc_large(new_len * sizeof(struct MapEntry *));
481 if (NULL == new_map) 476 if (NULL == new_map)
482 return; /* grow not possible */ 477 return; /* grow not possible */
483 map->modification_counter++; 478 map->modification_counter++;
484 map->map_length = new_len; 479 map->map_length = new_len;
485 map->map = new_map; 480 map->map = new_map;
486 for (unsigned int i = 0; i < old_len; i++) 481 for (unsigned int i = 0; i < old_len; i++)
487 {
488 while (NULL != (e = old_map[i]))
489 { 482 {
490 old_map[i] = e->next; 483 while (NULL != (e = old_map[i]))
491 idx = idx_of (map, e->key); 484 {
492 e->next = new_map[idx]; 485 old_map[i] = e->next;
493 new_map[idx] = e; 486 idx = idx_of(map, e->key);
487 e->next = new_map[idx];
488 new_map[idx] = e;
489 }
494 } 490 }
495 } 491 GNUNET_free(old_map);
496 GNUNET_free (old_map);
497} 492}
498 493
499 494
@@ -510,7 +505,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map)
510 * value already exists 505 * value already exists
511 */ 506 */
512int 507int
513GNUNET_CONTAINER_multihashmap32_put ( 508GNUNET_CONTAINER_multihashmap32_put(
514 struct GNUNET_CONTAINER_MultiHashMap32 *map, 509 struct GNUNET_CONTAINER_MultiHashMap32 *map,
515 uint32_t key, 510 uint32_t key,
516 void *value, 511 void *value,
@@ -519,29 +514,29 @@ GNUNET_CONTAINER_multihashmap32_put (
519 struct MapEntry *e; 514 struct MapEntry *e;
520 unsigned int i; 515 unsigned int i;
521 516
522 i = idx_of (map, key); 517 i = idx_of(map, key);
523 if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && 518 if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) &&
524 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 519 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
525 {
526 e = map->map[i];
527 while (e != NULL)
528 { 520 {
529 if (key == e->key) 521 e = map->map[i];
530 { 522 while (e != NULL)
531 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) 523 {
532 return GNUNET_SYSERR; 524 if (key == e->key)
533 e->value = value; 525 {
534 return GNUNET_NO; 526 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
535 } 527 return GNUNET_SYSERR;
536 e = e->next; 528 e->value = value;
529 return GNUNET_NO;
530 }
531 e = e->next;
532 }
537 } 533 }
538 }
539 if (map->size / 3 >= map->map_length / 4) 534 if (map->size / 3 >= map->map_length / 4)
540 { 535 {
541 grow (map); 536 grow(map);
542 i = idx_of (map, key); 537 i = idx_of(map, key);
543 } 538 }
544 e = GNUNET_new (struct MapEntry); 539 e = GNUNET_new(struct MapEntry);
545 e->key = key; 540 e->key = key;
546 e->value = value; 541 e->value = value;
547 e->next = map->map[i]; 542 e->next = map->map[i];
@@ -562,7 +557,7 @@ GNUNET_CONTAINER_multihashmap32_put (
562 * GNUNET_SYSERR if it aborted iteration 557 * GNUNET_SYSERR if it aborted iteration
563 */ 558 */
564int 559int
565GNUNET_CONTAINER_multihashmap32_get_multiple ( 560GNUNET_CONTAINER_multihashmap32_get_multiple(
566 struct GNUNET_CONTAINER_MultiHashMap32 *map, 561 struct GNUNET_CONTAINER_MultiHashMap32 *map,
567 uint32_t key, 562 uint32_t key,
568 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 563 GNUNET_CONTAINER_MulitHashMapIterator32Callback it,
@@ -574,22 +569,22 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (
574 569
575 count = 0; 570 count = 0;
576 ce = &map->next_cache[map->next_cache_off]; 571 ce = &map->next_cache[map->next_cache_off];
577 GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); 572 GNUNET_assert(++map->next_cache_off < NEXT_CACHE_SIZE);
578 573
579 *ce = map->map[idx_of (map, key)]; 574 *ce = map->map[idx_of(map, key)];
580 while (NULL != (e = *ce)) 575 while (NULL != (e = *ce))
581 {
582 *ce = e->next;
583 if (key != e->key)
584 continue;
585 if ((NULL != it) && (GNUNET_OK != it (it_cls, key, e->value)))
586 { 576 {
587 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); 577 *ce = e->next;
588 return GNUNET_SYSERR; 578 if (key != e->key)
579 continue;
580 if ((NULL != it) && (GNUNET_OK != it(it_cls, key, e->value)))
581 {
582 GNUNET_assert(--map->next_cache_off < NEXT_CACHE_SIZE);
583 return GNUNET_SYSERR;
584 }
585 count++;
589 } 586 }
590 count++; 587 GNUNET_assert(--map->next_cache_off < NEXT_CACHE_SIZE);
591 }
592 GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
593 return count; 588 return count;
594} 589}
595 590
@@ -607,12 +602,12 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (
607 * @return an iterator over the given multihashmap @a map 602 * @return an iterator over the given multihashmap @a map
608 */ 603 */
609struct GNUNET_CONTAINER_MultiHashMap32Iterator * 604struct GNUNET_CONTAINER_MultiHashMap32Iterator *
610GNUNET_CONTAINER_multihashmap32_iterator_create ( 605GNUNET_CONTAINER_multihashmap32_iterator_create(
611 const struct GNUNET_CONTAINER_MultiHashMap32 *map) 606 const struct GNUNET_CONTAINER_MultiHashMap32 *map)
612{ 607{
613 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter; 608 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter;
614 609
615 iter = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32Iterator); 610 iter = GNUNET_new(struct GNUNET_CONTAINER_MultiHashMap32Iterator);
616 iter->map = map; 611 iter->map = map;
617 iter->modification_counter = map->modification_counter; 612 iter->modification_counter = map->modification_counter;
618 iter->me = map->map[0]; 613 iter->me = map->map[0];
@@ -635,32 +630,32 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (
635 * #GNUNET_NO if we are out of elements 630 * #GNUNET_NO if we are out of elements
636 */ 631 */
637int 632int
638GNUNET_CONTAINER_multihashmap32_iterator_next ( 633GNUNET_CONTAINER_multihashmap32_iterator_next(
639 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, 634 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
640 uint32_t *key, 635 uint32_t *key,
641 const void **value) 636 const void **value)
642{ 637{
643 /* make sure the map has not been modified */ 638 /* make sure the map has not been modified */
644 GNUNET_assert (iter->modification_counter == iter->map->modification_counter); 639 GNUNET_assert(iter->modification_counter == iter->map->modification_counter);
645 640
646 /* look for the next entry, skipping empty buckets */ 641 /* look for the next entry, skipping empty buckets */
647 while (1) 642 while (1)
648 {
649 if (iter->idx >= iter->map->map_length)
650 return GNUNET_NO;
651 if (NULL != iter->me)
652 { 643 {
653 if (NULL != key) 644 if (iter->idx >= iter->map->map_length)
654 *key = iter->me->key; 645 return GNUNET_NO;
655 if (NULL != value) 646 if (NULL != iter->me)
656 *value = iter->me->value; 647 {
657 iter->me = iter->me->next; 648 if (NULL != key)
658 return GNUNET_YES; 649 *key = iter->me->key;
650 if (NULL != value)
651 *value = iter->me->value;
652 iter->me = iter->me->next;
653 return GNUNET_YES;
654 }
655 iter->idx += 1;
656 if (iter->idx < iter->map->map_length)
657 iter->me = iter->map->map[iter->idx];
659 } 658 }
660 iter->idx += 1;
661 if (iter->idx < iter->map->map_length)
662 iter->me = iter->map->map[iter->idx];
663 }
664} 659}
665 660
666 661
@@ -670,10 +665,10 @@ GNUNET_CONTAINER_multihashmap32_iterator_next (
670 * @param iter the iterator to destroy 665 * @param iter the iterator to destroy
671 */ 666 */
672void 667void
673GNUNET_CONTAINER_multihashmap32_iterator_destroy ( 668GNUNET_CONTAINER_multihashmap32_iterator_destroy(
674 struct GNUNET_CONTAINER_MultiHashMapIterator *iter) 669 struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
675{ 670{
676 GNUNET_free (iter); 671 GNUNET_free(iter);
677} 672}
678 673
679 674