aboutsummaryrefslogtreecommitdiffstats
path: root/cheesemap.h
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-03-22 17:28:26 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-03-22 17:28:26 +0100
commitcd38e101fcba293dbfe3ac9803bb9a7b673948fa (patch)
tree9b2a65428d6a85c4fca61adc8d6f323a4d2ba280 /cheesemap.h
parent543e8eb0075eb4bedb8bf08637416c2a5ebda50c (diff)
pass functions directly
Diffstat (limited to 'cheesemap.h')
-rw-r--r--cheesemap.h46
1 files changed, 15 insertions, 31 deletions
diff --git a/cheesemap.h b/cheesemap.h
index 0d89638..9a2fab9 100644
--- a/cheesemap.h
+++ b/cheesemap.h
@@ -31,28 +31,12 @@ enum {
typedef uint64_t cm_hash_t;
-/* memory methods */
-typedef void* (*cm_malloc_fn)(uintptr_t size, uint8_t* user);
-typedef void (*cm_free_fn)(void* ptr, uint8_t* user);
-
/* hash and compare methods */
typedef cm_hash_t (*cm_hash_fn)(const uint8_t* key, uint8_t* user);
typedef bool (*cm_compare_fn)(const uint8_t* key1, const uint8_t* key2,
uint8_t* user);
////////////////////////////////
-// callback methods needed by cheesemap
-//
-
-struct cheesemap_fns {
- uint8_t *mem_usr, *map_usr;
- cm_malloc_fn malloc;
- cm_free_fn free;
- cm_hash_fn hash;
- cm_compare_fn compare;
-};
-
-////////////////////////////////
// raw cheesemap implementation
//
// layout:
@@ -107,23 +91,22 @@ struct cheesemap_raw {
#define cm_raw_new() \
((struct cheesemap_raw){.ctrl = (uint8_t*)CM_CTRL_STATIC_EMPTY})
-bool cm_raw_new_with(struct cheesemap_raw* map, const struct cheesemap_fns* fns,
- uintptr_t key_size, uintptr_t value_size,
- uintptr_t initial_capacity);
-bool cm_raw_insert(struct cheesemap_raw* map, const struct cheesemap_fns* fns,
+bool cm_raw_new_with(struct cheesemap_raw* map, uintptr_t key_size,
+ uintptr_t value_size, uintptr_t initial_capacity);
+bool cm_raw_insert(struct cheesemap_raw* map, cm_hash_fn hash, uint8_t* user,
uintptr_t key_size, const uint8_t* key, uintptr_t value_size,
const uint8_t* value);
-bool cm_raw_reserve(struct cheesemap_raw* map, const struct cheesemap_fns* fns,
+bool cm_raw_reserve(struct cheesemap_raw* map, cm_hash_fn hash, uint8_t* user,
uintptr_t key_size, uintptr_t value_size,
uintptr_t additional);
-bool cm_raw_lookup(struct cheesemap_raw* map, const struct cheesemap_fns* fns,
- uintptr_t key_size, const uint8_t* key, uintptr_t value_size,
- uint8_t** out_value);
-bool cm_raw_remove(struct cheesemap_raw* map, const struct cheesemap_fns* fns,
- uintptr_t key_size, const uint8_t* key, uintptr_t value_size,
- uint8_t* out_value);
+bool cm_raw_lookup(struct cheesemap_raw* map, cm_hash_fn hash,
+ cm_compare_fn compare, uint8_t* user, uintptr_t key_size,
+ const uint8_t* key, uintptr_t value_size, uint8_t** out_value);
+bool cm_raw_remove(struct cheesemap_raw* map, cm_hash_fn hash,
+ cm_compare_fn compare, uint8_t* user, uintptr_t key_size,
+ const uint8_t* key, uintptr_t value_size, uint8_t* out_value);
void cm_raw_drop(struct cheesemap_raw* map, uintptr_t key_size,
- uintptr_t value_size, const struct cheesemap_fns* fns);
+ uintptr_t value_size);
////////////////////////////////
// cheesemap implementation
@@ -131,13 +114,14 @@ void cm_raw_drop(struct cheesemap_raw* map, uintptr_t key_size,
struct cheesemap {
uintptr_t key_size, value_size;
- struct cheesemap_fns fns;
+ uint8_t* user;
+ cm_hash_fn hash;
+ cm_compare_fn compare;
struct cheesemap_raw raw;
};
void cm_new(struct cheesemap* map, uintptr_t key_size, uintptr_t value_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);
+ uint8_t* user, cm_hash_fn hash, cm_compare_fn compare);
void cm_drop(struct cheesemap* map);
bool cm_insert(struct cheesemap* map, const uint8_t* key, const uint8_t* value);
bool cm_lookup(struct cheesemap* map, const uint8_t* key, uint8_t** out_value);