diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/util/container_multihashmap.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/util/container_multihashmap.c')
-rw-r--r-- | src/util/container_multihashmap.c | 208 |
1 files changed, 104 insertions, 104 deletions
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index 579573bdb..9635af17d 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c | |||
@@ -107,13 +107,13 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap | |||
107 | struct MapEntry *e; | 107 | struct MapEntry *e; |
108 | 108 | ||
109 | for (i = 0; i < map->map_length; i++) | 109 | for (i = 0; i < map->map_length; i++) |
110 | { | ||
111 | while (NULL != (e = map->map[i])) | ||
110 | { | 112 | { |
111 | while (NULL != (e = map->map[i])) | 113 | map->map[i] = e->next; |
112 | { | 114 | GNUNET_free (e); |
113 | map->map[i] = e->next; | ||
114 | GNUNET_free (e); | ||
115 | } | ||
116 | } | 115 | } |
116 | } | ||
117 | GNUNET_free (map->map); | 117 | GNUNET_free (map->map); |
118 | GNUNET_free (map); | 118 | GNUNET_free (map); |
119 | } | 119 | } |
@@ -130,7 +130,7 @@ static unsigned int | |||
130 | idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, | 130 | idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, |
131 | const GNUNET_HashCode * key) | 131 | const GNUNET_HashCode * key) |
132 | { | 132 | { |
133 | GNUNET_assert (m!=NULL); | 133 | GNUNET_assert (m != NULL); |
134 | return (*(unsigned int *) key) % m->map_length; | 134 | return (*(unsigned int *) key) % m->map_length; |
135 | } | 135 | } |
136 | 136 | ||
@@ -167,11 +167,11 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap | |||
167 | 167 | ||
168 | e = map->map[idx_of (map, key)]; | 168 | e = map->map[idx_of (map, key)]; |
169 | while (e != NULL) | 169 | while (e != NULL) |
170 | { | 170 | { |
171 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 171 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
172 | return e->value; | 172 | return e->value; |
173 | e = e->next; | 173 | e = e->next; |
174 | } | 174 | } |
175 | return NULL; | 175 | return NULL; |
176 | } | 176 | } |
177 | 177 | ||
@@ -198,22 +198,22 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct | |||
198 | GNUNET_HashCode kc; | 198 | GNUNET_HashCode kc; |
199 | 199 | ||
200 | count = 0; | 200 | count = 0; |
201 | GNUNET_assert(map != NULL); | 201 | GNUNET_assert (map != NULL); |
202 | for (i = 0; i < map->map_length; i++) | 202 | for (i = 0; i < map->map_length; i++) |
203 | { | ||
204 | n = map->map[i]; | ||
205 | while (NULL != (e = n)) | ||
203 | { | 206 | { |
204 | n = map->map[i]; | 207 | n = e->next; |
205 | while (NULL != (e = n)) | 208 | if (NULL != it) |
206 | { | 209 | { |
207 | n = e->next; | 210 | kc = e->key; |
208 | if (NULL != it) | 211 | if (GNUNET_OK != it (it_cls, &kc, e->value)) |
209 | { | 212 | return GNUNET_SYSERR; |
210 | kc = e->key; | 213 | } |
211 | if (GNUNET_OK != it (it_cls, &kc, e->value)) | 214 | count++; |
212 | return GNUNET_SYSERR; | ||
213 | } | ||
214 | count++; | ||
215 | } | ||
216 | } | 215 | } |
216 | } | ||
217 | return count; | 217 | return count; |
218 | } | 218 | } |
219 | 219 | ||
@@ -242,21 +242,21 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap | |||
242 | p = NULL; | 242 | p = NULL; |
243 | e = map->map[i]; | 243 | e = map->map[i]; |
244 | while (e != NULL) | 244 | while (e != NULL) |
245 | { | ||
246 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | ||
247 | (value == e->value)) | ||
245 | { | 248 | { |
246 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | 249 | if (p == NULL) |
247 | (value == e->value)) | 250 | map->map[i] = e->next; |
248 | { | 251 | else |
249 | if (p == NULL) | 252 | p->next = e->next; |
250 | map->map[i] = e->next; | 253 | GNUNET_free (e); |
251 | else | 254 | map->size--; |
252 | p->next = e->next; | 255 | return GNUNET_YES; |
253 | GNUNET_free (e); | ||
254 | map->size--; | ||
255 | return GNUNET_YES; | ||
256 | } | ||
257 | p = e; | ||
258 | e = e->next; | ||
259 | } | 256 | } |
257 | p = e; | ||
258 | e = e->next; | ||
259 | } | ||
260 | return GNUNET_NO; | 260 | return GNUNET_NO; |
261 | } | 261 | } |
262 | 262 | ||
@@ -283,27 +283,27 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | |||
283 | p = NULL; | 283 | p = NULL; |
284 | e = map->map[i]; | 284 | e = map->map[i]; |
285 | while (e != NULL) | 285 | while (e != NULL) |
286 | { | ||
287 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | ||
286 | { | 288 | { |
287 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 289 | if (p == NULL) |
288 | { | 290 | map->map[i] = e->next; |
289 | if (p == NULL) | ||
290 | map->map[i] = e->next; | ||
291 | else | ||
292 | p->next = e->next; | ||
293 | GNUNET_free (e); | ||
294 | map->size--; | ||
295 | if (p == NULL) | ||
296 | e = map->map[i]; | ||
297 | else | ||
298 | e = p->next; | ||
299 | ret++; | ||
300 | } | ||
301 | else | 291 | else |
302 | { | 292 | p->next = e->next; |
303 | p = e; | 293 | GNUNET_free (e); |
304 | e = e->next; | 294 | map->size--; |
305 | } | 295 | if (p == NULL) |
296 | e = map->map[i]; | ||
297 | else | ||
298 | e = p->next; | ||
299 | ret++; | ||
300 | } | ||
301 | else | ||
302 | { | ||
303 | p = e; | ||
304 | e = e->next; | ||
306 | } | 305 | } |
306 | } | ||
307 | return ret; | 307 | return ret; |
308 | } | 308 | } |
309 | 309 | ||
@@ -326,11 +326,11 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
326 | 326 | ||
327 | e = map->map[idx_of (map, key)]; | 327 | e = map->map[idx_of (map, key)]; |
328 | while (e != NULL) | 328 | while (e != NULL) |
329 | { | 329 | { |
330 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 330 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
331 | return GNUNET_YES; | 331 | return GNUNET_YES; |
332 | e = e->next; | 332 | e = e->next; |
333 | } | 333 | } |
334 | return GNUNET_NO; | 334 | return GNUNET_NO; |
335 | } | 335 | } |
336 | 336 | ||
@@ -345,22 +345,23 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
345 | * @return GNUNET_YES if such a value exists, | 345 | * @return GNUNET_YES if such a value exists, |
346 | * GNUNET_NO if not | 346 | * GNUNET_NO if not |
347 | */ | 347 | */ |
348 | int GNUNET_CONTAINER_multihashmap_contains_value (const struct | 348 | int |
349 | GNUNET_CONTAINER_MultiHashMap | 349 | GNUNET_CONTAINER_multihashmap_contains_value (const struct |
350 | *map, | 350 | GNUNET_CONTAINER_MultiHashMap |
351 | const GNUNET_HashCode * key, | 351 | *map, |
352 | const void *value) | 352 | const GNUNET_HashCode * key, |
353 | const void *value) | ||
353 | { | 354 | { |
354 | struct MapEntry *e; | 355 | struct MapEntry *e; |
355 | 356 | ||
356 | e = map->map[idx_of (map, key)]; | 357 | e = map->map[idx_of (map, key)]; |
357 | while (e != NULL) | 358 | while (e != NULL) |
358 | { | 359 | { |
359 | if ( (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | 360 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && |
360 | (e->value == value) ) | 361 | (e->value == value)) |
361 | return GNUNET_YES; | 362 | return GNUNET_YES; |
362 | e = e->next; | 363 | e = e->next; |
363 | } | 364 | } |
364 | return GNUNET_NO; | 365 | return GNUNET_NO; |
365 | } | 366 | } |
366 | 367 | ||
@@ -388,15 +389,15 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
388 | map->map_length = new_len; | 389 | map->map_length = new_len; |
389 | map->map = new_map; | 390 | map->map = new_map; |
390 | for (i = 0; i < old_len; i++) | 391 | for (i = 0; i < old_len; i++) |
392 | { | ||
393 | while (NULL != (e = old_map[i])) | ||
391 | { | 394 | { |
392 | while (NULL != (e = old_map[i])) | 395 | old_map[i] = e->next; |
393 | { | 396 | idx = idx_of (map, &e->key); |
394 | old_map[i] = e->next; | 397 | e->next = new_map[idx]; |
395 | idx = idx_of (map, &e->key); | 398 | new_map[idx] = e; |
396 | e->next = new_map[idx]; | ||
397 | new_map[idx] = e; | ||
398 | } | ||
399 | } | 399 | } |
400 | } | ||
400 | GNUNET_free (old_map); | 401 | GNUNET_free (old_map); |
401 | } | 402 | } |
402 | 403 | ||
@@ -417,8 +418,7 @@ int | |||
417 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | 418 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, |
418 | const GNUNET_HashCode * key, | 419 | const GNUNET_HashCode * key, |
419 | void *value, | 420 | void *value, |
420 | enum GNUNET_CONTAINER_MultiHashMapOption | 421 | enum GNUNET_CONTAINER_MultiHashMapOption opt) |
421 | opt) | ||
422 | { | 422 | { |
423 | struct MapEntry *e; | 423 | struct MapEntry *e; |
424 | unsigned int i; | 424 | unsigned int i; |
@@ -426,25 +426,25 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
426 | i = idx_of (map, key); | 426 | i = idx_of (map, key); |
427 | if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && | 427 | if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && |
428 | (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 428 | (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
429 | { | ||
430 | e = map->map[i]; | ||
431 | while (e != NULL) | ||
429 | { | 432 | { |
430 | e = map->map[i]; | 433 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
431 | while (e != NULL) | 434 | { |
432 | { | 435 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
433 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 436 | return GNUNET_SYSERR; |
434 | { | 437 | e->value = value; |
435 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 438 | return GNUNET_NO; |
436 | return GNUNET_SYSERR; | 439 | } |
437 | e->value = value; | 440 | e = e->next; |
438 | return GNUNET_NO; | ||
439 | } | ||
440 | e = e->next; | ||
441 | } | ||
442 | } | 441 | } |
442 | } | ||
443 | if (map->size / 3 >= map->map_length / 4) | 443 | if (map->size / 3 >= map->map_length / 4) |
444 | { | 444 | { |
445 | grow (map); | 445 | grow (map); |
446 | i = idx_of (map, key); | 446 | i = idx_of (map, key); |
447 | } | 447 | } |
448 | e = GNUNET_malloc (sizeof (struct MapEntry)); | 448 | e = GNUNET_malloc (sizeof (struct MapEntry)); |
449 | e->key = *key; | 449 | e->key = *key; |
450 | e->value = value; | 450 | e->value = value; |
@@ -479,14 +479,14 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct | |||
479 | count = 0; | 479 | count = 0; |
480 | n = map->map[idx_of (map, key)]; | 480 | n = map->map[idx_of (map, key)]; |
481 | while (NULL != (e = n)) | 481 | while (NULL != (e = n)) |
482 | { | 482 | { |
483 | n = e->next; | 483 | n = e->next; |
484 | if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 484 | if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
485 | continue; | 485 | continue; |
486 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) | 486 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) |
487 | return GNUNET_SYSERR; | 487 | return GNUNET_SYSERR; |
488 | count++; | 488 | count++; |
489 | } | 489 | } |
490 | return count; | 490 | return count; |
491 | } | 491 | } |
492 | 492 | ||