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