diff options
Diffstat (limited to 'include/stc/csmap.h')
| -rw-r--r-- | include/stc/csmap.h | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 2b0a9245..3ea30083 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -56,7 +56,7 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; #define _csmap_rep(self) c_container_of((self)->nodes, struct csmap_rep, nodes)
#if !defined cx_forwarded
- _c_aatree_types(Self, C, i_KEY, i_VAL);
+ _c_aatree_types(Self, C, i_key, i_val);
#endif
\
@@ -71,25 +71,25 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; cx_value_t value; \
}; \
\
- typedef i_KEYRAW cx_rawkey_t; \
- typedef i_VALRAW cx_memb(_rawmapped_t); \
- typedef cx_SET_ONLY( i_KEYRAW ) \
- cx_MAP_ONLY( struct { i_KEYRAW first; \
- i_VALRAW second; } ) \
+ typedef i_keyraw cx_rawkey_t; \
+ typedef i_valraw cx_memb(_rawmapped_t); \
+ typedef cx_SET_ONLY( i_keyraw ) \
+ cx_MAP_ONLY( struct { i_keyraw first; \
+ i_valraw second; } ) \
cx_rawvalue_t; \
\
STC_API Self cx_memb(_init)(void); \
STC_API Self cx_memb(_clone)(Self tree); \
STC_API void cx_memb(_del)(Self* self); \
STC_API void cx_memb(_reserve)(Self* self, size_t cap); \
- STC_API cx_value_t* cx_memb(_find_it)(const Self* self, i_KEYRAW rkey, cx_iter_t* out); \
- STC_API cx_iter_t cx_memb(_lower_bound)(const Self* self, i_KEYRAW rkey); \
+ STC_API cx_value_t* cx_memb(_find_it)(const Self* self, i_keyraw rkey, cx_iter_t* out); \
+ STC_API cx_iter_t cx_memb(_lower_bound)(const Self* self, i_keyraw rkey); \
STC_API cx_value_t* cx_memb(_front)(const Self* self); \
STC_API cx_value_t* cx_memb(_back)(const Self* self); \
- STC_API int cx_memb(_erase)(Self* self, i_KEYRAW rkey); \
+ STC_API int cx_memb(_erase)(Self* self, i_keyraw rkey); \
STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it); \
STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2); \
- STC_API cx_result_t cx_memb(_insert_entry_)(Self* self, i_KEYRAW rkey); \
+ STC_API cx_result_t cx_memb(_insert_entry_)(Self* self, i_keyraw rkey); \
STC_API void cx_memb(_next)(cx_iter_t* it); \
\
STC_INLINE bool cx_memb(_empty)(Self tree) { return _csmap_rep(&tree)->size == 0; } \
@@ -97,9 +97,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; STC_INLINE size_t cx_memb(_capacity)(Self tree) { return _csmap_rep(&tree)->cap; } \
STC_INLINE void cx_memb(_clear)(Self* self) { cx_memb(_del)(self); *self = cx_memb(_init)(); } \
STC_INLINE void cx_memb(_swap)(Self* a, Self* b) {c_swap(Self, *a, *b); } \
- STC_INLINE bool cx_memb(_contains)(const Self* self, i_KEYRAW rkey) \
+ STC_INLINE bool cx_memb(_contains)(const Self* self, i_keyraw rkey) \
{cx_iter_t it; return cx_memb(_find_it)(self, rkey, &it) != NULL; } \
- STC_INLINE cx_value_t* cx_memb(_get)(const Self* self, i_KEYRAW rkey) \
+ STC_INLINE cx_value_t* cx_memb(_get)(const Self* self, i_keyraw rkey) \
{cx_iter_t it; return cx_memb(_find_it)(self, rkey, &it); } \
\
STC_INLINE Self \
@@ -111,33 +111,33 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; \
STC_INLINE cx_rawvalue_t \
cx_memb(_value_toraw)(cx_value_t* val) { \
- return cx_SET_ONLY( i_KEYTO(val) ) \
- cx_MAP_ONLY( c_make(cx_rawvalue_t){i_KEYTO(&val->first), i_VALTO(&val->second)} ); \
+ return cx_SET_ONLY( i_keyto(val) ) \
+ cx_MAP_ONLY( c_make(cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} ); \
} \
STC_INLINE void \
cx_memb(_value_del)(cx_value_t* val) { \
- i_KEYDEL(cx_keyref(val)); \
- cx_MAP_ONLY( i_VALDEL(&val->second); ) \
+ i_keydel(cx_keyref(val)); \
+ cx_MAP_ONLY( i_valdel(&val->second); ) \
} \
STC_INLINE void \
cx_memb(_value_clone)(cx_value_t* dst, cx_value_t* val) { \
- *cx_keyref(dst) = i_KEYFROM(i_KEYTO(cx_keyref(val))); \
- cx_MAP_ONLY( dst->second = i_VALFROM(i_VALTO(&val->second)); ) \
+ *cx_keyref(dst) = i_keyfrom(i_keyto(cx_keyref(val))); \
+ cx_MAP_ONLY( dst->second = i_valfrom(i_valto(&val->second)); ) \
} \
\
STC_INLINE cx_iter_t \
- cx_memb(_find)(const Self* self, i_KEYRAW rkey) { \
+ cx_memb(_find)(const Self* self, i_keyraw rkey) { \
cx_iter_t it; \
cx_memb(_find_it)(self, rkey, &it); \
return it; \
} \
\
STC_INLINE cx_result_t \
- cx_memb(_emplace)(Self* self, i_KEYRAW rkey cx_MAP_ONLY(, i_VALRAW rmapped)) { \
+ cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { \
cx_result_t res = cx_memb(_insert_entry_)(self, rkey); \
if (res.inserted) { \
- *cx_keyref(res.ref) = i_KEYFROM(rkey); \
- cx_MAP_ONLY(res.ref->second = i_VALFROM(rmapped);) \
+ *cx_keyref(res.ref) = i_keyfrom(rkey); \
+ cx_MAP_ONLY(res.ref->second = i_valfrom(rmapped);) \
} \
return res; \
} \
@@ -149,37 +149,37 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; } \
\
STC_INLINE cx_result_t \
- cx_memb(_insert)(Self* self, i_KEY key cx_MAP_ONLY(, i_VAL mapped)) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, i_KEYTO(&key)); \
+ cx_memb(_insert)(Self* self, i_key key cx_MAP_ONLY(, i_val mapped)) { \
+ cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key)); \
if (res.inserted) {*cx_keyref(res.ref) = key; cx_MAP_ONLY( res.ref->second = mapped; )} \
- else {i_KEYDEL(&key); cx_MAP_ONLY( i_VALDEL(&mapped); )} \
+ else {i_keydel(&key); cx_MAP_ONLY( i_valdel(&mapped); )} \
return res; \
} \
\
cx_MAP_ONLY( \
STC_INLINE cx_result_t \
- cx_memb(_insert_or_assign)(Self* self, i_KEY key, i_VAL mapped) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, i_KEYTO(&key)); \
+ cx_memb(_insert_or_assign)(Self* self, i_key key, i_val mapped) { \
+ cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key)); \
if (res.inserted) res.ref->first = key; \
- else {i_KEYDEL(&key); i_VALDEL(&res.ref->second); } \
+ else {i_keydel(&key); i_valdel(&res.ref->second); } \
res.ref->second = mapped; return res; \
} \
\
STC_INLINE cx_result_t \
- cx_memb(_put)(Self* self, i_KEY key, i_VAL mapped) { \
+ cx_memb(_put)(Self* self, i_key key, i_val mapped) { \
return cx_memb(_insert_or_assign)(self, key, mapped); \
} \
\
STC_INLINE cx_result_t \
- cx_memb(_emplace_or_assign)(Self* self, i_KEYRAW rkey, i_VALRAW rmapped) { \
+ cx_memb(_emplace_or_assign)(Self* self, i_keyraw rkey, i_valraw rmapped) { \
cx_result_t res = cx_memb(_insert_entry_)(self, rkey); \
- if (res.inserted) res.ref->first = i_KEYFROM(rkey); \
- else i_VALDEL(&res.ref->second); \
- res.ref->second = i_VALFROM(rmapped); return res; \
+ if (res.inserted) res.ref->first = i_keyfrom(rkey); \
+ else i_valdel(&res.ref->second); \
+ res.ref->second = i_valfrom(rmapped); return res; \
} \
\
STC_INLINE cx_mapped_t* \
- cx_memb(_at)(const Self* self, i_KEYRAW rkey) { \
+ cx_memb(_at)(const Self* self, i_keyraw rkey) { \
cx_iter_t it; \
return &cx_memb(_find_it)(self, rkey, &it)->second; \
}) \
@@ -203,9 +203,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; return it; \
} \
\
- _c_implement_aatree(Self, C, i_KEY, i_VAL, i_CMP, \
- i_VALDEL, i_VALFROM, i_VALTO, i_VALRAW, \
- i_KEYDEL, i_KEYFROM, i_KEYTO, i_KEYRAW) \
+ _c_implement_aatree(Self, C, i_key, i_val, i_cmp, \
+ i_valdel, i_valfrom, i_valto, i_valraw, \
+ i_keydel, i_keyfrom, i_keyto, i_keyraw) \
struct stc_trailing_semicolon
/* -------------------------- IMPLEMENTATION ------------------------- */
@@ -213,9 +213,9 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0};
-#define _c_implement_aatree(Self, C, i_KEY, i_VAL, i_CMP, \
- i_VALDEL, i_VALFROM, i_VALTO, i_VALRAW, \
- i_KEYDEL, i_KEYFROM, i_KEYTO, i_KEYRAW) \
+#define _c_implement_aatree(Self, C, i_key, i_val, i_cmp, \
+ i_valdel, i_valfrom, i_valto, i_valraw, \
+ i_keydel, i_keyfrom, i_keyto, i_keyraw) \
STC_DEF Self \
cx_memb(_init)(void) { \
Self tree = {(cx_node_t *) _csmap_sentinel.nodes}; \
@@ -268,13 +268,13 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; } \
\
STC_DEF cx_value_t* \
- cx_memb(_find_it)(const Self* self, i_KEYRAW rkey, cx_iter_t* out) { \
+ cx_memb(_find_it)(const Self* self, i_keyraw rkey, cx_iter_t* out) { \
cx_memb(_size_t) tn = _csmap_rep(self)->root; \
cx_node_t *d = out->_d = self->nodes; \
out->_top = 0; \
while (tn) { \
- int c; cx_rawkey_t raw = i_KEYTO(cx_keyref(&d[tn].value)); \
- if ((c = i_CMP(&raw, &rkey)) < 0) \
+ int c; cx_rawkey_t raw = i_keyto(cx_keyref(&d[tn].value)); \
+ if ((c = i_cmp(&raw, &rkey)) < 0) \
tn = d[tn].link[1]; \
else if (c > 0) \
{ out->_st[out->_top++] = tn; tn = d[tn].link[0]; } \
@@ -285,7 +285,7 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; } \
\
STC_DEF cx_iter_t \
- cx_memb(_lower_bound)(const Self* self, i_KEYRAW rkey) { \
+ cx_memb(_lower_bound)(const Self* self, i_keyraw rkey) { \
cx_iter_t it; \
cx_memb(_find_it)(self, rkey, &it); \
if (!it.ref && it._top) { \
@@ -340,8 +340,8 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; int c, top = 0, dir = 0; \
while (tx) { \
up[top++] = tx; \
- i_KEYRAW raw = i_KEYTO(cx_keyref(&d[tx].value)); \
- if ((c = i_CMP(&raw, rkey)) == 0) {res->ref = &d[tx].value; return tn; } \
+ i_keyraw raw = i_keyto(cx_keyref(&d[tx].value)); \
+ if ((c = i_cmp(&raw, rkey)) == 0) {res->ref = &d[tx].value; return tn; } \
dir = (c < 0); \
tx = d[tx].link[dir]; \
} \
@@ -359,7 +359,7 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; } \
\
STC_DEF cx_result_t \
- cx_memb(_insert_entry_)(Self* self, i_KEYRAW rkey) { \
+ cx_memb(_insert_entry_)(Self* self, i_keyraw rkey) { \
cx_result_t res = {NULL, false}; \
cx_memb(_size_t) tn = cx_memb(_insert_entry_i_)(self, (cx_memb(_size_t)) _csmap_rep(self)->root, &rkey, &res); \
_csmap_rep(self)->root = tn; \
@@ -370,8 +370,8 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; STC_DEF cx_memb(_size_t) \
cx_memb(_erase_r_)(cx_node_t *d, cx_memb(_size_t) tn, const cx_rawkey_t* rkey, int *erased) { \
if (tn == 0) return 0; \
- i_KEYRAW raw = i_KEYTO(cx_keyref(&d[tn].value)); \
- cx_memb(_size_t) tx; int c = i_CMP(&raw, rkey); \
+ i_keyraw raw = i_keyto(cx_keyref(&d[tn].value)); \
+ cx_memb(_size_t) tx; int c = i_cmp(&raw, rkey); \
if (c != 0) \
d[tn].link[c < 0] = cx_memb(_erase_r_)(d, d[tn].link[c < 0], rkey, erased); \
else { \
@@ -381,7 +381,7 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; while (d[tx].link[1]) \
tx = d[tx].link[1]; \
d[tn].value = d[tx].value; /* move */ \
- raw = i_KEYTO(cx_keyref(&d[tn].value)); \
+ raw = i_keyto(cx_keyref(&d[tn].value)); \
d[tn].link[0] = cx_memb(_erase_r_)(d, d[tn].link[0], &raw, erased); \
} else { /* unlink node */ \
tx = tn; \
@@ -406,7 +406,7 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; } \
\
STC_DEF int \
- cx_memb(_erase)(Self* self, i_KEYRAW rkey) { \
+ cx_memb(_erase)(Self* self, i_keyraw rkey) { \
int erased = 0; \
cx_memb(_size_t) root = cx_memb(_erase_r_)(self->nodes, (cx_memb(_size_t)) _csmap_rep(self)->root, &rkey, &erased); \
return erased ? (_csmap_rep(self)->root = root, --_csmap_rep(self)->size, 1) : 0; \
@@ -414,9 +414,9 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; \
STC_DEF cx_iter_t \
cx_memb(_erase_at)(Self* self, cx_iter_t it) { \
- cx_rawkey_t raw = i_KEYTO(cx_keyref(it.ref)), nxt; \
+ cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt; \
cx_memb(_next)(&it); \
- if (it.ref) nxt = i_KEYTO(cx_keyref(it.ref)); \
+ if (it.ref) nxt = i_keyto(cx_keyref(it.ref)); \
cx_memb(_erase)(self, raw); \
if (it.ref) cx_memb(_find_it)(self, nxt, &it); \
return it; \
@@ -427,12 +427,12 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; if (!it2.ref) { while (it1.ref) it1 = cx_memb(_erase_at)(self, it1); \
return it1; } \
cx_key_t k1 = *cx_keyref(it1.ref), k2 = *cx_keyref(it2.ref); \
- cx_rawkey_t r1 = i_KEYTO(&k1); \
+ cx_rawkey_t r1 = i_keyto(&k1); \
for (;;) { \
if (memcmp(&k1, &k2, sizeof k1) == 0) return it1; \
cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref); \
cx_memb(_erase)(self, r1); \
- cx_memb(_find_it)(self, (r1 = i_KEYTO(&k1)), &it1); \
+ cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1); \
} \
} \
\
|
