summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-03-10 23:35:09 +0100
committerTyge Løvset <[email protected]>2021-03-10 23:35:09 +0100
commit00a6264d9e888e1fac3c51f14fdaaaf20633b84d (patch)
treeb44194717c2272e4a5be6872fd9cd7d73e943a57 /examples
parent6cc5a8a96304eb270babbb10161c560dcded3fe3 (diff)
downloadSTC-modified-00a6264d9e888e1fac3c51f14fdaaaf20633b84d.tar.gz
STC-modified-00a6264d9e888e1fac3c51f14fdaaaf20633b84d.zip
Reduced macro token-pasting a lot in maps.
Diffstat (limited to 'examples')
-rw-r--r--examples/csmap_v1.h314
1 files changed, 157 insertions, 157 deletions
diff --git a/examples/csmap_v1.h b/examples/csmap_v1.h
index c2489df4..5adbed7d 100644
--- a/examples/csmap_v1.h
+++ b/examples/csmap_v1.h
@@ -61,7 +61,7 @@ int main(void) {
#define using_csmap_10(X, Key, Mapped, keyCompareRaw, mappedDel, mappedClone, \
keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CBST(X, csmap, Key, Mapped, keyCompareRaw, mappedDel, keyDel, \
+ _using_CBST(X, csmap_, Key, Mapped, keyCompareRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedClone, c_trivial_toraw, Mapped)
/* csset: */
@@ -78,24 +78,24 @@ int main(void) {
using_csset_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key)
#define using_csset_7(X, Key, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CBST(X, csset, Key, Key, keyCompareRaw, @@, keyDel, \
+ _using_CBST(X, csset_, Key, Key, keyCompareRaw, @@, keyDel, \
keyFromRaw, keyToRaw, RawKey, @@, @@, void)
/* csset_str, csmap_str, csmap_strkey, csmap_strval: */
#define using_csset_str() \
- _using_CBST_strkey(str, csset, cstr_t, @@, @@)
+ _using_CBST_strkey(str, csset_, cstr_t, @@, @@)
#define using_csmap_str() \
- _using_CBST(str, csmap, cstr_t, cstr_t, cstr_compare_raw, cstr_del, cstr_del, \
+ _using_CBST(str, csmap_, cstr_t, cstr_t, cstr_compare_raw, cstr_del, cstr_del, \
cstr_from, cstr_c_str, const char*, 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_CBST_strkey(X, csmap, Mapped, c_trivial_del, c_trivial_fromraw)
+ _using_CBST_strkey(X, csmap_, Mapped, c_trivial_del, c_trivial_fromraw)
#define using_csmap_strkey_4(X, Mapped, mappedDel, mappedClone) \
- _using_CBST_strkey(X, csmap, Mapped, mappedDel, mappedClone)
+ _using_CBST_strkey(X, csmap_, Mapped, mappedDel, mappedClone)
#define _using_CBST_strkey(X, C, Mapped, mappedDel, mappedClone) \
_using_CBST(X, C, cstr_t, Mapped, cstr_compare_raw, mappedDel, cstr_del, \
@@ -114,36 +114,36 @@ int main(void) {
using_csmap_strval_7(X, Key, keyCompare, keyDel, keyClone, c_trivial_toraw, Key)
#define using_csmap_strval_7(X, Key, keyCompare, keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CBST(X, csmap, Key, cstr_t, keyCompare, cstr_del, keyDel, \
+ _using_CBST(X, csmap_, Key, cstr_t, keyCompare, cstr_del, keyDel, \
keyFromRaw, keyToRaw, RawKey, cstr_from, cstr_c_str, const char*)
-#define SET_ONLY_csset(...) __VA_ARGS__
-#define SET_ONLY_csmap(...)
-#define MAP_ONLY_csset(...)
-#define MAP_ONLY_csmap(...) __VA_ARGS__
-#define KEY_REF_csset(vp) (vp)
-#define KEY_REF_csmap(vp) (&(vp)->first)
+#define SET_ONLY_csset_(...) __VA_ARGS__
+#define SET_ONLY_csmap_(...)
+#define MAP_ONLY_csset_(...)
+#define MAP_ONLY_csmap_(...) __VA_ARGS__
+#define KEY_REF_csset_(vp) (vp)
+#define KEY_REF_csmap_(vp) (&(vp)->first)
#define _using_CBST_types(X, C, Key, Mapped) \
- typedef Key C##_##X##_key_t; \
- typedef Mapped C##_##X##_mapped_t; \
+ typedef Key C##X##_key_t; \
+ typedef Mapped C##X##_mapped_t; \
\
- typedef SET_ONLY_##C( C##_##X##_key_t ) \
- MAP_ONLY_##C( struct {C##_##X##_key_t first; \
- C##_##X##_mapped_t second;} ) \
- C##_##X##_value_t; \
+ typedef SET_ONLY_##C( C##X##_key_t ) \
+ MAP_ONLY_##C( struct {C##X##_key_t first; \
+ C##X##_mapped_t second;} ) \
+ C##X##_value_t; \
\
- typedef struct C##_##X##_node { \
- struct C##_##X##_node *link[2]; \
+ typedef struct C##X##_node { \
+ struct C##X##_node *link[2]; \
uint8_t level; \
- C##_##X##_value_t value; \
- } C##_##X##_node_t; \
+ C##X##_value_t value; \
+ } C##X##_node_t; \
\
typedef struct { \
- C##_##X##_value_t *ref; \
+ C##X##_value_t *ref; \
int _top; \
- C##_##X##_node_t *_tn, *_st[48]; \
- } C##_##X##_iter_t
+ C##X##_node_t *_tn, *_st[48]; \
+ } C##X##_iter_t
#define _using_CBST(X, C, Key, Mapped, keyCompareRaw, mappedDel, keyDel, \
@@ -151,79 +151,79 @@ int main(void) {
_using_CBST_types(X, C, Key, Mapped); \
\
typedef struct { \
- C##_##X##_node_t* root; \
+ C##X##_node_t* root; \
size_t size; \
- } C##_##X; \
+ } C##X; \
\
- typedef RawKey C##_##X##_rawkey_t; \
- typedef RawMapped C##_##X##_rawmapped_t; \
- typedef SET_ONLY_##C( C##_##X##_rawkey_t ) \
- MAP_ONLY_##C( struct {C##_##X##_rawkey_t first; \
- C##_##X##_rawmapped_t second;} ) \
- C##_##X##_rawvalue_t; \
+ typedef RawKey C##X##_rawkey_t; \
+ typedef RawMapped C##X##_rawmapped_t; \
+ typedef SET_ONLY_##C( C##X##_rawkey_t ) \
+ MAP_ONLY_##C( struct {C##X##_rawkey_t first; \
+ C##X##_rawmapped_t second;} ) \
+ C##X##_rawvalue_t; \
\
typedef struct { \
- C##_##X##_value_t *first; \
+ C##X##_value_t *first; \
bool second; \
- } C##_##X##_result_t; \
+ } C##X##_result_t; \
\
- STC_API C##_##X \
- C##_##X##_init(void); \
+ STC_API C##X \
+ C##X##_init(void); \
STC_INLINE bool \
- C##_##X##_empty(C##_##X m) {return m.size == 0;} \
+ C##X##_empty(C##X m) {return m.size == 0;} \
STC_INLINE size_t \
- C##_##X##_size(C##_##X m) {return m.size;} \
+ C##X##_size(C##X m) {return m.size;} \
\
STC_API void \
- C##_##X##_del_r_(C##_##X##_node_t* tn); \
+ C##X##_del_r_(C##X##_node_t* tn); \
\
STC_INLINE void \
- C##_##X##_del(C##_##X* self) {C##_##X##_del_r_(self->root);} \
+ C##X##_del(C##X* self) {C##X##_del_r_(self->root);} \
STC_INLINE void \
- C##_##X##_clear(C##_##X* self) {C##_##X##_del(self); *self = C##_##X##_init();} \
+ C##X##_clear(C##X* self) {C##X##_del(self); *self = C##X##_init();} \
STC_INLINE void \
- C##_##X##_swap(C##_##X* a, C##_##X* b) {c_swap(C##_##X, *a, *b);} \
+ C##X##_swap(C##X* a, C##X* b) {c_swap(C##X, *a, *b);} \
\
STC_INLINE void \
- C##_##X##_value_del(C##_##X##_value_t* val) { \
+ C##X##_value_del(C##X##_value_t* val) { \
keyDel(KEY_REF_##C(val)); \
MAP_ONLY_##C( mappedDel(&val->second); ) \
} \
- STC_INLINE C##_##X##_value_t \
- C##_##X##_value_clone(C##_##X##_value_t val) { \
+ STC_INLINE C##X##_value_t \
+ C##X##_value_clone(C##X##_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_API C##_##X##_node_t* C##_##X##_clone_r_(C##_##X##_node_t *tn); \
- STC_INLINE C##_##X \
- C##_##X##_clone(C##_##X bst) { \
- C##_##X clone = {C##_##X##_clone_r_(bst.root), bst.size}; \
+ STC_API C##X##_node_t* C##X##_clone_r_(C##X##_node_t *tn); \
+ STC_INLINE C##X \
+ C##X##_clone(C##X bst) { \
+ C##X clone = {C##X##_clone_r_(bst.root), bst.size}; \
return clone; \
} \
\
- STC_API C##_##X##_value_t* \
- C##_##X##_find_it(const C##_##X* self, RawKey rkey, C##_##X##_iter_t* out); \
+ STC_API C##X##_value_t* \
+ C##X##_find_it(const C##X* self, RawKey rkey, C##X##_iter_t* out); \
\
- STC_INLINE C##_##X##_iter_t \
- C##_##X##_find(const C##_##X* self, RawKey rkey) { \
- C##_##X##_iter_t it; \
- C##_##X##_find_it(self, rkey, &it); \
+ STC_INLINE C##X##_iter_t \
+ C##X##_find(const C##X* self, RawKey rkey) { \
+ C##X##_iter_t it; \
+ C##X##_find_it(self, rkey, &it); \
return it; \
} \
STC_INLINE bool \
- C##_##X##_contains(const C##_##X* self, RawKey rkey) { \
- C##_##X##_iter_t it; \
- return C##_##X##_find_it(self, rkey, &it) != NULL; \
+ C##X##_contains(const C##X* self, RawKey rkey) { \
+ C##X##_iter_t it; \
+ return C##X##_find_it(self, rkey, &it) != NULL; \
} \
\
- STC_API C##_##X##_result_t \
- C##_##X##_insert_entry_(C##_##X* self, RawKey rkey); \
+ STC_API C##X##_result_t \
+ C##X##_insert_entry_(C##X* self, RawKey rkey); \
\
- 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 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); \
if (res.second) { \
*KEY_REF_##C(res.first) = keyFromRaw(rkey); \
MAP_ONLY_##C(res.first->second = mappedFromRaw(rmapped);) \
@@ -231,108 +231,108 @@ int main(void) {
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); ) \
+ 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); ) \
} \
\
- 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 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)); \
if (res.second) {*KEY_REF_##C(res.first) = key; MAP_ONLY_##C( res.first->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 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)); \
if (res.second) res.first->first = key; \
else {keyDel(&key); mappedDel(&res.first->second);} \
res.first->second = mapped; return res; \
} \
- STC_INLINE C##_##X##_result_t \
- C##_##X##_put(C##_##X* self, Key k, Mapped m) { \
- return C##_##X##_insert_or_assign(self, k, m); \
+ STC_INLINE C##X##_result_t \
+ C##X##_put(C##X* self, Key k, Mapped m) { \
+ return C##X##_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 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); \
if (res.second) res.first->first = keyFromRaw(rkey); \
else mappedDel(&res.first->second); \
res.first->second = mappedFromRaw(rmapped); return res; \
} \
- STC_INLINE C##_##X##_mapped_t* \
- C##_##X##_at(const C##_##X* self, RawKey rkey) { \
- C##_##X##_iter_t it; \
- return &C##_##X##_find_it(self, rkey, &it)->second; \
+ STC_INLINE C##X##_mapped_t* \
+ C##X##_at(const C##X* self, RawKey rkey) { \
+ C##X##_iter_t it; \
+ return &C##X##_find_it(self, rkey, &it)->second; \
}) \
\
- STC_INLINE C##_##X##_value_t* \
- C##_##X##_front(const C##_##X* self) { \
- C##_##X##_node_t *tn = self->root; \
+ STC_INLINE C##X##_value_t* \
+ C##X##_front(const C##X* self) { \
+ C##X##_node_t *tn = self->root; \
while (tn->link[0]->level) tn = tn->link[0]; \
return &tn->value; \
} \
- STC_INLINE C##_##X##_value_t* \
- C##_##X##_back(const C##_##X* self) { \
- C##_##X##_node_t *tn = self->root; \
+ STC_INLINE C##X##_value_t* \
+ C##X##_back(const C##X* self) { \
+ C##X##_node_t *tn = self->root; \
while (tn->link[1]->level) tn = tn->link[1]; \
return &tn->value; \
} \
\
STC_API void \
- C##_##X##_next(C##_##X##_iter_t* it); \
+ C##X##_next(C##X##_iter_t* it); \
\
- STC_INLINE C##_##X##_iter_t \
- C##_##X##_begin(const C##_##X* self) { \
- C##_##X##_iter_t it = {NULL, 0, self->root}; \
- C##_##X##_next(&it); return it; \
+ STC_INLINE C##X##_iter_t \
+ C##X##_begin(const C##X* self) { \
+ C##X##_iter_t it = {NULL, 0, self->root}; \
+ C##X##_next(&it); return it; \
} \
- STC_INLINE C##_##X##_iter_t \
- C##_##X##_end(const C##_##X* self) {\
- C##_##X##_iter_t it = {NULL}; return it; \
+ STC_INLINE C##X##_iter_t \
+ C##X##_end(const C##X* self) {\
+ C##X##_iter_t it = {NULL}; return it; \
} \
- STC_INLINE C##_##X##_mapped_t* \
- C##_##X##_itval(C##_##X##_iter_t it) {return SET_ONLY_##C( it.ref ) \
+ 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 C##_##X##_node_t* \
- C##_##X##_erase_r_(C##_##X##_node_t *tn, const C##_##X##_rawkey_t* rkey, int *erased); \
+ STC_API C##X##_node_t* \
+ C##X##_erase_r_(C##X##_node_t *tn, const C##X##_rawkey_t* rkey, int *erased); \
\
STC_INLINE size_t \
- C##_##X##_erase(C##_##X* self, RawKey rkey) { \
+ C##X##_erase(C##X* self, RawKey rkey) { \
int erased = 0; \
- self->root = C##_##X##_erase_r_(self->root, &rkey, &erased); \
+ self->root = C##X##_erase_r_(self->root, &rkey, &erased); \
self->size -= erased; return erased; \
} \
STC_INLINE size_t \
- C##_##X##_erase_at(C##_##X* self, C##_##X##_iter_t pos) { \
- return C##_##X##_erase(self, keyToRaw(KEY_REF_##C(pos.ref))); \
+ C##X##_erase_at(C##X* self, C##X##_iter_t pos) { \
+ return C##X##_erase(self, keyToRaw(KEY_REF_##C(pos.ref))); \
} \
\
_implement_CBST(X, C, Key, Mapped, keyCompareRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped) \
- typedef C##_##X C##_##X##_t
+ typedef C##X C##X##_t
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
#define _implement_CBST(X, C, Key, Mapped, keyCompareRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped) \
- STC_DEF C##_##X \
- C##_##X##_init(void) { \
- C##_##X m = {(C##_##X##_node_t *) &cbst_nil, 0}; \
+ STC_DEF C##X \
+ C##X##_init(void) { \
+ C##X m = {(C##X##_node_t *) &cbst_nil, 0}; \
return m; \
} \
\
- STC_DEF C##_##X##_value_t* \
- C##_##X##_find_it(const C##_##X* self, C##_##X##_rawkey_t rkey, C##_##X##_iter_t* out) { \
- C##_##X##_node_t *tn = self->root; \
+ STC_DEF C##X##_value_t* \
+ C##X##_find_it(const C##X* self, C##X##_rawkey_t rkey, C##X##_iter_t* out) { \
+ C##X##_node_t *tn = self->root; \
out->_top = 0; \
while (tn->level) { \
- int c; C##_##X##_rawkey_t rx = keyToRaw(KEY_REF_##C(&tn->value)); \
+ int c; C##X##_rawkey_t rx = keyToRaw(KEY_REF_##C(&tn->value)); \
if ((c = keyCompareRaw(&rx, &rkey)) < 0) tn = tn->link[1]; \
else if (c > 0) {out->_st[out->_top++] = tn; tn = tn->link[0];} \
else {out->_tn = tn->link[1]; return (out->ref = &tn->value);} \
@@ -341,8 +341,8 @@ int main(void) {
} \
\
STC_DEF void \
- C##_##X##_next(C##_##X##_iter_t *it) { \
- C##_##X##_node_t *tn = it->_tn; \
+ C##X##_next(C##X##_iter_t *it) { \
+ C##X##_node_t *tn = it->_tn; \
if (it->_top || tn->level) { \
while (tn->level) { \
it->_st[it->_top++] = tn; \
@@ -355,10 +355,10 @@ int main(void) {
it->ref = NULL; \
} \
\
- static C##_##X##_node_t * \
- C##_##X##_skew_(C##_##X##_node_t *tn) { \
+ static C##X##_node_t * \
+ C##X##_skew_(C##X##_node_t *tn) { \
if (tn && tn->link[0]->level == tn->level && tn->level) { \
- C##_##X##_node_t *tmp = tn->link[0]; \
+ C##X##_node_t *tmp = tn->link[0]; \
tn->link[0] = tmp->link[1]; \
tmp->link[1] = tn; \
tn = tmp; \
@@ -366,10 +366,10 @@ int main(void) {
return tn; \
} \
\
- static C##_##X##_node_t * \
- C##_##X##_split_(C##_##X##_node_t *tn) { \
+ static C##X##_node_t * \
+ C##X##_split_(C##X##_node_t *tn) { \
if (tn->link[1]->link[1]->level == tn->level && tn->level) { \
- C##_##X##_node_t *tmp = tn->link[1]; \
+ C##X##_node_t *tmp = tn->link[1]; \
tn->link[1] = tmp->link[0]; \
tmp->link[0] = tn; \
tn = tmp; \
@@ -378,55 +378,55 @@ int main(void) {
return tn; \
} \
\
- static inline C##_##X##_node_t* \
- C##_##X##_insert_entry_i_(C##_##X##_node_t* tn, const C##_##X##_rawkey_t* rkey, C##_##X##_result_t* res) { \
- C##_##X##_node_t *up[64], *it = tn; \
+ static inline C##X##_node_t* \
+ C##X##_insert_entry_i_(C##X##_node_t* tn, const C##X##_rawkey_t* rkey, C##X##_result_t* res) { \
+ C##X##_node_t *up[64], *it = tn; \
int c, top = 0, dir = 0; \
while (it->level) { \
up[top++] = it; \
- C##_##X##_rawkey_t r = keyToRaw(KEY_REF_##C(&it->value)); \
+ C##X##_rawkey_t r = keyToRaw(KEY_REF_##C(&it->value)); \
if ((c = keyCompareRaw(&r, rkey)) == 0) {res->first = &it->value; return tn;} \
it = it->link[(dir = (c == -1))]; \
} \
- tn = c_new_1(C##_##X##_node_t); \
+ tn = c_new_1(C##X##_node_t); \
res->first = &tn->value, res->second = true; \
- tn->link[0] = tn->link[1] = (C##_##X##_node_t*) &cbst_nil, tn->level = 1; \
+ tn->link[0] = tn->link[1] = (C##X##_node_t*) &cbst_nil, tn->level = 1; \
if (top == 0) return tn; \
up[top - 1]->link[dir] = tn; \
while (top--) { \
if (top) dir = (up[top - 1]->link[1] == up[top]); \
- up[top] = C##_##X##_skew_(up[top]); \
- up[top] = C##_##X##_split_(up[top]); \
+ up[top] = C##X##_skew_(up[top]); \
+ up[top] = C##X##_split_(up[top]); \
if (top) up[top - 1]->link[dir] = up[top]; \
} \
return up[0]; \
} \
\
- STC_DEF C##_##X##_result_t \
- C##_##X##_insert_entry_(C##_##X* self, RawKey rkey) { \
- C##_##X##_result_t res = {NULL, false}; \
- self->root = C##_##X##_insert_entry_i_(self->root, &rkey, &res); \
+ STC_DEF C##X##_result_t \
+ C##X##_insert_entry_(C##X* self, RawKey rkey) { \
+ C##X##_result_t res = {NULL, false}; \
+ self->root = C##X##_insert_entry_i_(self->root, &rkey, &res); \
self->size += res.second; \
return res; \
} \
\
- STC_DEF C##_##X##_node_t* \
- C##_##X##_erase_r_(C##_##X##_node_t *tn, const C##_##X##_rawkey_t* rkey, int *erased) { \
+ STC_DEF C##X##_node_t* \
+ C##X##_erase_r_(C##X##_node_t *tn, const C##X##_rawkey_t* rkey, int *erased) { \
if (tn->level == 0) \
return tn; \
- C##_##X##_rawkey_t raw = keyToRaw(KEY_REF_##C(&tn->value)); \
- C##_##X##_node_t *tx; int c = keyCompareRaw(&raw, rkey); \
+ C##X##_rawkey_t raw = keyToRaw(KEY_REF_##C(&tn->value)); \
+ C##X##_node_t *tx; int c = keyCompareRaw(&raw, rkey); \
if (c != 0) \
- tn->link[c == -1] = C##_##X##_erase_r_(tn->link[c == -1], rkey, erased); \
+ tn->link[c == -1] = C##X##_erase_r_(tn->link[c == -1], rkey, erased); \
else { \
- if (!*erased) {C##_##X##_value_del(&tn->value); *erased = 1;} \
+ if (!*erased) {C##X##_value_del(&tn->value); *erased = 1;} \
if (tn->link[0]->level && tn->link[1]->level) { \
tx = tn->link[0]; \
while (tx->link[1]->level) \
tx = tx->link[1]; \
tn->value = tx->value; \
raw = keyToRaw(KEY_REF_##C(&tn->value)); \
- tn->link[0] = C##_##X##_erase_r_(tn->link[0], &raw, erased); \
+ tn->link[0] = C##X##_erase_r_(tn->link[0], &raw, erased); \
} else { \
tx = tn; \
tn = tn->link[tn->link[0]->level == 0]; \
@@ -436,38 +436,38 @@ int main(void) {
if (tn->link[0]->level < tn->level - 1 || tn->link[1]->level < tn->level - 1) { \
if (tn->link[1]->level > --tn->level) \
tn->link[1]->level = tn->level; \
- tn = C##_##X##_skew_(tn); \
- tx = tn->link[0] = C##_##X##_skew_(tn->link[0]); \
- tx->link[0] = C##_##X##_skew_(tx->link[0]); \
- tn = C##_##X##_split_(tn); \
- tn->link[0] = C##_##X##_split_(tn->link[0]); \
+ tn = C##X##_skew_(tn); \
+ tx = tn->link[0] = C##X##_skew_(tn->link[0]); \
+ tx->link[0] = C##X##_skew_(tx->link[0]); \
+ tn = C##X##_split_(tn); \
+ tn->link[0] = C##X##_split_(tn->link[0]); \
} \
return tn; \
} \
\
- STC_DEF C##_##X##_node_t* \
- C##_##X##_clone_r_(C##_##X##_node_t *tn) { \
+ STC_DEF C##X##_node_t* \
+ C##X##_clone_r_(C##X##_node_t *tn) { \
if (! tn->level) return tn; \
- C##_##X##_node_t *cn = c_new_1(C##_##X##_node_t); \
- cn->link[0] = C##_##X##_clone_r_(tn->link[0]); \
- cn->link[1] = C##_##X##_clone_r_(tn->link[1]); \
+ C##X##_node_t *cn = c_new_1(C##X##_node_t); \
+ cn->link[0] = C##X##_clone_r_(tn->link[0]); \
+ cn->link[1] = C##X##_clone_r_(tn->link[1]); \
cn->level = tn->level; \
- cn->value = C##_##X##_value_clone(tn->value); \
+ cn->value = C##X##_value_clone(tn->value); \
return cn; \
} \
\
STC_DEF void \
- C##_##X##_del_r_(C##_##X##_node_t* tn) { \
+ C##X##_del_r_(C##X##_node_t* tn) { \
if (tn->level != 0) { \
- C##_##X##_del_r_(tn->link[0]); \
- C##_##X##_del_r_(tn->link[1]); \
- C##_##X##_value_del(&tn->value); \
+ C##X##_del_r_(tn->link[0]); \
+ C##X##_del_r_(tn->link[1]); \
+ C##X##_value_del(&tn->value); \
c_free(tn); \
} \
}
-_using_CBST_types(_, csmap, int, int);
+_using_CBST_types(_, csmap_, int, int);
static csmap___node_t cbst_nil = {&cbst_nil, &cbst_nil, 0};
#else