From b0a7ab1d4213ed5f209764c3a582096d5ce96bb1 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sat, 10 Apr 2021 17:03:10 +0200 Subject: Formatting and internal renaming. Increased readability and consistency. --- stc/carray.h | 6 +-- stc/cdeq.h | 30 +++++------ stc/clist.h | 115 +++++++++++++++++++++--------------------- stc/cmap.h | 160 ++++++++++++++++++++++++++++------------------------------- stc/cpque.h | 10 ++-- stc/cqueue.h | 6 +-- stc/cset.h | 15 +++--- stc/csmap.h | 72 +++++++++++++-------------- stc/csptr.h | 66 ++++++++++++++---------- stc/csset.h | 15 +++--- stc/cstack.h | 7 ++- stc/cvec.h | 37 +++++++------- 12 files changed, 268 insertions(+), 271 deletions(-) diff --git a/stc/carray.h b/stc/carray.h index c3b60663..9c5b488e 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -55,11 +55,11 @@ int main() { #define using_carray2(...) c_MACRO_OVERLOAD(using_carray2, __VA_ARGS__) #define using_carray2_2(X, Value) \ - _c_using_carray2(carray2##X, Value, c_trivial_del, c_trivial_fromraw) + _c_using_carray2(carray2##X, Value, c_trivial_del, c_trivial_fromraw) #define using_carray2_3(X, Value, valueDel) \ - _c_using_carray2(carray2##X, Value, valueDel, c_no_clone) + _c_using_carray2(carray2##X, Value, valueDel, c_no_clone) #define using_carray2_4(X, Value, valueDel, valueClone) \ - _c_using_carray2(carray2##X, Value, valueDel, valueClone) + _c_using_carray2(carray2##X, Value, valueDel, valueClone) #define _c_using_carray2(CX, Value, valueDel, valueClone) \ \ diff --git a/stc/cdeq.h b/stc/cdeq.h index 5b402981..b6447eda 100644 --- a/stc/cdeq.h +++ b/stc/cdeq.h @@ -29,17 +29,17 @@ #define using_cdeq(...) c_MACRO_OVERLOAD(using_cdeq, __VA_ARGS__) #define using_cdeq_2(X, Value) \ - using_cdeq_3(X, Value, c_default_compare) + using_cdeq_3(X, Value, c_default_compare) #define using_cdeq_3(X, Value, valueCompare) \ - using_cdeq_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) + using_cdeq_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) #define using_cdeq_4(X, Value, valueCompare, valueDel) \ - using_cdeq_5(X, Value, valueCompare, valueDel, c_no_clone) + using_cdeq_5(X, Value, valueCompare, valueDel, c_no_clone) #define using_cdeq_5(X, Value, valueCompare, valueDel, valueClone) \ - using_cdeq_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) + using_cdeq_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) #define using_cdeq_7(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - _c_using_cdeq(cdeq_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) + _c_using_cdeq(cdeq_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) #define using_cdeq_str() \ - _c_using_cdeq(cdeq_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) + _c_using_cdeq(cdeq_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) #define typedefs_cdeq(CX, Value, RawValue) \ typedef Value CX##_value_t; \ @@ -116,20 +116,20 @@ typedef int (*c_cmp_fn)(const void*, const void*); CX##_insert_range_p(CX* self, CX##_value_t* pos, const CX##_value_t* pfirst, const CX##_value_t* pfinish); \ \ STC_INLINE CX##_iter_t \ - CX##_insert_range(CX* self, CX##_iter_t pos, CX##_iter_t first, CX##_iter_t finish) { \ - return CX##_insert_range_p(self, pos.ref, first.ref, finish.ref); \ + CX##_insert_range(CX* self, CX##_iter_t it, CX##_iter_t first, CX##_iter_t finish) { \ + return CX##_insert_range_p(self, it.ref, first.ref, finish.ref); \ } \ STC_INLINE CX##_iter_t \ - CX##_insert_at(CX* self, CX##_iter_t pos, Value value) { \ - return CX##_insert_range_p(self, pos.ref, &value, &value + 1); \ + CX##_insert_at(CX* self, CX##_iter_t it, Value value) { \ + return CX##_insert_range_p(self, it.ref, &value, &value + 1); \ } \ STC_INLINE CX##_iter_t \ CX##_insert(CX* self, size_t idx, Value value) { \ return CX##_insert_range_p(self, self->data + idx, &value, &value + 1); \ } \ STC_INLINE CX##_iter_t \ - CX##_emplace_at(CX* self, CX##_iter_t pos, RawValue raw) { \ - return CX##_insert_at(self, pos, valueFromRaw(raw)); \ + CX##_emplace_at(CX* self, CX##_iter_t it, RawValue raw) { \ + return CX##_insert_at(self, it, valueFromRaw(raw)); \ } \ STC_INLINE CX##_iter_t \ CX##_emplace(CX* self, size_t idx, RawValue raw) { \ @@ -144,8 +144,8 @@ typedef int (*c_cmp_fn)(const void*, const void*); return CX##_erase_range_p(self, first.ref, finish.ref); \ } \ STC_INLINE CX##_iter_t \ - CX##_erase_at(CX* self, CX##_iter_t pos) { \ - return CX##_erase_range_p(self, pos.ref, pos.ref + 1); \ + CX##_erase_at(CX* self, CX##_iter_t it) { \ + return CX##_erase_range_p(self, it.ref, it.ref + 1); \ } \ STC_INLINE CX##_iter_t \ CX##_erase(CX* self, size_t idx, size_t n) { \ @@ -183,7 +183,7 @@ typedef int (*c_cmp_fn)(const void*, const void*); CX##_sort_range(CX##_begin(self), CX##_end(self), CX##_value_compare); \ } \ _c_implement_cdeq(CX, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - typedef CX CX##_t + struct stc_trailing_semicolon /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/stc/clist.h b/stc/clist.h index 5ec3024a..61ac6ad2 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -58,17 +58,17 @@ #define using_clist(...) c_MACRO_OVERLOAD(using_clist, __VA_ARGS__) #define using_clist_2(X, Value) \ - using_clist_3(X, Value, c_default_compare) + using_clist_3(X, Value, c_default_compare) #define using_clist_3(X, Value, valueCompare) \ - using_clist_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) + using_clist_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) #define using_clist_4(X, Value, valueCompare, valueDel) \ - using_clist_5(X, Value, valueCompare, valueDel, c_no_clone) + using_clist_5(X, Value, valueCompare, valueDel, c_no_clone) #define using_clist_5(X, Value, valueCompare, valueDel, valueClone) \ - using_clist_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) + using_clist_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) #define using_clist_7(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - _c_using_clist(clist_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) + _c_using_clist(clist_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) #define using_clist_str() \ - _c_using_clist(clist_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) + _c_using_clist(clist_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) #define _c_using_clist_types(CX, Value) \ typedef Value CX##_value_t; \ @@ -109,35 +109,32 @@ STC_API size_t _clist_size(const clist_VOID* self); STC_INLINE Value CX##_value_fromraw(RawValue raw) \ {return valueFromRaw(raw);} \ \ - STC_API void CX##_emplace_n(CX *self, const CX##_rawvalue_t arr[], size_t size); \ STC_API void CX##_push_back(CX* self, Value value); \ STC_API void CX##_push_front(CX* self, Value value); \ STC_INLINE void CX##_emplace_back(CX* self, RawValue raw) \ {CX##_push_back(self, valueFromRaw(raw));} \ STC_INLINE void CX##_emplace_front(CX* self, RawValue raw) \ {CX##_push_front(self, valueFromRaw(raw));} \ + STC_API CX##_iter_t CX##_insert(CX* self, CX##_iter_t it, Value value); \ + STC_INLINE \ + CX##_iter_t CX##_emplace(CX* self, CX##_iter_t it, RawValue raw) \ + {return CX##_insert(self, it, valueFromRaw(raw));} \ + STC_API void CX##_emplace_n(CX *self, const CX##_rawvalue_t arr[], size_t size); \ \ STC_API CX##_node_t* CX##_erase_after_(CX* self, CX##_node_t* node); \ STC_INLINE void CX##_pop_front(CX* self) {CX##_erase_after_(self, self->last);} \ + STC_API CX##_iter_t CX##_erase_at(CX* self, CX##_iter_t it); \ + STC_API CX##_iter_t CX##_erase_range(CX* self, CX##_iter_t it1, CX##_iter_t it2); \ + STC_API size_t CX##_remove(CX* self, RawValue val); \ \ - STC_API void CX##_splice(CX* self, CX##_iter_t pos, CX* other); \ - STC_API CX CX##_split(CX* self, CX##_iter_t pos1, CX##_iter_t pos2); \ -\ - STC_API CX##_iter_t CX##_insert(CX* self, CX##_iter_t pos, Value value); \ - STC_API CX##_iter_t CX##_erase_at(CX* self, CX##_iter_t pos); \ - STC_API CX##_iter_t CX##_erase_range(CX* self, CX##_iter_t pos, CX##_iter_t finish); \ + STC_API void CX##_splice(CX* self, CX##_iter_t it, CX* other); \ + STC_API CX CX##_split(CX* self, CX##_iter_t it1, CX##_iter_t it2); \ \ - STC_API size_t CX##_remove(CX* self, RawValue val); \ STC_API void CX##_sort(CX* self); \ - STC_API CX##_iter_t CX##_find_in_range(const CX* self, CX##_iter_t first, CX##_iter_t finish, RawValue val); \ + STC_API CX##_iter_t CX##_find_in_range(const CX* self, CX##_iter_t it1, CX##_iter_t it2, RawValue val); \ \ STC_INLINE Value* CX##_front(const CX* self) {return &self->last->next->value;} \ STC_INLINE Value* CX##_back(const CX* self) {return &self->last->value;} \ -\ - STC_INLINE CX##_iter_t \ - CX##_emplace(CX* self, CX##_iter_t pos, RawValue raw) { \ - return CX##_insert(self, pos, valueFromRaw(raw)); \ - } \ \ STC_INLINE CX##_iter_t \ CX##_begin(const CX* self) { \ @@ -146,7 +143,7 @@ STC_API size_t _clist_size(const clist_VOID* self); } \ STC_INLINE CX##_iter_t \ CX##_end(const CX* self) { \ - CX##_iter_t it = {&self->last, NULL, NULL}; return it; \ + CX##_iter_t it = {NULL}; return it; \ } \ STC_INLINE void \ CX##_next(CX##_iter_t* it) { \ @@ -160,10 +157,10 @@ STC_API size_t _clist_size(const clist_VOID* self); } \ \ STC_INLINE void \ - CX##_splice_range(CX* self, CX##_iter_t pos, \ - CX* other, CX##_iter_t pos1, CX##_iter_t pos2) { \ - CX tmp = CX##_split(other, pos1, pos2); \ - CX##_splice(self, pos, &tmp); \ + CX##_splice_range(CX* self, CX##_iter_t it, \ + CX* other, CX##_iter_t it1, CX##_iter_t it2) { \ + CX tmp = CX##_split(other, it1, it2); \ + CX##_splice(self, it, &tmp); \ } \ \ STC_INLINE CX##_iter_t \ @@ -172,7 +169,7 @@ STC_API size_t _clist_size(const clist_VOID* self); } \ \ _c_implement_clist(CX, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - typedef CX CX##_t + struct stc_trailing_semicolon /* -------------------------- IMPLEMENTATION ------------------------- */ @@ -182,10 +179,10 @@ STC_API size_t _clist_size(const clist_VOID* self); STC_DEF CX \ CX##_clone(CX list) { \ CX out = CX##_init(); \ - c_foreach_3 (i, CX, list) \ - CX##_emplace_back(&out, valueToRaw(i.ref)); \ + c_foreach_3 (it, CX, list) CX##_emplace_back(&out, valueToRaw(it.ref)); \ return out; \ } \ +\ STC_DEF void \ CX##_del(CX* self) { \ while (self->last) CX##_erase_after_(self, self->last); \ @@ -196,50 +193,52 @@ STC_API size_t _clist_size(const clist_VOID* self); _c_clist_insert_after(self, CX, self->last, value); \ self->last = entry; \ } \ +\ STC_DEF void \ CX##_push_front(CX* self, Value value) { \ _c_clist_insert_after(self, CX, self->last, value); \ if (!self->last) self->last = entry; \ } \ +\ STC_DEF void \ CX##_emplace_n(CX *self, const CX##_rawvalue_t arr[], size_t n) { \ for (size_t i=0; ilast; \ + CX##_insert(CX* self, CX##_iter_t it, Value value) { \ + CX##_node_t* node = it.ref ? it._prev : self->last; \ _c_clist_insert_after(self, CX, node, value); \ - if (!self->last || !pos.ref) { \ - pos._prev = self->last ? self->last : entry; \ + if (!self->last || !it.ref) { \ + it._prev = self->last ? self->last : entry; \ self->last = entry; \ } \ - pos.ref = &entry->value; \ - return pos; \ + it.ref = &entry->value; \ + return it; \ } \ \ STC_DEF CX##_iter_t \ - CX##_erase_at(CX* self, CX##_iter_t pos) { \ - CX##_node_t *node = _clist_node(CX, pos.ref); \ - pos.ref = (node == self->last) ? NULL : &node->next->value; \ - CX##_erase_after_(self, pos._prev); \ - return pos; \ + CX##_erase_at(CX* self, CX##_iter_t it) { \ + CX##_node_t *node = _clist_node(CX, it.ref); \ + it.ref = (node == self->last) ? NULL : &node->next->value; \ + CX##_erase_after_(self, it._prev); \ + return it; \ } \ \ STC_DEF CX##_iter_t \ - CX##_erase_range(CX* self, CX##_iter_t first, CX##_iter_t finish) { \ - CX##_node_t *node = first.ref ? first._prev : NULL, \ - *done = finish.ref ? _clist_node(CX, finish.ref) : NULL; \ + CX##_erase_range(CX* self, CX##_iter_t it1, CX##_iter_t it2) { \ + CX##_node_t *node = it1.ref ? it1._prev : NULL, \ + *done = it2.ref ? _clist_node(CX, it2.ref) : NULL; \ while (node && node->next != done) \ node = CX##_erase_after_(self, node); \ - return finish; \ + return it2; \ } \ \ STC_DEF CX##_iter_t \ - CX##_find_in_range(const CX* self, CX##_iter_t first, CX##_iter_t finish, RawValue val) { \ - c_foreach_4 (i, CX, first, finish) { \ - RawValue r = valueToRaw(i.ref); \ - if (valueCompareRaw(&r, &val) == 0) return i; \ + CX##_find_in_range(const CX* self, CX##_iter_t it1, CX##_iter_t it2, RawValue val) { \ + c_foreach_4 (it, CX, it1, it2) { \ + RawValue r = valueToRaw(it.ref); \ + if (valueCompareRaw(&r, &val) == 0) return it; \ } \ return CX##_end(self); \ } \ @@ -270,25 +269,25 @@ STC_API size_t _clist_size(const clist_VOID* self); } \ \ STC_DEF void \ - CX##_splice(CX* self, CX##_iter_t pos, CX* other) { \ + CX##_splice(CX* self, CX##_iter_t it, CX* other) { \ if (!self->last) \ self->last = other->last; \ else if (other->last) { \ - CX##_node_t *p = pos.ref ? pos._prev : self->last, *next = p->next; \ + CX##_node_t *p = it.ref ? it._prev : self->last, *next = p->next; \ p->next = other->last->next; \ other->last->next = next; \ - if (!pos.ref) self->last = other->last; \ + if (!it.ref) self->last = other->last; \ } \ other->last = NULL; \ } \ \ STC_DEF CX \ - CX##_split(CX* self, CX##_iter_t pos1, CX##_iter_t pos2) { \ + CX##_split(CX* self, CX##_iter_t it1, CX##_iter_t it2) { \ CX list = {NULL}; \ - if (pos1.ref == pos2.ref) return list; \ - CX##_node_t *p1 = pos1._prev, \ - *p2 = pos2.ref ? pos2._prev : self->last; \ - p1->next = p2->next, p2->next = _clist_node(CX, pos1.ref); \ + if (it1.ref == it2.ref) return list; \ + CX##_node_t *p1 = it1._prev, \ + *p2 = it2.ref ? it2._prev : self->last; \ + p1->next = p2->next, p2->next = _clist_node(CX, it1.ref); \ if (self->last == p2) self->last = (p1 == p2) ? NULL : p1; \ list.last = p2; \ return list; \ @@ -316,10 +315,10 @@ STC_API size_t _clist_size(const clist_VOID* self); STC_DEF size_t _clist_size(const clist_VOID* self) { - const clist_VOID_node_t *i = self->last; - if (!i) return 0; + const clist_VOID_node_t *node = self->last; + if (!node) return 0; size_t n = 1; - while ((i = i->next) != self->last) ++n; + while ((node = node->next) != self->last) ++n; return n; } diff --git a/stc/cmap.h b/stc/cmap.h index f3062400..ea4e577b 100644 --- a/stc/cmap.h +++ b/stc/cmap.h @@ -50,94 +50,84 @@ int main(void) { #include #include -#define _cmap_inits {NULL, NULL, 0, 0, 0.15f, 0.85f} -typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; - #define using_cmap(...) c_MACRO_OVERLOAD(using_cmap, __VA_ARGS__) #define using_cmap_3(X, Key, Mapped) \ - using_cmap_5(X, Key, Mapped, c_default_equals, c_default_hash) + using_cmap_5(X, Key, Mapped, c_default_equals, c_default_hash) #define using_cmap_5(X, Key, Mapped, keyEquals, keyHash) \ - using_cmap_7(X, Key, Mapped, keyEquals, keyHash, \ - c_trivial_del, c_trivial_fromraw) + using_cmap_7(X, Key, Mapped, keyEquals, keyHash, \ + c_trivial_del, c_trivial_fromraw) #define using_cmap_6(X, Key, Mapped, keyEquals, keyHash, mappedDel) \ - using_cmap_7(X, Key, Mapped, keyEquals, keyHash, \ - mappedDel, c_no_clone) + using_cmap_7(X, Key, Mapped, keyEquals, keyHash, \ + mappedDel, c_no_clone) #define using_cmap_7(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone) \ - using_cmap_9(X, Key, Mapped, keyEquals, keyHash, \ - mappedDel, mappedClone, c_trivial_toraw, Mapped) + using_cmap_9(X, Key, Mapped, keyEquals, keyHash, \ + mappedDel, mappedClone, c_trivial_toraw, Mapped) #define using_cmap_9(X, Key, Mapped, keyEquals, keyHash, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \ - _c_using_chash(cmap_##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) \ - _c_using_chash(cmap_##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__) #define using_cmap_keydef_7(X, Key, Mapped, keyEquals, keyHash, keyDel, keyClone) \ - using_cmap_keydef_9(X, Key, Mapped, keyEquals, keyHash, \ - keyDel, keyClone, c_trivial_toraw, Key) + using_cmap_keydef_9(X, Key, Mapped, keyEquals, keyHash, \ + keyDel, keyClone, c_trivial_toraw, Key) #define using_cmap_keydef_9(X, Key, Mapped, keyEqualsRaw, keyHashRaw, \ 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) + _c_using_chash(cmap_##X, cmap_, Key, Mapped, keyEqualsRaw, keyHashRaw, \ + c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Mapped, \ + keyDel, keyFromRaw, keyToRaw, RawKey) #define using_cmap_str() \ - _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*) + _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__) #define using_cmap_strkey_2(X, Mapped) \ - using_cmap_strkey_4(X, Mapped, c_trivial_del, c_trivial_fromraw) + using_cmap_strkey_4(X, Mapped, c_trivial_del, c_trivial_fromraw) #define using_cmap_strkey_3(X, Mapped, mappedDel) \ - using_cmap_strkey_4(X, Mapped, mappedDel, c_no_clone) + using_cmap_strkey_4(X, Mapped, mappedDel, c_no_clone) #define using_cmap_strkey_4(X, Mapped, mappedDel, mappedClone) \ - _c_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) \ - _c_using_chash_strkey(X, cmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) + _c_using_chash_strkey(X, cmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) #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*) + _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__) #define using_cmap_strval_2(X, Key) \ - using_cmap_strval_4(X, Key, c_default_equals, c_default_hash) + using_cmap_strval_4(X, Key, c_default_equals, c_default_hash) #define using_cmap_strval_4(X, Key, keyEquals, keyHash) \ - using_cmap_strval_6(X, Key, keyEquals, keyHash, c_trivial_del, c_trivial_fromraw) + using_cmap_strval_6(X, Key, keyEquals, keyHash, c_trivial_del, c_trivial_fromraw) #define using_cmap_strval_5(X, Key, keyEquals, keyHash, keyDel) \ - using_cmap_strval_6(X, Key, keyEquals, keyHash, keyDel, c_no_clone) + using_cmap_strval_6(X, Key, keyEquals, keyHash, keyDel, c_no_clone) #define using_cmap_strval_6(X, Key, keyEquals, keyHash, keyDel, keyClone) \ - using_cmap_strval_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_trivial_toraw, Key) + 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) \ - _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__ -#define KEY_REF_cmap_(vp) (&(vp)->first) -#ifndef CMAP_SIZE_T -#define CMAP_SIZE_T uint32_t -#endif + _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 _c_using_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \ @@ -177,57 +167,45 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; uint8_t* _hx; \ } CX##_iter_t; \ \ - STC_INLINE CX \ - CX##_init(void) {CX m = _cmap_inits; return m;} \ - STC_INLINE bool \ - CX##_empty(CX m) {return m.size == 0;} \ - STC_INLINE size_t \ - CX##_size(CX m) {return (size_t) m.size;} \ + STC_API chash_bucket_t CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr); \ + STC_API CX##_result_t CX##_insert_entry_(CX* self, RawKey rkey); \ +\ + STC_INLINE CX CX##_init(void) {CX m = _cmap_inits; return m;} \ + STC_API CX CX##_with_capacity(size_t cap); \ + STC_API CX CX##_clone(CX map); \ + STC_API void CX##_reserve(CX* self, size_t capacity); \ + STC_API void CX##_del(CX* self); \ + STC_API void CX##_clear(CX* self); \ + STC_INLINE bool CX##_empty(CX m) {return m.size == 0;} \ + STC_INLINE size_t CX##_size(CX m) {return (size_t) m.size;} \ + STC_INLINE size_t CX##_bucket_count(CX map) {return (size_t) map.bucket_count;} \ + STC_INLINE size_t CX##_capacity(CX map) \ + {return (size_t) (map.bucket_count*map.max_load_factor);} \ + STC_INLINE void CX##_swap(CX *map1, CX *map2) {c_swap(CX, *map1, *map2);} \ + STC_API CX##_iter_t CX##_find(const CX* self, RawKey rkey); \ + STC_INLINE bool CX##_contains(const CX* self, RawKey rkey) \ + {return self->size && self->_hashx[CX##_bucket_(self, &rkey).idx];} \ + STC_API void CX##_erase_entry(CX* self, CX##_value_t* val); \ +\ 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 \ CX##_value_del(CX##_value_t* val) { \ keyDel(KEY_REF_##C(val)); \ MAP_ONLY_##C( mappedDel(&val->second); ) \ } \ - STC_INLINE size_t \ - CX##_bucket_count(CX map) {return (size_t) map.bucket_count;} \ - STC_INLINE size_t \ - CX##_capacity(CX map) {return (size_t) (map.bucket_count*map.max_load_factor);} \ - STC_INLINE void \ - CX##_swap(CX *map1, CX *map2) {c_swap(CX, *map1, *map2);} \ +\ STC_INLINE void \ 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 CX \ - CX##_with_capacity(size_t cap); \ - STC_API CX \ - CX##_clone(CX map); \ - STC_API void \ - CX##_reserve(CX* self, size_t capacity); \ - STC_API void \ - CX##_del(CX* self); \ - STC_API void \ - CX##_clear(CX* self); \ -\ - STC_API CX##_result_t \ - CX##_insert_entry_(CX* self, RawKey rkey); \ - STC_API chash_bucket_t \ - CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr); \ -\ - STC_API CX##_iter_t \ - CX##_find(const CX* self, RawKey rkey); \ - STC_INLINE bool \ - CX##_contains(const CX* self, RawKey rkey) { \ - return self->size && self->_hashx[CX##_bucket_(self, &rkey).idx]; \ - } \ -\ + \ 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); \ @@ -237,6 +215,7 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; } \ return res; \ } \ +\ STC_INLINE void \ CX##_emplace_n(CX* self, const CX##_rawvalue_t arr[], size_t n) { \ for (size_t i=0; iref, *++it->_hx == 0)) ; \ } \ \ - STC_API void \ - CX##_erase_entry(CX* self, CX##_value_t* val); \ STC_INLINE size_t \ CX##_erase(CX* self, RawKey rkey) { \ if (self->size == 0) return 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 CX##_iter_t \ CX##_erase_at(CX* self, CX##_iter_t pos) { \ CX##_erase_entry(self, pos.ref); \ @@ -309,7 +287,17 @@ typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_t; _c_implement_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ keyDel, keyFromRaw, keyToRaw, RawKey) \ - typedef CX CX##_t + struct stc_trailing_semicolon + + +#define SET_ONLY_cmap_(...) +#define MAP_ONLY_cmap_(...) __VA_ARGS__ +#define KEY_REF_cmap_(vp) (&(vp)->first) +#ifndef CMAP_SIZE_T +#define CMAP_SIZE_T uint32_t +#endif +#define _cmap_inits {NULL, NULL, 0, 0, 0.15f, 0.85f} +typedef struct {size_t idx; uint_fast8_t hx;} chash_bucket_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) @@ -321,12 +309,14 @@ STC_INLINE uint64_t c_default_hash64(const void* data, size_t ignored) #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) -#define fastrange_uint32_t(x, n) ((size_t) (((uint32_t)(x)*(uint64_t)(n)) >> 32)) #ifdef c_umul128 -STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) {uint64_t l,h; c_umul128(x,n,&l,&h); return h;} +STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ + {uint64_t l, h; c_umul128(x, n, &l, &h); return h;} #endif +#define fastrange_uint32_t(x, n) ((size_t) (((uint32_t)(x)*(uint64_t)(n)) >> 32)) #define chash_index_(h, entryPtr) ((entryPtr) - (h).table) + #define _c_implement_chash(CX, C, Key, Mapped, keyEqualsRaw, keyHashRaw, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ keyDel, keyFromRaw, keyToRaw, RawKey) \ diff --git a/stc/cpque.h b/stc/cpque.h index 30197bd2..05a2295b 100644 --- a/stc/cpque.h +++ b/stc/cpque.h @@ -52,12 +52,12 @@ #define using_cpque(...) c_MACRO_OVERLOAD(using_cpque, __VA_ARGS__) #define using_cpque_2(X, ctype) \ - _c_using_cpque(cpque_##X, ctype, ctype##_value_compare) + _c_using_cpque(cpque_##X, ctype, ctype##_value_compare) #define using_cpque_3(X, ctype, valueCompare) \ - _c_using_cpque(cpque_##X, ctype, valueCompare) + _c_using_cpque(cpque_##X, ctype, valueCompare) #define _c_using_cpque(CX, ctype, valueCompare) \ - typedef ctype##_t CX; \ + typedef ctype CX; \ typedef ctype##_value_t CX##_value_t; \ typedef ctype##_rawvalue_t CX##_rawvalue_t; \ \ @@ -82,7 +82,8 @@ {CX##_push(self, ctype##_value_fromraw(raw));} \ STC_API void CX##_emplace_n(CX *self, const CX##_rawvalue_t arr[], size_t n); \ \ - _c_implement_cpque(CX, ctype, valueCompare) + _c_implement_cpque(CX, ctype, valueCompare) \ + struct stc_trailing_semicolon /* -------------------------- IMPLEMENTATION ------------------------- */ @@ -135,7 +136,6 @@ for (size_t i = 0; i < n; ++i) \ CX##_push(self, ctype##_value_fromraw(arr[i])); \ } \ - typedef CX CX##_t #else #define _c_implement_cpque(CX, ctype, valueCompare) diff --git a/stc/cqueue.h b/stc/cqueue.h index 464ce612..920b155e 100644 --- a/stc/cqueue.h +++ b/stc/cqueue.h @@ -57,10 +57,10 @@ #include "cdeq.h" #define using_cqueue(X, ctype) \ - _c_using_cqueue(cqueue_##X, ctype) + _c_using_cqueue(cqueue_##X, ctype) #define _c_using_cqueue(CX, ctype) \ - typedef ctype##_t CX; \ + typedef ctype CX; \ typedef ctype##_value_t CX##_value_t; \ typedef ctype##_rawvalue_t CX##_rawvalue_t; \ typedef ctype##_iter_t CX##_iter_t; \ @@ -88,6 +88,6 @@ STC_INLINE CX##_iter_t CX##_begin(const CX* self) {return ctype##_begin(self);} \ STC_INLINE CX##_iter_t CX##_end(const CX* self) {return ctype##_end(self);} \ STC_INLINE void CX##_next(CX##_iter_t* it) {ctype##_next(it);} \ - typedef CX CX##_t + struct stc_trailing_semicolon #endif diff --git a/stc/cset.h b/stc/cset.h index 8a3fc28b..cae23b80 100644 --- a/stc/cset.h +++ b/stc/cset.h @@ -48,22 +48,21 @@ int main(void) { c_MACRO_OVERLOAD(using_cset, __VA_ARGS__) #define using_cset_2(X, Key) \ - using_cset_4(X, Key, c_default_equals, c_default_hash) + using_cset_4(X, Key, c_default_equals, c_default_hash) #define using_cset_4(X, Key, keyEquals, keyHash) \ - using_cset_6(X, Key, keyEquals, keyHash, c_trivial_del, c_trivial_fromraw) + using_cset_6(X, Key, keyEquals, keyHash, c_trivial_del, c_trivial_fromraw) #define using_cset_5(X, Key, keyEquals, keyHash, keyDel) \ - using_cset_6(X, Key, keyEquals, keyHash, keyDel, c_no_clone) + using_cset_6(X, Key, keyEquals, keyHash, keyDel, c_no_clone) #define using_cset_6(X, Key, keyEquals, keyHash, keyDel, keyClone) \ - using_cset_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_trivial_toraw, Key) + using_cset_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_trivial_toraw, Key) #define using_cset_8(X, Key, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \ - _c_using_chash(cset_##X, cset_, Key, Key, keyEqualsRaw, keyHashRaw, \ - @@, @@, @@, void, \ - keyDel, keyFromRaw, keyToRaw, RawKey) + _c_using_chash(cset_##X, cset_, Key, Key, keyEqualsRaw, keyHashRaw, \ + @@, @@, @@, void, keyDel, keyFromRaw, keyToRaw, RawKey) /* cset_str: */ #define using_cset_str() \ - _c_using_chash_strkey(str, cset_, cstr_t, @@, @@, @@, void) + _c_using_chash_strkey(str, cset_, cstr_t, @@, @@, @@, void) #define SET_ONLY_cset_(...) __VA_ARGS__ #define MAP_ONLY_cset_(...) diff --git a/stc/csmap.h b/stc/csmap.h index b026d019..8694f6a7 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -52,77 +52,77 @@ int main(void) { #define using_csmap(...) c_MACRO_OVERLOAD(using_csmap, __VA_ARGS__) #define using_csmap_3(X, Key, Mapped) \ - using_csmap_4(X, Key, Mapped, c_default_compare) + using_csmap_4(X, Key, Mapped, c_default_compare) #define using_csmap_4(X, Key, Mapped, keyCompare) \ - using_csmap_6(X, Key, Mapped, keyCompare, c_trivial_del, c_trivial_fromraw) + using_csmap_6(X, Key, Mapped, keyCompare, c_trivial_del, c_trivial_fromraw) #define using_csmap_5(X, Key, Mapped, keyCompare, mappedDel) \ - using_csmap_6(X, Key, Mapped, keyCompare, mappedDel, c_no_clone) + using_csmap_6(X, Key, Mapped, keyCompare, mappedDel, c_no_clone) #define using_csmap_6(X, Key, Mapped, keyCompare, mappedDel, mappedClone) \ - using_csmap_8(X, Key, Mapped, keyCompare, mappedDel, mappedClone, c_trivial_toraw, Mapped) + using_csmap_8(X, Key, Mapped, keyCompare, mappedDel, mappedClone, c_trivial_toraw, Mapped) #define using_csmap_8(X, Key, Mapped, keyCompare, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \ - using_csmap_12(X, Key, Mapped, keyCompare, \ - mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ - c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Key) + using_csmap_12(X, Key, Mapped, keyCompare, \ + mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ + c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Key) #define using_csmap_12(X, Key, Mapped, keyCompareRaw, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ keyDel, keyFromRaw, keyToRaw, RawKey) \ - _c_using_aatree(csmap_##X, csmap_, Key, Mapped, keyCompareRaw, \ - mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ - keyDel, keyFromRaw, keyToRaw, RawKey) + _c_using_aatree(csmap_##X, csmap_, Key, Mapped, keyCompareRaw, \ + mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ + keyDel, keyFromRaw, keyToRaw, RawKey) #define using_csmap_keydef(...) c_MACRO_OVERLOAD(using_csmap_keydef, __VA_ARGS__) #define using_csmap_keydef_6(X, Key, Mapped, keyCompare, keyDel, keyClone) \ - using_csmap_keydef_8(X, Key, Mapped, keyCompare, \ - keyDel, keyClone, c_trivial_toraw, Key) + using_csmap_keydef_8(X, Key, Mapped, keyCompare, \ + keyDel, keyClone, c_trivial_toraw, Key) #define using_csmap_keydef_8(X, Key, Mapped, keyCompareRaw, \ - keyDel, keyFromRaw, keyToRaw, RawKey) \ - _c_using_aatree(csmap_##X, csmap_, Key, Mapped, keyCompareRaw, \ - c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Mapped, \ - keyDel, keyFromRaw, keyToRaw, RawKey) + keyDel, keyFromRaw, keyToRaw, RawKey) \ + _c_using_aatree(csmap_##X, csmap_, Key, Mapped, keyCompareRaw, \ + c_trivial_del, c_trivial_fromraw, c_trivial_toraw, Mapped, \ + keyDel, keyFromRaw, keyToRaw, RawKey) #define using_csmap_str() \ - _c_using_aatree(csmap_str, csmap_, cstr_t, cstr_t, cstr_compare_raw, \ - cstr_del, cstr_from, cstr_c_str, const char*, \ - cstr_del, cstr_from, cstr_c_str, const char*) + _c_using_aatree(csmap_str, csmap_, cstr_t, cstr_t, cstr_compare_raw, \ + cstr_del, cstr_from, cstr_c_str, const char*, \ + cstr_del, cstr_from, cstr_c_str, const char*) #define using_csmap_strkey(...) c_MACRO_OVERLOAD(using_csmap_strkey, __VA_ARGS__) #define using_csmap_strkey_2(X, Mapped) \ - using_csmap_strkey_4(X, Mapped, c_trivial_del, c_trivial_fromraw) + using_csmap_strkey_4(X, Mapped, c_trivial_del, c_trivial_fromraw) #define using_csmap_strkey_3(X, Mapped, mappedDel) \ - using_csmap_strkey_4(X, Mapped, mappedDel, c_no_clone) + using_csmap_strkey_4(X, Mapped, mappedDel, c_no_clone) #define using_csmap_strkey_4(X, Mapped, mappedDel, mappedClone) \ - _c_using_aatree_strkey(X, csmap_, Mapped, mappedDel, mappedClone, c_trivial_toraw, Mapped) + _c_using_aatree_strkey(X, csmap_, Mapped, mappedDel, mappedClone, c_trivial_toraw, Mapped) #define using_csmap_strkey_6(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \ - _c_using_aatree_strkey(X, csmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) + _c_using_aatree_strkey(X, csmap_, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) #define _c_using_aatree_strkey(X, C, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped) \ - _c_using_aatree(C##X, C, cstr_t, Mapped, cstr_compare_raw, \ - mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ - cstr_del, cstr_from, cstr_c_str, const char*) + _c_using_aatree(C##X, C, cstr_t, Mapped, cstr_compare_raw, \ + mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ + cstr_del, cstr_from, cstr_c_str, const char*) #define using_csmap_strval(...) c_MACRO_OVERLOAD(using_csmap_strval, __VA_ARGS__) #define using_csmap_strval_2(X, Key) \ - using_csmap_strval_3(X, Key, c_default_compare) + using_csmap_strval_3(X, Key, c_default_compare) #define using_csmap_strval_3(X, Key, keyCompare) \ - using_csmap_strval_5(X, Key, keyCompare, c_trivial_del, c_trivial_fromraw) + using_csmap_strval_5(X, Key, keyCompare, c_trivial_del, c_trivial_fromraw) #define using_csmap_strval_4(X, Key, keyCompare, keyDel) \ - using_csmap_strval_5(X, Key, keyCompare, keyDel, c_no_clone) + using_csmap_strval_5(X, Key, keyCompare, keyDel, c_no_clone) #define using_csmap_strval_5(X, Key, keyCompare, keyDel, keyClone) \ - using_csmap_strval_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key) + using_csmap_strval_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key) #define using_csmap_strval_7(X, Key, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \ - _c_using_aatree(csmap_##X, csmap_, Key, cstr_t, keyCompareRaw, \ - cstr_del, cstr_from, cstr_c_str, const char*, \ - keyDel, keyFromRaw, keyToRaw, RawKey) + _c_using_aatree(csmap_##X, csmap_, Key, cstr_t, keyCompareRaw, \ + cstr_del, cstr_from, cstr_c_str, const char*, \ + keyDel, keyFromRaw, keyToRaw, RawKey) #define SET_ONLY_csmap_(...) #define MAP_ONLY_csmap_(...) __VA_ARGS__ @@ -294,19 +294,19 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; _c_implement_aatree(CX, C, Key, Mapped, keyCompareRaw, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ keyDel, keyFromRaw, keyToRaw, RawKey) \ - typedef CX CX##_t + struct stc_trailing_semicolon /* -------------------------- IMPLEMENTATION ------------------------- */ #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) -static struct csmap_rep _smap_inits = {0, 0, 0, 0}; +static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; #define _c_implement_aatree(CX, C, Key, Mapped, keyCompareRaw, \ mappedDel, mappedFromRaw, mappedToRaw, RawMapped, \ keyDel, keyFromRaw, keyToRaw, RawKey) \ STC_DEF CX \ CX##_init(void) { \ - CX tree = {(CX##_node_t *) _smap_inits.nodes}; \ + CX tree = {(CX##_node_t *) _csmap_inits.nodes}; \ return tree; \ } \ \ diff --git a/stc/csptr.h b/stc/csptr.h index feb89b5a..382ae59c 100644 --- a/stc/csptr.h +++ b/stc/csptr.h @@ -87,65 +87,77 @@ typedef long atomic_count_t; #define using_csptr(...) c_MACRO_OVERLOAD(using_csptr, __VA_ARGS__) #define using_csptr_2(X, Value) \ - using_csptr_3(X, Value, c_default_compare) - + using_csptr_3(X, Value, c_default_compare) #define using_csptr_3(X, Value, valueCompare) \ - using_csptr_4(X, Value, valueCompare, c_trivial_del) + using_csptr_4(X, Value, valueCompare, c_trivial_del) +#define using_csptr_4(X, Value, valueCompare, valueDel) \ + _c_using_csptr(csptr_##X, Value, valueCompare, valueDel) + -#define using_csptr_4(X, Value, valueCompare, valueDel) \ - typedef Value csptr_##X##_value_t; \ - typedef struct { csptr_##X##_value_t* get; atomic_count_t* use_count; } csptr_##X; \ +#define _c_using_csptr(CX, Value, valueCompare, valueDel) \ + typedef Value CX##_value_t; \ +\ + typedef struct { \ + CX##_value_t* get; \ + atomic_count_t* use_count; \ + } CX; \ \ - STC_INLINE csptr_##X \ - csptr_##X##_from(csptr_##X##_value_t* p) { \ - csptr_##X ptr = {p}; \ + STC_INLINE CX \ + CX##_from(CX##_value_t* p) { \ + CX ptr = {p}; \ if (p) *(ptr.use_count = c_new_1(atomic_count_t)) = 1; \ return ptr; \ } \ - STC_INLINE csptr_##X \ - csptr_##X##_make(csptr_##X##_value_t val) { \ - csptr_##X ptr = {c_new_1(csptr_##X##_value_t), c_new_1(atomic_count_t)}; \ +\ + STC_INLINE CX \ + CX##_make(CX##_value_t val) { \ + CX ptr = {c_new_1(CX##_value_t), c_new_1(atomic_count_t)}; \ *ptr.get = val, *ptr.use_count = 1; return ptr; \ } \ - STC_INLINE csptr_##X \ - csptr_##X##_clone(csptr_##X ptr) { \ +\ + STC_INLINE CX \ + CX##_clone(CX ptr) { \ if (ptr.use_count) atomic_increment(ptr.use_count); \ return ptr; \ } \ - STC_INLINE csptr_##X \ - csptr_##X##_move(csptr_##X* self) { \ - csptr_##X ptr = *self; \ +\ + STC_INLINE CX \ + CX##_move(CX* self) { \ + CX ptr = *self; \ self->get = NULL, self->use_count = NULL; \ return ptr; \ } \ \ STC_INLINE void \ - csptr_##X##_del(csptr_##X* self) { \ + CX##_del(CX* self) { \ if (self->use_count && atomic_decrement(self->use_count) == 0) { \ - c_free(self->use_count); \ valueDel(self->get); \ + c_free(self->use_count); \ c_free(self->get); \ } \ } \ +\ STC_INLINE void \ - csptr_##X##_reset(csptr_##X* self) { \ - csptr_##X##_del(self); \ + CX##_reset(CX* self) { \ + CX##_del(self); \ self->use_count = NULL, self->get = NULL; \ } \ +\ STC_INLINE void \ - csptr_##X##_reset_to(csptr_##X* self, csptr_##X##_value_t* p) { \ - csptr_##X##_del(self); \ - *self = csptr_##X##_from(p); \ + CX##_reset_to(CX* self, CX##_value_t* p) { \ + CX##_del(self); \ + *self = CX##_from(p); \ } \ \ STC_INLINE int \ - csptr_##X##_compare(csptr_##X* x, csptr_##X* y) { \ + CX##_compare(CX* x, CX* y) { \ return valueCompare(x->get, y->get); \ } \ +\ STC_INLINE bool \ - csptr_##X##_equals(csptr_##X* x, csptr_##X* y) { \ + CX##_equals(CX* x, CX* y) { \ return valueCompare(x->get, y->get) == 0; \ } \ - typedef csptr_##X csptr_##X##_t + struct stc_trailing_semicolon #endif diff --git a/stc/csset.h b/stc/csset.h index 774a451a..7d02b055 100644 --- a/stc/csset.h +++ b/stc/csset.h @@ -45,25 +45,24 @@ int main(void) { #include "csmap.h" -/* csset: */ #define using_csset(...) \ c_MACRO_OVERLOAD(using_csset, __VA_ARGS__) #define using_csset_2(X, Key) \ - using_csset_3(X, Key, c_default_compare) + using_csset_3(X, Key, c_default_compare) #define using_csset_3(X, Key, keyCompare) \ - using_csset_5(X, Key, keyCompare, c_trivial_del, c_trivial_fromraw) + using_csset_5(X, Key, keyCompare, c_trivial_del, c_trivial_fromraw) #define using_csset_4(X, Key, keyCompare, keyDel) \ - using_csset_5(X, Key, keyCompare, keyDel, c_no_clone) + using_csset_5(X, Key, keyCompare, keyDel, c_no_clone) #define using_csset_5(X, Key, keyCompare, keyDel, keyClone) \ - using_csset_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key) + using_csset_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key) #define using_csset_7(X, Key, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \ - _c_using_aatree(csset_##X, csset_, Key, Key, keyCompareRaw, \ - @@, @@, @@, void, keyDel, keyFromRaw, keyToRaw, RawKey) + _c_using_aatree(csset_##X, csset_, Key, Key, keyCompareRaw, \ + @@, @@, @@, void, keyDel, keyFromRaw, keyToRaw, RawKey) #define using_csset_str() \ - _c_using_aatree_strkey(str, csset_, cstr_t, @@, @@, @@, void) + _c_using_aatree_strkey(str, csset_, cstr_t, @@, @@, @@, void) #define SET_ONLY_csset_(...) __VA_ARGS__ #define MAP_ONLY_csset_(...) diff --git a/stc/cstack.h b/stc/cstack.h index cc5372ec..89a262dd 100644 --- a/stc/cstack.h +++ b/stc/cstack.h @@ -46,10 +46,10 @@ #include "cvec.h" #define using_cstack(X, ctype) \ - _c_using_cstack(cstack_##X, ctype) + _c_using_cstack(cstack_##X, ctype) #define _c_using_cstack(CX, ctype) \ - typedef ctype##_t CX; \ + typedef ctype CX; \ typedef ctype##_value_t CX##_value_t; \ typedef ctype##_rawvalue_t CX##_rawvalue_t; \ typedef ctype##_iter_t CX##_iter_t; \ @@ -76,7 +76,6 @@ STC_INLINE CX##_iter_t CX##_begin(const CX* self) {return ctype##_begin(self);} \ STC_INLINE CX##_iter_t CX##_end(const CX* self) {return ctype##_end(self);} \ STC_INLINE void CX##_next(CX##_iter_t* it) {ctype##_next(it);} \ - \ - typedef CX CX##_t + struct stc_trailing_semicolon #endif diff --git a/stc/cvec.h b/stc/cvec.h index a23dcb54..59bfd889 100644 --- a/stc/cvec.h +++ b/stc/cvec.h @@ -29,17 +29,17 @@ #define using_cvec(...) c_MACRO_OVERLOAD(using_cvec, __VA_ARGS__) #define using_cvec_2(X, Value) \ - using_cvec_3(X, Value, c_default_compare) + using_cvec_3(X, Value, c_default_compare) #define using_cvec_3(X, Value, valueCompare) \ - using_cvec_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) + using_cvec_5(X, Value, valueCompare, c_trivial_del, c_trivial_fromraw) #define using_cvec_4(X, Value, valueCompare, valueDel) \ - using_cvec_5(X, Value, valueCompare, valueDel, c_no_clone) + using_cvec_5(X, Value, valueCompare, valueDel, c_no_clone) #define using_cvec_5(X, Value, valueCompare, valueDel, valueClone) \ - using_cvec_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) + using_cvec_7(X, Value, valueCompare, valueDel, valueClone, c_trivial_toraw, Value) #define using_cvec_7(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - _c_using_cvec(cvec_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) + _c_using_cvec(cvec_##X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) #define using_cvec_str() \ - _c_using_cvec(cvec_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) + _c_using_cvec(cvec_str, cstr_t, cstr_compare_raw, cstr_del, cstr_from, cstr_c_str, const char*) #define typedefs_cvec(CX, Value, RawValue) \ typedef Value CX##_value_t; \ @@ -68,7 +68,6 @@ typedef int (*c_cmp_fn)(const void*, const void*); STC_API void CX##_reserve(CX* self, size_t cap); \ STC_API void CX##_resize(CX* self, size_t size, Value fill_val); \ STC_INLINE void CX##_swap(CX* a, CX* b) {c_swap(CX, *a, *b);} \ -\ STC_API void CX##_emplace_n(CX *self, const CX##_rawvalue_t arr[], size_t size); \ STC_API void CX##_push_back(CX* self, Value value); \ STC_INLINE void CX##_emplace_back(CX* self, RawValue raw) \ @@ -105,20 +104,20 @@ typedef int (*c_cmp_fn)(const void*, const void*); CX##_insert_range_p(CX* self, CX##_value_t* pos, const CX##_value_t* pfirst, const CX##_value_t* pfinish); \ \ STC_INLINE CX##_iter_t \ - CX##_insert_range(CX* self, CX##_iter_t pos, CX##_iter_t first, CX##_iter_t finish) { \ - return CX##_insert_range_p(self, pos.ref, first.ref, finish.ref); \ + CX##_insert_range(CX* self, CX##_iter_t it, CX##_iter_t it1, CX##_iter_t it2) { \ + return CX##_insert_range_p(self, it.ref, it1.ref, it2.ref); \ } \ STC_INLINE CX##_iter_t \ - CX##_insert_at(CX* self, CX##_iter_t pos, Value value) { \ - return CX##_insert_range_p(self, pos.ref, &value, &value + 1); \ + CX##_insert_at(CX* self, CX##_iter_t it, Value value) { \ + return CX##_insert_range_p(self, it.ref, &value, &value + 1); \ } \ STC_INLINE CX##_iter_t \ CX##_insert(CX* self, size_t idx, Value value) { \ return CX##_insert_range_p(self, self->data + idx, &value, &value + 1); \ } \ STC_INLINE CX##_iter_t \ - CX##_emplace_at(CX* self, CX##_iter_t pos, RawValue raw) { \ - return CX##_insert_at(self, pos, valueFromRaw(raw)); \ + CX##_emplace_at(CX* self, CX##_iter_t it, RawValue raw) { \ + return CX##_insert_at(self, it, valueFromRaw(raw)); \ } \ STC_INLINE CX##_iter_t \ CX##_emplace(CX* self, size_t idx, RawValue raw) { \ @@ -129,12 +128,12 @@ typedef int (*c_cmp_fn)(const void*, const void*); CX##_erase_range_p(CX* self, CX##_value_t* first, CX##_value_t* finish); \ \ STC_INLINE CX##_iter_t \ - CX##_erase_range(CX* self, CX##_iter_t first, CX##_iter_t finish) { \ - return CX##_erase_range_p(self, first.ref, finish.ref); \ + CX##_erase_range(CX* self, CX##_iter_t it1, CX##_iter_t it2) { \ + return CX##_erase_range_p(self, it1.ref, it2.ref); \ } \ STC_INLINE CX##_iter_t \ - CX##_erase_at(CX* self, CX##_iter_t pos) { \ - return CX##_erase_range_p(self, pos.ref, pos.ref + 1); \ + CX##_erase_at(CX* self, CX##_iter_t it) { \ + return CX##_erase_range_p(self, it.ref, it.ref + 1); \ } \ STC_INLINE CX##_iter_t \ CX##_erase(CX* self, size_t idx, size_t n) { \ @@ -166,7 +165,7 @@ typedef int (*c_cmp_fn)(const void*, const void*); CX##_index(CX vec, CX##_iter_t it) {return it.ref - vec.data;} \ \ STC_API CX##_iter_t \ - CX##_find_in_range(CX##_iter_t first, CX##_iter_t finish, RawValue raw); \ + CX##_find_in_range(CX##_iter_t it1, CX##_iter_t it2, RawValue raw); \ STC_INLINE CX##_iter_t \ CX##_find(const CX* self, RawValue raw) { \ return CX##_find_in_range(CX##_begin(self), CX##_end(self), raw); \ @@ -189,7 +188,7 @@ typedef int (*c_cmp_fn)(const void*, const void*); } \ \ _c_implement_cvec(CX, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue) \ - typedef CX CX##_t + struct stc_trailing_semicolon /* -------------------------- IMPLEMENTATION ------------------------- */ -- cgit v1.2.3