diff options
Diffstat (limited to 'stc/cmap.h')
| -rw-r--r-- | stc/cmap.h | 301 |
1 files changed, 149 insertions, 152 deletions
@@ -69,16 +69,16 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; #define using_cmap_9(X, Key, Mapped, keyEquals, keyHash, \
mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \
- _using_CHASH(X, cmap_, Key, Mapped, keyEquals, keyHash, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Key)
+ _c_using_chash(cmap_##X, cmap_, Key, Mapped, keyEquals, keyHash, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Key)
#define using_cmap_13(X, Key, Mapped, keyEqualsRaw, keyHashRaw, \
mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cmap_, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey)
+ _c_using_chash(cmap_##X, cmap_, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey)
#define using_cmap_keydef(...) c_MACRO_OVERLOAD(using_cmap_keydef, __VA_ARGS__)
@@ -88,15 +88,15 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; #define using_cmap_keydef_9(X, Key, Mapped, keyEqualsRaw, keyHashRaw, \
keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cmap_, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Mapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey)
+ _c_using_chash(cmap_##X, cmap_, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Mapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey)
/* cmap_str, cmap_strkey, cmap_strval: */
#define using_cmap_str() \
- _using_CHASH(str, cmap_, cstr_t, cstr_t, cstr_equals_raw, cstr_hash_raw, \
- cstr_del, cstr_from, cstr_c_str, const char*, \
- cstr_del, cstr_from, cstr_c_str, const char*)
+ _c_using_chash(cmap_str, cmap_, cstr_t, cstr_t, cstr_equals_raw, cstr_hash_raw, \
+ cstr_del, cstr_from, cstr_c_str, const char*, \
+ cstr_del, cstr_from, cstr_c_str, const char*)
#define using_cmap_strkey(...) \
c_MACRO_OVERLOAD(using_cmap_strkey, __VA_ARGS__)
@@ -106,14 +106,14 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; #define using_cmap_strkey_3(X, Mapped, mappedDel) \
using_cmap_strkey_4(X, Mapped, mappedDel, c_no_clone)
#define using_cmap_strkey_4(X, Mapped, mappedDel, mappedClone) \
- _using_CHASH_strkey(X, cmap_, Mapped, mappedDel, mappedClone, c_trivial_toraw, Mapped)
+ _c_using_chash_strkey(X, cmap_, Mapped, mappedDel, mappedClone, c_trivial_toraw, Mapped)
#define using_cmap_strkey_6(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \
- _using_CHASH_strkey(X, cmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped)
+ _c_using_chash_strkey(X, cmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped)
-#define _using_CHASH_strkey(X, C, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \
- _using_CHASH(X, C, cstr_t, Mapped, cstr_equals_raw, cstr_hash_raw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- cstr_del, cstr_from, cstr_c_str, const char*)
+#define _c_using_chash_strkey(X, C, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \
+ _c_using_chash(C##X, C, cstr_t, Mapped, cstr_equals_raw, cstr_hash_raw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ cstr_del, cstr_from, cstr_c_str, const char*)
#define using_cmap_strval(...) \
c_MACRO_OVERLOAD(using_cmap_strval, __VA_ARGS__)
@@ -128,9 +128,9 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; using_cmap_strval_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_trivial_toraw, Key)
#define using_cmap_strval_8(X, Key, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cmap_, Key, cstr_t, keyEqualsRaw, keyHashRaw, \
- cstr_del, cstr_from, cstr_c_str, const char*, \
- keyDel, keyFromRaw, keyToRaw, RawKey)
+ _c_using_chash(cmap_##X, cmap_, Key, cstr_t, keyEqualsRaw, keyHashRaw, \
+ cstr_del, cstr_from, cstr_c_str, const char*, \
+ keyDel, keyFromRaw, keyToRaw, RawKey)
#define SET_ONLY_cmap_(...)
#define MAP_ONLY_cmap_(...) __VA_ARGS__
@@ -139,97 +139,97 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; #define CMAP_SIZE_T uint32_t
#endif
-#define _using_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey) \
- typedef Key C##X##_key_t; \
- typedef Mapped C##X##_mapped_t; \
- typedef RawKey C##X##_rawkey_t; \
- typedef RawMapped C##X##_rawmapped_t; \
- typedef CMAP_SIZE_T C##X##_size_t; \
+#define _c_using_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey) \
+ typedef Key CX##_key_t; \
+ typedef Mapped CX##_mapped_t; \
+ typedef RawKey CX##_rawkey_t; \
+ typedef RawMapped CX##_rawmapped_t; \
+ typedef CMAP_SIZE_T CX##_size_t; \
\
typedef SET_ONLY_##C( Key ) \
MAP_ONLY_##C( struct {Key first; \
Mapped second;} ) \
- C##X##_value_t; \
+ CX##_value_t; \
\
typedef SET_ONLY_##C( RawKey ) \
MAP_ONLY_##C( struct {RawKey first; \
RawMapped second;} ) \
- C##X##_rawvalue_t; \
+ CX##_rawvalue_t; \
\
typedef struct { \
- C##X##_value_t *ref; \
+ CX##_value_t *ref; \
bool inserted; \
- } C##X##_result_t; \
+ } CX##_result_t; \
\
typedef struct { \
- C##X##_value_t* table; \
+ CX##_value_t* table; \
uint8_t* _hashx; \
- C##X##_size_t size, bucket_count; \
+ CX##_size_t size, bucket_count; \
float min_load_factor; \
float max_load_factor; \
- } C##X; \
+ } CX; \
\
typedef struct { \
- C##X##_value_t *ref; \
+ CX##_value_t *ref; \
uint8_t* _hx; \
- } C##X##_iter_t; \
+ } CX##_iter_t; \
\
- STC_INLINE C##X \
- C##X##_init(void) {C##X m = _cmap_inits; return m;} \
+ STC_INLINE CX \
+ CX##_init(void) {CX m = _cmap_inits; return m;} \
STC_INLINE bool \
- C##X##_empty(C##X m) {return m.size == 0;} \
+ CX##_empty(CX m) {return m.size == 0;} \
STC_INLINE size_t \
- C##X##_size(C##X m) {return (size_t) m.size;} \
- STC_INLINE C##X##_value_t \
- C##X##_value_clone(C##X##_value_t val) { \
+ CX##_size(CX m) {return (size_t) m.size;} \
+ STC_INLINE CX##_value_t \
+ CX##_value_clone(CX##_value_t val) { \
*KEY_REF_##C(&val) = keyFromRaw(keyToRaw(KEY_REF_##C(&val))); \
MAP_ONLY_##C( val.second = mappedFromRaw(mappedToRaw(&val.second)); ) \
return val; \
} \
STC_INLINE void \
- C##X##_value_del(C##X##_value_t* val) { \
+ CX##_value_del(CX##_value_t* val) { \
keyDel(KEY_REF_##C(val)); \
MAP_ONLY_##C( mappedDel(&val->second); ) \
} \
STC_INLINE size_t \
- C##X##_bucket_count(C##X map) {return (size_t) map.bucket_count;} \
+ CX##_bucket_count(CX map) {return (size_t) map.bucket_count;} \
STC_INLINE size_t \
- C##X##_capacity(C##X map) {return (size_t) (map.bucket_count*map.max_load_factor);} \
+ CX##_capacity(CX map) {return (size_t) (map.bucket_count*map.max_load_factor);} \
STC_INLINE void \
- C##X##_swap(C##X *map1, C##X *map2) {c_swap(C##X, *map1, *map2);} \
+ CX##_swap(CX *map1, CX *map2) {c_swap(CX, *map1, *map2);} \
STC_INLINE void \
- C##X##_set_load_factors(C##X* self, float min_load, float max_load) { \
+ CX##_set_load_factors(CX* self, float min_load, float max_load) { \
self->min_load_factor = min_load; \
self->max_load_factor = max_load; \
} \
- STC_API C##X \
- C##X##_with_capacity(size_t cap); \
- STC_API C##X \
- C##X##_clone(C##X map); \
+ STC_API CX \
+ CX##_with_capacity(size_t cap); \
+ STC_API CX \
+ CX##_clone(CX map); \
STC_API void \
- C##X##_reserve(C##X* self, size_t capacity); \
+ CX##_reserve(CX* self, size_t capacity); \
STC_API void \
- C##X##_del(C##X* self); \
+ CX##_del(CX* self); \
STC_API void \
- C##X##_clear(C##X* self); \
+ CX##_clear(CX* self); \
\
- STC_API C##X##_result_t \
- C##X##_insert_entry_(C##X* self, RawKey rkey); \
+ STC_API CX##_result_t \
+ CX##_insert_entry_(CX* self, RawKey rkey); \
STC_API chash_bucket_t \
- C##X##_bucket_(const C##X* self, const C##X##_rawkey_t* rkeyptr); \
+ CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr); \
\
- STC_API C##X##_iter_t \
- C##X##_find(const C##X* self, RawKey rkey); \
+ STC_API CX##_iter_t \
+ CX##_find(const CX* self, RawKey rkey); \
STC_INLINE bool \
- C##X##_contains(const C##X* self, RawKey rkey) { \
- return self->size && self->_hashx[C##X##_bucket_(self, &rkey).idx]; \
+ CX##_contains(const CX* self, RawKey rkey) { \
+ return self->size && self->_hashx[CX##_bucket_(self, &rkey).idx]; \
} \
\
- STC_INLINE C##X##_result_t \
- C##X##_emplace(C##X* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
- C##X##_result_t res = C##X##_insert_entry_(self, rkey); \
+ STC_INLINE CX##_result_t \
+ CX##_emplace(CX* self, RawKey rkey MAP_ONLY_##C(, RawMapped rmapped)) { \
+ CX##_result_t res = CX##_insert_entry_(self, rkey); \
if (res.inserted) { \
*KEY_REF_##C(res.ref) = keyFromRaw(rkey); \
MAP_ONLY_##C(res.ref->second = mappedFromRaw(rmapped);) \
@@ -237,81 +237,78 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; return res; \
} \
STC_INLINE void \
- C##X##_emplace_n(C##X* self, const C##X##_rawvalue_t arr[], size_t n) { \
- for (size_t i=0; i<n; ++i) SET_ONLY_##C( C##X##_emplace(self, arr[i]); ) \
- MAP_ONLY_##C( C##X##_emplace(self, arr[i].first, arr[i].second); ) \
+ CX##_emplace_n(CX* self, const CX##_rawvalue_t arr[], size_t n) { \
+ for (size_t i=0; i<n; ++i) SET_ONLY_##C( CX##_emplace(self, arr[i]); ) \
+ MAP_ONLY_##C( CX##_emplace(self, arr[i].first, arr[i].second); ) \
} \
\
- STC_INLINE C##X##_result_t \
- C##X##_insert(C##X* self, Key key MAP_ONLY_##C(, Mapped mapped)) { \
- C##X##_result_t res = C##X##_insert_entry_(self, keyToRaw(&key)); \
+ STC_INLINE CX##_result_t \
+ CX##_insert(CX* self, Key key MAP_ONLY_##C(, Mapped mapped)) { \
+ CX##_result_t res = CX##_insert_entry_(self, keyToRaw(&key)); \
if (res.inserted) {*KEY_REF_##C(res.ref) = key; MAP_ONLY_##C( res.ref->second = mapped; )} \
else {keyDel(&key); MAP_ONLY_##C( mappedDel(&mapped); )} \
return res; \
} \
\
MAP_ONLY_##C( \
- STC_INLINE C##X##_result_t \
- C##X##_insert_or_assign(C##X* self, Key key, Mapped mapped) { \
- C##X##_result_t res = C##X##_insert_entry_(self, keyToRaw(&key)); \
+ STC_INLINE CX##_result_t \
+ CX##_insert_or_assign(CX* self, Key key, Mapped mapped) { \
+ CX##_result_t res = CX##_insert_entry_(self, keyToRaw(&key)); \
if (res.inserted) res.ref->first = key; \
else {keyDel(&key); mappedDel(&res.ref->second);} \
res.ref->second = mapped; return res; \
} \
- STC_INLINE C##X##_result_t \
- C##X##_put(C##X* self, Key k, Mapped m) { /* shorter, like operator[] */ \
- return C##X##_insert_or_assign(self, k, m); \
+ STC_INLINE CX##_result_t \
+ CX##_put(CX* self, Key k, Mapped m) { /* shorter, like operator[] */ \
+ return CX##_insert_or_assign(self, k, m); \
} \
- STC_INLINE C##X##_result_t \
- C##X##_emplace_or_assign(C##X* self, RawKey rkey, RawMapped rmapped) { \
- C##X##_result_t res = C##X##_insert_entry_(self, rkey); \
+ STC_INLINE CX##_result_t \
+ CX##_emplace_or_assign(CX* self, RawKey rkey, RawMapped rmapped) { \
+ CX##_result_t res = CX##_insert_entry_(self, rkey); \
if (res.inserted) res.ref->first = keyFromRaw(rkey); \
else mappedDel(&res.ref->second); \
res.ref->second = mappedFromRaw(rmapped); return res; \
} \
- STC_INLINE C##X##_mapped_t* \
- C##X##_at(const C##X* self, RawKey rkey) { \
- chash_bucket_t b = C##X##_bucket_(self, &rkey); \
+ STC_INLINE CX##_mapped_t* \
+ CX##_at(const CX* self, RawKey rkey) { \
+ chash_bucket_t b = CX##_bucket_(self, &rkey); \
assert(self->_hashx[b.idx]); \
return &self->table[b.idx].second; \
}) \
\
- STC_INLINE C##X##_iter_t \
- C##X##_begin(const C##X* self) { \
- C##X##_iter_t it = {self->table, self->_hashx}; \
+ STC_INLINE CX##_iter_t \
+ CX##_begin(const CX* self) { \
+ CX##_iter_t it = {self->table, self->_hashx}; \
if (it._hx) while (*it._hx == 0) ++it.ref, ++it._hx; \
return it; \
} \
- STC_INLINE C##X##_iter_t \
- C##X##_end(const C##X* self) {\
- C##X##_iter_t it = {self->table + self->bucket_count}; return it; \
+ STC_INLINE CX##_iter_t \
+ CX##_end(const CX* self) {\
+ CX##_iter_t it = {self->table + self->bucket_count}; return it; \
} \
STC_INLINE void \
- C##X##_next(C##X##_iter_t* it) { \
+ CX##_next(CX##_iter_t* it) { \
while ((++it->ref, *++it->_hx == 0)) ; \
} \
- STC_INLINE C##X##_mapped_t* \
- C##X##_itval(C##X##_iter_t it) {return SET_ONLY_##C( it.ref ) \
- MAP_ONLY_##C( &it.ref->second );} \
\
STC_API void \
- C##X##_erase_entry(C##X* self, C##X##_value_t* val); \
+ CX##_erase_entry(CX* self, CX##_value_t* val); \
STC_INLINE size_t \
- C##X##_erase(C##X* self, RawKey rkey) { \
+ CX##_erase(CX* self, RawKey rkey) { \
if (self->size == 0) return 0; \
- chash_bucket_t b = C##X##_bucket_(self, &rkey); \
- return self->_hashx[b.idx] ? C##X##_erase_entry(self, self->table + b.idx), 1 : 0; \
+ chash_bucket_t b = CX##_bucket_(self, &rkey); \
+ return self->_hashx[b.idx] ? CX##_erase_entry(self, self->table + b.idx), 1 : 0; \
} \
- STC_INLINE C##X##_iter_t \
- C##X##_erase_at(C##X* self, C##X##_iter_t pos) { \
- C##X##_erase_entry(self, pos.ref); \
- C##X##_next(&pos); return pos; \
+ STC_INLINE CX##_iter_t \
+ CX##_erase_at(CX* self, CX##_iter_t pos) { \
+ CX##_erase_entry(self, pos.ref); \
+ CX##_next(&pos); return pos; \
} \
\
- _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey) \
- typedef C##X C##X##_t
+ _c_implement_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey) \
+ typedef CX CX##_t
STC_API uint64_t c_default_hash(const void *data, size_t len);
STC_INLINE uint64_t c_default_hash32(const void* data, size_t ignored)
@@ -329,37 +326,37 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um #endif
#define chash_index_(h, entryPtr) ((entryPtr) - (h).table)
-#define _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey) \
- STC_DEF C##X \
- C##X##_with_capacity(size_t cap) { \
- C##X h = _cmap_inits; \
- C##X##_reserve(&h, cap); \
+#define _c_implement_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey) \
+ STC_DEF CX \
+ CX##_with_capacity(size_t cap) { \
+ CX h = _cmap_inits; \
+ CX##_reserve(&h, cap); \
return h; \
} \
\
- STC_INLINE void C##X##_wipe_(C##X* self) { \
+ STC_INLINE void CX##_wipe_(CX* self) { \
if (self->size == 0) return; \
- C##X##_value_t* e = self->table, *end = e + self->bucket_count; \
+ CX##_value_t* e = self->table, *end = e + self->bucket_count; \
uint8_t *hx = self->_hashx; \
- for (; e != end; ++e) if (*hx++) C##X##_value_del(e); \
+ for (; e != end; ++e) if (*hx++) CX##_value_del(e); \
} \
\
- STC_DEF void C##X##_del(C##X* self) { \
- C##X##_wipe_(self); \
+ STC_DEF void CX##_del(CX* self) { \
+ CX##_wipe_(self); \
c_free(self->_hashx); \
c_free(self->table); \
} \
\
- STC_DEF void C##X##_clear(C##X* self) { \
- C##X##_wipe_(self); \
+ STC_DEF void CX##_clear(CX* self) { \
+ CX##_wipe_(self); \
self->size = 0; \
memset(self->_hashx, 0, self->bucket_count); \
} \
\
STC_DEF chash_bucket_t \
- C##X##_bucket_(const C##X* self, const C##X##_rawkey_t* rkeyptr) { \
+ CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr) { \
const uint64_t hash = keyHashRaw(rkeyptr, sizeof(RawKey)); \
uint_fast8_t sx; size_t cap = self->bucket_count; \
chash_bucket_t b = {_c_SELECT(fastrange,CMAP_SIZE_T)(hash, cap), (uint_fast8_t)(hash | 0x80)}; \
@@ -374,24 +371,24 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um return b; \
} \
\
- STC_DEF C##X##_iter_t \
- C##X##_find(const C##X* self, RawKey rkey) { \
- C##X##_iter_t it = {NULL}; \
+ STC_DEF CX##_iter_t \
+ CX##_find(const CX* self, RawKey rkey) { \
+ CX##_iter_t it = {NULL}; \
if (self->size == 0) return it; \
- chash_bucket_t b = C##X##_bucket_(self, &rkey); \
+ chash_bucket_t b = CX##_bucket_(self, &rkey); \
if (*(it._hx = self->_hashx+b.idx)) it.ref = self->table+b.idx; \
return it; \
} \
\
- STC_INLINE void C##X##_reserve_expand_(C##X* self) { \
+ STC_INLINE void CX##_reserve_expand_(CX* self) { \
if (self->size + 1 >= self->bucket_count*self->max_load_factor) \
- C##X##_reserve(self, 5 + self->size * 3 / 2); \
+ CX##_reserve(self, 5 + self->size * 3 / 2); \
} \
- STC_DEF C##X##_result_t \
- C##X##_insert_entry_(C##X* self, RawKey rkey) { \
- C##X##_reserve_expand_(self); \
- chash_bucket_t b = C##X##_bucket_(self, &rkey); \
- C##X##_result_t res = {&self->table[b.idx], !self->_hashx[b.idx]}; \
+ STC_DEF CX##_result_t \
+ CX##_insert_entry_(CX* self, RawKey rkey) { \
+ CX##_reserve_expand_(self); \
+ chash_bucket_t b = CX##_bucket_(self, &rkey); \
+ CX##_result_t res = {&self->table[b.idx], !self->_hashx[b.idx]}; \
if (res.inserted) { \
self->_hashx[b.idx] = b.hx; \
++self->size; \
@@ -399,38 +396,38 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um return res; \
} \
\
- STC_DEF C##X \
- C##X##_clone(C##X m) { \
- C##X clone = { \
- c_new_2(C##X##_value_t, m.bucket_count), \
+ STC_DEF CX \
+ CX##_clone(CX m) { \
+ CX clone = { \
+ c_new_2(CX##_value_t, m.bucket_count), \
(uint8_t *) memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1), \
m.size, m.bucket_count, m.min_load_factor, m.max_load_factor \
}; \
- C##X##_value_t *e = m.table, *end = e + m.bucket_count, *dst = clone.table; \
+ CX##_value_t *e = m.table, *end = e + m.bucket_count, *dst = clone.table; \
for (uint8_t *hx = m._hashx; e != end; ++hx, ++e, ++dst) \
- if (*hx) *dst = C##X##_value_clone(*e); \
+ if (*hx) *dst = CX##_value_clone(*e); \
return clone; \
} \
\
STC_DEF void \
- C##X##_reserve(C##X* self, size_t newcap) { \
+ CX##_reserve(CX* self, size_t newcap) { \
if (newcap < self->size) return; \
size_t oldcap = self->bucket_count; \
newcap = (size_t) (newcap / self->max_load_factor) | 1; \
- C##X tmp = { \
- c_new_2 (C##X##_value_t, newcap), \
+ CX tmp = { \
+ c_new_2 (CX##_value_t, newcap), \
(uint8_t *) c_calloc(newcap + 1, sizeof(uint8_t)), \
- self->size, (C##X##_size_t) newcap, \
+ self->size, (CX##_size_t) newcap, \
self->min_load_factor, self->max_load_factor \
}; \
/* Rehash: */ \
- tmp._hashx[newcap] = 0xff; c_swap(C##X, *self, tmp); \
- C##X##_value_t* e = tmp.table, *slot = self->table; \
+ tmp._hashx[newcap] = 0xff; c_swap(CX, *self, tmp); \
+ CX##_value_t* e = tmp.table, *slot = self->table; \
uint8_t* hashx = self->_hashx; \
for (size_t i = 0; i < oldcap; ++i, ++e) \
if (tmp._hashx[i]) { \
RawKey r = keyToRaw(KEY_REF_##C(e)); \
- chash_bucket_t b = C##X##_bucket_(self, &r); \
+ chash_bucket_t b = CX##_bucket_(self, &r); \
slot[b.idx] = *e, \
hashx[b.idx] = (uint8_t) b.hx; \
} \
@@ -439,11 +436,11 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um } \
\
STC_DEF void \
- C##X##_erase_entry(C##X* self, C##X##_value_t* val) { \
+ CX##_erase_entry(CX* self, CX##_value_t* val) { \
size_t i = chash_index_(*self, val), j = i, k, cap = self->bucket_count; \
- C##X##_value_t* slot = self->table; \
+ CX##_value_t* slot = self->table; \
uint8_t* hashx = self->_hashx; \
- C##X##_value_del(&slot[i]); \
+ CX##_value_del(&slot[i]); \
for (;;) { /* delete without leaving tombstone */ \
if (++j == cap) j = 0; \
if (! hashx[j]) \
@@ -455,7 +452,7 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_um } \
hashx[i] = 0, k = --self->size; \
if (k < cap*self->min_load_factor && k > 512) \
- C##X##_reserve(self, k*1.2); \
+ CX##_reserve(self, k*1.2); \
}
STC_DEF uint64_t c_default_hash(const void *key, size_t len) {
@@ -476,9 +473,9 @@ STC_DEF uint64_t c_default_hash(const void *key, size_t len) { }
#else
-#define _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
- mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
- keyDel, keyFromRaw, keyToRaw, RawKey)
+#define _c_implement_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \
+ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \
+ keyDel, keyFromRaw, keyToRaw, RawKey)
#endif
#endif
|
