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