From 32425013e4c4bba14598b69e25471a45df8f8578 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Fri, 20 Mar 2026 23:46:24 +0100 Subject: adding stuff --- cheesemap.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'cheesemap.h') diff --git a/cheesemap.h b/cheesemap.h index d49bfce..520c3aa 100644 --- a/cheesemap.h +++ b/cheesemap.h @@ -14,8 +14,11 @@ #error "assert is not defined" #endif +typedef uintptr_t group_t; +typedef group_t bitmask_t; + enum { - CM_GROUP_SIZE = 8, + CM_GROUP_SIZE = sizeof(group_t), }; //////////////////////////////// @@ -54,8 +57,11 @@ struct cheesemap_fns { enum { CM_INITIAL_CAPACITY = CM_GROUP_SIZE, - CM_CTRL_EMPTY = 0x80, - CM_CTRL_DELETED = 0xFE, + // -1 as i8, all bits set, top bit = 1 + CM_CTRL_EMPTY = 0xFF, + // -128 as i8, top bit = 1 + CM_CTRL_DELETED = 0x80, + // FULL entries have top bit = 0, lower 7 bits are H2 hash CM_H2_MASK = 0x7F, CM_FP_SIZE = 7 }; @@ -68,9 +74,11 @@ static inline uint8_t cm_h2(cm_hash_t hash) { return (uint8_t)(hash & CM_H2_MASK); } +extern const uint8_t CM_CTRL_STATIC_EMPTY[CM_GROUP_SIZE]; + struct cheesemap_raw { - // mask of the capacity - uintptr_t cap_mask; + // number of buckets as mask + uintptr_t bucket_mask; // number of entries in the map uintptr_t entry_count; // number of entry left until resize @@ -79,10 +87,13 @@ struct cheesemap_raw { uint8_t* ctrl; }; -#define cm_raw_new() ((struct cheesemap_raw){0}) +#define cm_raw_new() \ + ((struct cheesemap_raw){.ctrl = (uint8_t*)CM_CTRL_STATIC_EMPTY}) +void cm_raw_insert(struct cheesemap_raw* map, const struct cheesemap_fns* fns, + const void* key, const void* value); void cm_raw_drop(struct cheesemap_raw* map, uintptr_t entry_size, - struct cheesemap_fns* fns); + const struct cheesemap_fns* fns); //////////////////////////////// // cheesemap implementation @@ -94,10 +105,9 @@ struct cheesemap { struct cheesemap_raw raw; }; -void cm_new(struct cheesemap* map, uintptr_t entry_size, - uint8_t* mem_usr, cm_malloc_fn malloc, cm_free_fn free, - uint8_t* map_usr, cm_hash_fn hash, - cm_compare_fn compare); +void cm_new(struct cheesemap* map, uintptr_t entry_size, uint8_t* mem_usr, + cm_malloc_fn malloc, cm_free_fn free, uint8_t* map_usr, + cm_hash_fn hash, cm_compare_fn compare); static inline void cm_drop(struct cheesemap* map) { assert(map != NULL); -- cgit v1.2.3