]> pd.if.org Git - nbds/blob - map/mlocal.h
use a vtable approach for generic map interface
[nbds] / map / mlocal.h
1 #ifndef MLOCAL_H
2 #define MLOCAL_H
3
4 #define CAS_EXPECT_DOES_NOT_EXIST ( 0)
5 #define CAS_EXPECT_EXISTS         (-1)
6 #define CAS_EXPECT_WHATEVER       (-2)
7
8 typedef void *   (*map_alloc_t)  (void);
9 typedef uint64_t (*map_cas_t)    (void *, const void *, uint32_t, uint64_t, uint64_t);
10 typedef uint64_t (*map_get_t)    (void *, const void *, uint32_t);
11 typedef uint64_t (*map_remove_t) (void *, const void *, uint32_t);
12 typedef uint64_t (*map_count_t)  (void *);
13 typedef void     (*map_print_t)  (void *);
14 typedef void     (*map_free_t)   (void *);
15
16 typedef struct map_impl {
17     map_alloc_t  alloc;
18     map_cas_t    cas;
19     map_get_t    get;
20     map_remove_t remove;
21     map_count_t  count;
22     map_print_t  print;
23     map_free_t   free_;
24 } map_impl_t;
25
26 typedef struct ht hashtable_t;
27 typedef struct sl skiplist_t;
28 typedef struct ll list_t;
29
30 hashtable_t * ht_alloc (void);
31 skiplist_t *  sl_alloc (void);
32 list_t *      ll_alloc (void);
33
34 uint64_t ht_cas    (hashtable_t *ht, const char *key, uint32_t key_len, uint64_t expected_val, uint64_t val);
35 uint64_t ht_get    (hashtable_t *ht, const char *key, uint32_t len);
36 uint64_t ht_remove (hashtable_t *ht, const char *key, uint32_t len);
37 uint64_t ht_count  (hashtable_t *ht);
38 void     ht_print  (hashtable_t *ht);
39 void     ht_free   (hashtable_t *ht);
40
41 uint64_t sl_cas    (skiplist_t *sl, const void *key_data, uint32_t key_len, uint64_t expected_val, uint64_t new_val);
42 uint64_t sl_lookup (skiplist_t *sl, const void *key_data, uint32_t key_len);
43 uint64_t sl_remove (skiplist_t *sl, const void *key_data, uint32_t key_len);
44 uint64_t sl_count  (skiplist_t *sl);
45 void     sl_print  (skiplist_t *sl);
46 void     sl_free   (skiplist_t *sl);
47
48 uint64_t ll_cas    (list_t *ll, const void *key_data, uint32_t key_len, uint64_t expected_val, uint64_t new_val);
49 uint64_t ll_lookup (list_t *ll, const void *key_data, uint32_t key_len);
50 uint64_t ll_remove (list_t *ll, const void *key_data, uint32_t key_len);
51 uint64_t ll_count  (list_t *ll);
52 void     ll_print  (list_t *ll);
53 void     ll_free   (list_t *ll);
54
55 #endif//MLOCAL_H