Browse code

Add some conveniences, based on enumerator.

Nat! authored on 24-03-2016 13:38:26
Showing 4 changed files
... ...
@@ -462,6 +462,8 @@ retry:
462 462
 }
463 463
 
464 464
 
465
+
466
+
465 467
 static int   _mulle_concurrent_hashmap_search_next( struct mulle_concurrent_hashmap *map,
466 468
                                                     unsigned int  *expect_mask,
467 469
                                                     unsigned int  *index,
... ...
@@ -637,3 +639,18 @@ int  _mulle_concurrent_hashmapenumerator_next( struct mulle_concurrent_hashmapen
637 639
 
638 640
    return( 1);
639 641
 }
642
+
643
+
644
+void  *_mulle_concurrent_hashmap_lookup_any( struct mulle_concurrent_hashmap *map)
645
+{
646
+   struct mulle_concurrent_hashmapenumerator  rover;
647
+   void  *any;
648
+   
649
+   any   = NULL;
650
+   
651
+   rover = mulle_concurrent_hashmap_enumerate( map);
652
+   _mulle_concurrent_hashmapenumerator_next( &rover, NULL, &any);
653
+   _mulle_concurrent_hashmapenumerator_done( &rover);
654
+   
655
+   return( any);
656
+}
... ...
@@ -66,7 +66,6 @@ int  _mulle_concurrent_hashmap_remove( struct mulle_concurrent_hashmap *map,
66 66
 void  *_mulle_concurrent_hashmap_lookup( struct mulle_concurrent_hashmap *map,
67 67
                                          intptr_t hash);
68 68
 
69
-
70 69
 unsigned int  _mulle_concurrent_hashmap_get_size( struct mulle_concurrent_hashmap *map);
71 70
 unsigned int  mulle_concurrent_hashmap_get_count( struct mulle_concurrent_hashmap *map);
72 71
 
... ...
@@ -111,4 +110,8 @@ static inline void  _mulle_concurrent_hashmapenumerator_done( struct mulle_concu
111 110
 {
112 111
 }
113 112
 
113
+// convenience using the enumerator
114
+
115
+void  *_mulle_concurrent_hashmap_lookup_any( struct mulle_concurrent_hashmap *map);
116
+
114 117
 #endif /* mulle_concurrent_hashmap_h */
... ...
@@ -396,3 +396,25 @@ int   _mulle_concurrent_pointerarray_find( struct mulle_concurrent_pointerarray
396 396
    return( found);
397 397
 }
398 398
 
399
+
400
+int   mulle_concurrent_pointerarray_map( struct mulle_concurrent_pointerarray *list,
401
+                                                void (*f)( void *, void *),
402
+                                                void *userinfo)
403
+{
404
+   struct mulle_concurrent_pointerarrayenumerator  rover;
405
+   void                                            *value;
406
+   
407
+   rover = mulle_concurrent_pointerarray_enumerate( list);
408
+   for(;;)
409
+   {
410
+      switch( _mulle_concurrent_pointerarrayenumerator_next( &rover, &value))
411
+      {
412
+      case -1 : return( -1);
413
+      case  1 : (*f)( value, userinfo); continue;
414
+      }
415
+      break;
416
+   }
417
+   _mulle_concurrent_pointerarrayenumerator_done( &rover);
418
+   return( 0);
419
+}
420
+
... ...
@@ -126,4 +126,10 @@ static inline void  _mulle_concurrent_pointerarrayreverseenumerator_done( struct
126 126
 {
127 127
 }
128 128
 
129
+
130
+// convenience using the enumrator
131
+int   mulle_concurrent_pointerarray_map( struct mulle_concurrent_pointerarray *list,
132
+                                        void (*f)( void *, void *),
133
+                                        void *userinfo);
134
+
129 135
 #endif /* mulle_concurrent_pointerarray_h */