]> pd.if.org Git - nbds/blobdiff - include/map.h
generic map iterator interface
[nbds] / include / map.h
index 4d8b78f39ab22147ee12b7db5fd0f28eaa727ef6..27e8dae00008cac7afef16bdde792c3dffcfccd1 100644 (file)
@@ -4,18 +4,23 @@
 #include "datatype.h"
 
 typedef struct map map_t;
+typedef struct map_iter map_iter_t;
 typedef struct map_impl map_impl_t;
 
-map_t *  map_alloc  (const map_impl_t *map_impl, const datatype_t *key_type);
-uint64_t map_get    (map_t *map, void *key);
-uint64_t map_set    (map_t *map, void *key, uint64_t new_val);
-uint64_t map_add    (map_t *map, void *key, uint64_t new_val);
-uint64_t map_cas    (map_t *map, void *key, uint64_t expected_val, uint64_t new_val);
-uint64_t map_replace(map_t *map, void *key, uint64_t new_val);
-uint64_t map_remove (map_t *map, void *key);
-uint64_t map_count  (map_t *map);
-void     map_print  (map_t *map);
-void     map_free   (map_t *map);
+map_t *  map_alloc   (const map_impl_t *map_impl, const datatype_t *key_type);
+uint64_t map_get     (map_t *map, void *key);
+uint64_t map_set     (map_t *map, void *key, uint64_t new_val);
+uint64_t map_add     (map_t *map, void *key, uint64_t new_val);
+uint64_t map_cas     (map_t *map, void *key, uint64_t expected_val, uint64_t new_val);
+uint64_t map_replace (map_t *map, void *key, uint64_t new_val);
+uint64_t map_remove  (map_t *map, void *key);
+uint64_t map_count   (map_t *map);
+void     map_print   (map_t *map);
+void     map_free    (map_t *map);
+
+map_iter_t * map_iter_begin (map_t *map, void *key);
+uint64_t     map_iter_next  (map_iter_t *iter, void **key);
+void         map_iter_free  (map_iter_t *iter);
 
 /////////////////////////////////////////////////////////////////////////////////////
 
@@ -24,12 +29,16 @@ void     map_free   (map_t *map);
 #define CAS_EXPECT_WHATEVER       (-2)
 
 typedef void *   (*map_alloc_t)  (const datatype_t *);
-typedef uint64_t (*map_cas_t)    (void *, void *, uint64_t, uint64_t);
-typedef uint64_t (*map_get_t)    (void *, void *);
-typedef uint64_t (*map_remove_t) (void *, void *);
-typedef uint64_t (*map_count_t)  (void *);
-typedef void     (*map_print_t)  (void *);
-typedef void     (*map_free_t)   (void *);
+typedef uint64_t (*map_cas_t)    (map_impl_t *, void *, uint64_t, uint64_t);
+typedef uint64_t (*map_get_t)    (map_impl_t *, void *);
+typedef uint64_t (*map_remove_t) (map_impl_t *, void *);
+typedef uint64_t (*map_count_t)  (map_impl_t *);
+typedef void     (*map_print_t)  (map_impl_t *);
+typedef void     (*map_free_t)   (map_impl_t *);
+
+typedef map_iter_t * (*map_iter_begin_t) (map_impl_t *, void *);
+typedef uint64_t     (*map_iter_next_t)  (map_iter_t *, void **);
+typedef void         (*map_iter_free_t)  (map_iter_t *);
 
 struct map_impl {
     map_alloc_t  alloc;
@@ -39,6 +48,10 @@ struct map_impl {
     map_count_t  count;
     map_print_t  print;
     map_free_t   free_;
+
+    map_iter_begin_t iter_begin;
+    map_iter_next_t  iter_next;
+    map_iter_free_t  iter_free;
 };
 
 #endif//MAP_H