]> pd.if.org Git - nbds/blob - include/map.h
27e8dae00008cac7afef16bdde792c3dffcfccd1
[nbds] / include / map.h
1 #ifndef MAP_H
2 #define MAP_H
3
4 #include "datatype.h"
5
6 typedef struct map map_t;
7 typedef struct map_iter map_iter_t;
8 typedef struct map_impl map_impl_t;
9
10 map_t *  map_alloc   (const map_impl_t *map_impl, const datatype_t *key_type);
11 uint64_t map_get     (map_t *map, void *key);
12 uint64_t map_set     (map_t *map, void *key, uint64_t new_val);
13 uint64_t map_add     (map_t *map, void *key, uint64_t new_val);
14 uint64_t map_cas     (map_t *map, void *key, uint64_t expected_val, uint64_t new_val);
15 uint64_t map_replace (map_t *map, void *key, uint64_t new_val);
16 uint64_t map_remove  (map_t *map, void *key);
17 uint64_t map_count   (map_t *map);
18 void     map_print   (map_t *map);
19 void     map_free    (map_t *map);
20
21 map_iter_t * map_iter_begin (map_t *map, void *key);
22 uint64_t     map_iter_next  (map_iter_t *iter, void **key);
23 void         map_iter_free  (map_iter_t *iter);
24
25 /////////////////////////////////////////////////////////////////////////////////////
26
27 #define CAS_EXPECT_DOES_NOT_EXIST ( 0)
28 #define CAS_EXPECT_EXISTS         (-1)
29 #define CAS_EXPECT_WHATEVER       (-2)
30
31 typedef void *   (*map_alloc_t)  (const datatype_t *);
32 typedef uint64_t (*map_cas_t)    (map_impl_t *, void *, uint64_t, uint64_t);
33 typedef uint64_t (*map_get_t)    (map_impl_t *, void *);
34 typedef uint64_t (*map_remove_t) (map_impl_t *, void *);
35 typedef uint64_t (*map_count_t)  (map_impl_t *);
36 typedef void     (*map_print_t)  (map_impl_t *);
37 typedef void     (*map_free_t)   (map_impl_t *);
38
39 typedef map_iter_t * (*map_iter_begin_t) (map_impl_t *, void *);
40 typedef uint64_t     (*map_iter_next_t)  (map_iter_t *, void **);
41 typedef void         (*map_iter_free_t)  (map_iter_t *);
42
43 struct map_impl {
44     map_alloc_t  alloc;
45     map_cas_t    cas;
46     map_get_t    get;
47     map_remove_t remove;
48     map_count_t  count;
49     map_print_t  print;
50     map_free_t   free_;
51
52     map_iter_begin_t iter_begin;
53     map_iter_next_t  iter_next;
54     map_iter_free_t  iter_free;
55 };
56
57 #endif//MAP_H