X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=include%2Fmap.h;h=27e8dae00008cac7afef16bdde792c3dffcfccd1;hp=d670c35d17d877191fadd55938e8c87974c00575;hb=329b5ab58cde015f4faec1879d3106f635294dd6;hpb=025017478bb385da88a6b185849c8bcffeb2e2aa diff --git a/include/map.h b/include/map.h index d670c35..27e8dae 100644 --- a/include/map.h +++ b/include/map.h @@ -1,20 +1,57 @@ #ifndef MAP_H #define MAP_H +#include "datatype.h" + typedef struct map map_t; -typedef enum stat { MAP_STAT_COUNT } map_stat_e; -typedef enum { MAP_TYPE_HASHTABLE, MAP_TYPE_SKIPLIST, MAP_TYPE_LIST } map_type_e; - -map_t * map_alloc (map_type_e map_type); -void map_free (map_t *map); -void map_print (map_t *map); -uint64_t map_stat (map_t *map, map_stat_e stat_type); - -uint64_t map_get (map_t *map, const void *key_data, uint32_t key_len); -uint64_t map_set (map_t *map, const void *key_data, uint32_t key_len, uint64_t new_val); -uint64_t map_add (map_t *map, const void *key_data, uint32_t key_len, uint64_t new_val); -uint64_t map_cas (map_t *map, const void *key_data, uint32_t key_len, uint64_t expected_val, uint64_t new_val); -uint64_t map_replace(map_t *map, const void *key_data, uint32_t key_len, uint64_t new_val); -uint64_t map_remove (map_t *map, const void *key_data, uint32_t key_len); +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_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); + +///////////////////////////////////////////////////////////////////////////////////// + +#define CAS_EXPECT_DOES_NOT_EXIST ( 0) +#define CAS_EXPECT_EXISTS (-1) +#define CAS_EXPECT_WHATEVER (-2) + +typedef void * (*map_alloc_t) (const datatype_t *); +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; + map_cas_t cas; + map_get_t get; + map_remove_t remove; + 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