X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=include%2Fmap.h;h=4d8b78f39ab22147ee12b7db5fd0f28eaa727ef6;hp=d670c35d17d877191fadd55938e8c87974c00575;hb=9d72edf41ce3a2ddbbe2d44afc23ef5ec53339c3;hpb=025017478bb385da88a6b185849c8bcffeb2e2aa diff --git a/include/map.h b/include/map.h index d670c35..4d8b78f 100644 --- a/include/map.h +++ b/include/map.h @@ -1,20 +1,44 @@ #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; +typedef struct map_impl map_impl_t; -map_t * map_alloc (map_type_e map_type); -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); -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); +void map_free (map_t *map); + +///////////////////////////////////////////////////////////////////////////////////// + +#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) (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 *); + +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_; +}; #endif//MAP_H