From 9ef0abf7ab5266f6b58c0e55bbe9dd9038bc7f6e Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sat, 14 Feb 2026 02:53:37 -0500 Subject: more like dangerousc.org atp --- set.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 set.h (limited to 'set.h') diff --git a/set.h b/set.h new file mode 100644 index 0000000..82292c2 --- /dev/null +++ b/set.h @@ -0,0 +1,40 @@ +#ifndef __SAFEC_SET_H +#define __SAFEC_SET_H +#include "types.h" +#include "hash.h" + +typedef struct { + hash_func_t hash_func; + eq_func_t eq_func; + double load_limit; + + size_t size; + + size_t __num_buckets; + void** __buckets; +} set_t; + +void set_init( + set_t* set, + hash_func_t hash_func, + eq_func_t eq_func, + double load_limit); +void set_init_capacity( + set_t* set, + hash_func_t hash_func, + eq_func_t eq_func, + double load_limit, + size_t capacity); +void set_destroy(set_t* set); + +bool set_contains(const set_t* set, const void* key); +void* set_get(const set_t* set, const void* key); +void* set_get_or_default(const set_t* set, const void* key, void* default_key); +void* set_add(set_t* set, void* key); +void set_put(set_t* set, void* key); +void* set_remove(set_t* set, const void* key); + +typedef void (*set_foreach_func_t)(void* key, void* data); +void set_foreach(set_t* set, set_foreach_func_t foreach_func, void* data); + +#endif -- cgit v1.2.3