From 0205c4913430aa54eb0536eb1621287da719be1f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 29 Oct 2021 14:52:21 +0200 Subject: renamed _cx_..._t to _cx_... --- benchmarks/others/old/clist.h | 122 ++++++++++++------------- benchmarks/others/old/csmap.h | 178 ++++++++++++++++++------------------- include/stc/carr2.h | 34 +++---- include/stc/carr3.h | 36 ++++---- include/stc/cdeq.h | 142 ++++++++++++++--------------- include/stc/clist.h | 120 ++++++++++++------------- include/stc/cmap.h | 110 +++++++++++------------ include/stc/cpque.h | 30 +++---- include/stc/csmap.h | 202 +++++++++++++++++++++--------------------- include/stc/csptr.h | 10 +-- include/stc/cstack.h | 40 ++++----- include/stc/cvec.h | 148 +++++++++++++++---------------- include/stc/template.h | 20 ++--- 13 files changed, 596 insertions(+), 596 deletions(-) diff --git a/benchmarks/others/old/clist.h b/benchmarks/others/old/clist.h index c10909d3..e677e40d 100644 --- a/benchmarks/others/old/clist.h +++ b/benchmarks/others/old/clist.h @@ -59,30 +59,30 @@ _c_clist_types(clist_VOID, int); STC_API size_t _clist_count(const clist_VOID* self); -#define _clist_node(_cx_self, vp) c_container_of(vp, _cx_node_t, value) +#define _clist_node(_cx_self, vp) c_container_of(vp, _cx_node, value) #define _c_using_clist(_cx_self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw, defTypes) \ \ defTypes( _c_clist_types(_cx_self, i_val); ) \ - typedef i_valraw _cx_rawvalue_t; \ + typedef i_valraw _cx_rawvalue; \ \ STC_API _cx_self _cx_memb(_clone)(_cx_self lst); \ STC_API void _cx_memb(_del)(_cx_self* self); \ STC_API void _cx_memb(_push_back)(_cx_self* self, i_val value); \ STC_API void _cx_memb(_push_front)(_cx_self* self, i_val value); \ - STC_API void _cx_memb(_emplace_items)(_cx_self *self, const _cx_rawvalue_t arr[], size_t n); \ - STC_API _cx_self _cx_memb(_split_after)(_cx_self* self, _cx_iter_t pos1, _cx_iter_t pos2); \ - STC_API void _cx_memb(_splice_after)(_cx_self* self, _cx_iter_t pos, _cx_self* other); \ - STC_DEF void _cx_memb(_splice_after_range)(_cx_self* self, _cx_iter_t pos, _cx_self* other, _cx_iter_t i1, _cx_iter_t i2); \ - STC_API _cx_iter_t _cx_memb(_find)(const _cx_self* self, i_valraw val); \ - STC_API _cx_iter_t _cx_memb(_find_before)(const _cx_self* self, i_valraw val); \ - STC_API _cx_iter_t _cx_memb(_find_before_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val); \ + STC_API void _cx_memb(_emplace_items)(_cx_self *self, const _cx_rawvalue arr[], size_t n); \ + STC_API _cx_self _cx_memb(_split_after)(_cx_self* self, _cx_iter pos1, _cx_iter pos2); \ + STC_API void _cx_memb(_splice_after)(_cx_self* self, _cx_iter pos, _cx_self* other); \ + STC_DEF void _cx_memb(_splice_after_range)(_cx_self* self, _cx_iter pos, _cx_self* other, _cx_iter i1, _cx_iter i2); \ + STC_API _cx_iter _cx_memb(_find)(const _cx_self* self, i_valraw val); \ + STC_API _cx_iter _cx_memb(_find_before)(const _cx_self* self, i_valraw val); \ + STC_API _cx_iter _cx_memb(_find_before_in)(_cx_iter it1, _cx_iter it2, i_valraw val); \ STC_API void _cx_memb(_sort)(_cx_self* self); \ STC_API size_t _cx_memb(_remove)(_cx_self* self, i_valraw val); \ - STC_API _cx_iter_t _cx_memb(_insert_after)(_cx_self* self, _cx_iter_t pos, i_val value); \ - STC_API _cx_iter_t _cx_memb(_erase_after)(_cx_self* self, _cx_iter_t pos); \ - STC_API _cx_iter_t _cx_memb(_erase_range_after)(_cx_self* self, _cx_iter_t pos, _cx_iter_t it2); \ - STC_API _cx_node_t* _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node); \ + STC_API _cx_iter _cx_memb(_insert_after)(_cx_self* self, _cx_iter pos, i_val value); \ + STC_API _cx_iter _cx_memb(_erase_after)(_cx_self* self, _cx_iter pos); \ + STC_API _cx_iter _cx_memb(_erase_range_after)(_cx_self* self, _cx_iter pos, _cx_iter it2); \ + STC_API _cx_node* _cx_memb(_erase_after_)(_cx_self* self, _cx_node* node); \ \ STC_INLINE _cx_self _cx_memb(_init)(void) {_cx_self lst = {NULL}; return lst; } \ STC_INLINE bool _cx_memb(_empty)(_cx_self lst) { return lst.last == NULL; } \ @@ -94,9 +94,9 @@ STC_API size_t _clist_count(const clist_VOID* self); { _cx_memb(_push_back)(self, i_valfrom(raw)); } \ STC_INLINE void _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) \ { _cx_memb(_push_front)(self, i_valfrom(raw)); } \ - STC_INLINE _cx_value_t* \ + STC_INLINE _cx_value* \ _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; } \ - STC_INLINE _cx_value_t* \ + STC_INLINE _cx_value* \ _cx_memb(_back)(const _cx_self* self) { return &self->last->value; } \ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) { _cx_memb(_erase_after_)(self, self->last); } \ STC_INLINE void _cx_memb(_splice_front)(_cx_self* self, _cx_self* other) \ @@ -104,42 +104,42 @@ STC_API size_t _clist_count(const clist_VOID* self); STC_INLINE void _cx_memb(_splice_back)(_cx_self* self, _cx_self* other) \ { _cx_memb(_splice_after)(self, _cx_memb(_last)(self), other); } \ \ - STC_INLINE _cx_iter_t \ - _cx_memb(_emplace_after)(_cx_self* self, _cx_iter_t pos, i_valraw raw) { \ + STC_INLINE _cx_iter \ + _cx_memb(_emplace_after)(_cx_self* self, _cx_iter pos, i_valraw raw) { \ return _cx_memb(_insert_after)(self, pos, i_valfrom(raw)); \ } \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_before_begin)(const _cx_self* self) { \ - _cx_value_t *last = self->last ? &self->last->value : NULL; \ - _cx_iter_t it = {&self->last, last, -1}; return it; \ + _cx_value *last = self->last ? &self->last->value : NULL; \ + _cx_iter it = {&self->last, last, -1}; return it; \ } \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_begin)(const _cx_self* self) { \ - _cx_value_t* head = self->last ? &self->last->next->value : NULL; \ - _cx_iter_t it = {&self->last, head, 0}; return it; \ + _cx_value* head = self->last ? &self->last->next->value : NULL; \ + _cx_iter it = {&self->last, head, 0}; return it; \ } \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_last)(const _cx_self* self) { \ - _cx_value_t *last = self->last ? &self->last->value : NULL; \ - _cx_iter_t it = {&self->last, last, 0}; return it; \ + _cx_value *last = self->last ? &self->last->value : NULL; \ + _cx_iter it = {&self->last, last, 0}; return it; \ } \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_end)(const _cx_self* self) { \ - _cx_iter_t it = {NULL, NULL}; return it; \ + _cx_iter it = {NULL, NULL}; return it; \ } \ \ STC_INLINE void \ - _cx_memb(_next)(_cx_iter_t* it) { \ - _cx_node_t* node = _clist_node(_cx_self, it->ref); \ + _cx_memb(_next)(_cx_iter* it) { \ + _cx_node* node = _clist_node(_cx_self, it->ref); \ it->ref = ((it->_state += node == *it->_last) == 1) ? NULL : &node->next->value; \ } \ \ - STC_INLINE _cx_iter_t \ - _cx_memb(_advance)(_cx_iter_t it, size_t n) { \ + STC_INLINE _cx_iter \ + _cx_memb(_advance)(_cx_iter it, size_t n) { \ while (n-- && it.ref) _cx_memb(_next)(&it); return it; \ } \ \ @@ -176,35 +176,35 @@ STC_API size_t _clist_count(const clist_VOID* self); } \ \ STC_DEF void \ - _cx_memb(_emplace_items)(_cx_self *self, const _cx_rawvalue_t arr[], size_t n) { \ + _cx_memb(_emplace_items)(_cx_self *self, const _cx_rawvalue arr[], size_t n) { \ for (size_t i=0; ilast && pos._state == 0) self->last = entry; \ pos.ref = &entry->value, pos._state = 0; return pos; \ } \ \ - STC_DEF _cx_iter_t \ - _cx_memb(_erase_after)(_cx_self* self, _cx_iter_t pos) { \ + STC_DEF _cx_iter \ + _cx_memb(_erase_after)(_cx_self* self, _cx_iter pos) { \ _cx_memb(_erase_after_)(self, _clist_node(_cx_self, pos.ref)); \ _cx_memb(_next)(&pos); return pos; \ } \ \ - STC_DEF _cx_iter_t \ - _cx_memb(_erase_range_after)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { \ - _cx_node_t* node = _clist_node(_cx_self, it1.ref), *done = it2.ref ? _clist_node(_cx_self, it2.ref) : NULL; \ + STC_DEF _cx_iter \ + _cx_memb(_erase_range_after)(_cx_self* self, _cx_iter it1, _cx_iter it2) { \ + _cx_node* node = _clist_node(_cx_self, it1.ref), *done = it2.ref ? _clist_node(_cx_self, it2.ref) : NULL; \ while (node && node->next != done) \ node = _cx_memb(_erase_after_)(self, node); \ _cx_memb(_next)(&it1); return it1; \ } \ \ - STC_DEF _cx_iter_t \ - _cx_memb(_find_before_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val) { \ - _cx_iter_t i = it1; \ + STC_DEF _cx_iter \ + _cx_memb(_find_before_in)(_cx_iter it1, _cx_iter it2, i_valraw val) { \ + _cx_iter i = it1; \ for (_cx_memb(_next)(&i); i.ref != it2.ref; _cx_memb(_next)(&i)) { \ i_valraw r = i_valto(i.ref); \ if (i_cmp(&r, &val) == 0) return it1; \ @@ -213,22 +213,22 @@ STC_API size_t _clist_count(const clist_VOID* self); it1.ref = NULL; return it1; \ } \ \ - STC_DEF _cx_iter_t \ + STC_DEF _cx_iter \ _cx_memb(_find_before)(const _cx_self* self, i_valraw val) { \ - _cx_iter_t it = _cx_memb(_find_before_in)(_cx_memb(_before_begin)(self), _cx_memb(_end)(self), val); \ + _cx_iter it = _cx_memb(_find_before_in)(_cx_memb(_before_begin)(self), _cx_memb(_end)(self), val); \ return it; \ } \ \ - STC_DEF _cx_iter_t \ + STC_DEF _cx_iter \ _cx_memb(_find)(const _cx_self* self, i_valraw val) { \ - _cx_iter_t it = _cx_memb(_find_before_in)(_cx_memb(_before_begin)(self), _cx_memb(_end)(self), val); \ + _cx_iter it = _cx_memb(_find_before_in)(_cx_memb(_before_begin)(self), _cx_memb(_end)(self), val); \ if (it.ref != _cx_memb(_end)(self).ref) _cx_memb(_next)(&it); \ return it; \ } \ \ - STC_DEF _cx_node_t* \ - _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node) { \ - _cx_node_t* del = node->next, *next = del->next; \ + STC_DEF _cx_node* \ + _cx_memb(_erase_after_)(_cx_self* self, _cx_node* node) { \ + _cx_node* del = node->next, *next = del->next; \ node->next = next; \ if (del == next) self->last = node = NULL; \ else if (self->last == del) self->last = node, node = NULL; \ @@ -239,7 +239,7 @@ STC_API size_t _clist_count(const clist_VOID* self); STC_DEF size_t \ _cx_memb(_remove)(_cx_self* self, i_valraw val) { \ size_t n = 0; \ - _cx_node_t* prev = self->last, *node; \ + _cx_node* prev = self->last, *node; \ while (prev) { \ node = prev->next; \ i_valraw r = i_valto(&node->value); \ @@ -252,8 +252,8 @@ STC_API size_t _clist_count(const clist_VOID* self); } \ \ STC_DEF _cx_self \ - _cx_memb(_split_after)(_cx_self* self, _cx_iter_t pos1, _cx_iter_t pos2) { \ - _cx_node_t *node1 = _clist_node(_cx_self, pos1.ref), *next1 = node1->next, \ + _cx_memb(_split_after)(_cx_self* self, _cx_iter pos1, _cx_iter pos2) { \ + _cx_node *node1 = _clist_node(_cx_self, pos1.ref), *next1 = node1->next, \ *node2 = _clist_node(_cx_self, pos2.ref); \ node1->next = node2->next, node2->next = next1; \ if (self->last == node2) self->last = node1; \ @@ -261,11 +261,11 @@ STC_API size_t _clist_count(const clist_VOID* self); } \ \ STC_DEF void \ - _cx_memb(_splice_after)(_cx_self* self, _cx_iter_t pos, _cx_self* other) { \ + _cx_memb(_splice_after)(_cx_self* self, _cx_iter pos, _cx_self* other) { \ if (!pos.ref) \ self->last = other->last; \ else if (other->last) { \ - _cx_node_t *node = _clist_node(_cx_self, pos.ref), *next = node->next; \ + _cx_node *node = _clist_node(_cx_self, pos.ref), *next = node->next; \ node->next = other->last->next; \ other->last->next = next; \ if (node == self->last && pos._state == 0) self->last = other->last; \ @@ -274,27 +274,27 @@ STC_API size_t _clist_count(const clist_VOID* self); } \ \ STC_DEF void \ - _cx_memb(_splice_after_range)(_cx_self* self, _cx_iter_t pos, _cx_self* other, _cx_iter_t pos1, _cx_iter_t pos2) { \ + _cx_memb(_splice_after_range)(_cx_self* self, _cx_iter pos, _cx_self* other, _cx_iter pos1, _cx_iter pos2) { \ _cx_self tmp = _cx_memb(_split_after)(other, pos1, pos2); \ _cx_memb(_splice_after)(self, pos, &tmp); \ } \ \ STC_DEF int \ _cx_memb(_sort_cmp_)(const void* x, const void* y) { \ - i_valraw a = i_valto(&((_cx_node_t *) x)->value); \ - i_valraw b = i_valto(&((_cx_node_t *) y)->value); \ + i_valraw a = i_valto(&((_cx_node *) x)->value); \ + i_valraw b = i_valto(&((_cx_node *) y)->value); \ return i_cmp(&a, &b); \ } \ \ STC_DEF void \ _cx_memb(_sort)(_cx_self* self) { \ if (self->last) \ - self->last = (_cx_node_t *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_)); \ + self->last = (_cx_node *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_)); \ } #define _c_clist_insert_after(self, _cx_self, node, val) \ - _cx_node_t *entry = c_new (_cx_node_t); \ + _cx_node *entry = c_new (_cx_node); \ if (node) entry->next = node->next, node->next = entry; \ else entry->next = entry; \ entry->value = val diff --git a/benchmarks/others/old/csmap.h b/benchmarks/others/old/csmap.h index 848e6170..a60d16e0 100644 --- a/benchmarks/others/old/csmap.h +++ b/benchmarks/others/old/csmap.h @@ -53,14 +53,14 @@ int main(void) { #define KEY_REF_csmap_(vp) (&(vp)->first) #define _c_aatree_complete_types(_cx_self, C) \ - cx_MAP_ONLY( struct _cx_value_t { \ - _cx_key_t first; \ - _cx_mapped_t second; \ + cx_MAP_ONLY( struct _cx_value { \ + _cx_key first; \ + _cx_mapped second; \ }; ) \ - struct _cx_node_t { \ - struct _cx_node_t *link[2]; \ + struct _cx_node { \ + struct _cx_node *link[2]; \ uint8_t level; \ - _cx_value_t value; \ + _cx_value value; \ } #ifndef cx_forwarded @@ -69,25 +69,25 @@ int main(void) { _c_aatree_complete_types(_cx_self, C); \ \ - typedef i_keyraw _cx_rawkey_t; \ + typedef i_keyraw _cx_rawkey; \ typedef i_valraw _cx_memb(_rawmapped_t); \ - typedef cx_SET_ONLY( _cx_rawkey_t ) \ - cx_MAP_ONLY( struct { _cx_rawkey_t first; \ + typedef cx_SET_ONLY( _cx_rawkey ) \ + cx_MAP_ONLY( struct { _cx_rawkey first; \ _cx_memb(_rawmapped_t) second; } ) \ - _cx_rawvalue_t; \ + _cx_rawvalue; \ \ STC_API _cx_self _cx_memb(_init)(void); \ - STC_API _cx_value_t* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out); \ - STC_API _cx_iter_t _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey); \ - STC_API _cx_value_t* _cx_memb(_front)(const _cx_self* self); \ - STC_API _cx_value_t* _cx_memb(_back)(const _cx_self* self); \ - STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it); \ - STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2); \ - STC_API _cx_node_t* _cx_memb(_erase_r_)(_cx_node_t *tn, const _cx_rawkey_t* rkey, int *erased); \ - STC_API void _cx_memb(_del_r_)(_cx_node_t* tn); \ - STC_API _cx_node_t* _cx_memb(_clone_r_)(_cx_node_t *tn); \ - STC_API _cx_result_t _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); \ - STC_API void _cx_memb(_next)(_cx_iter_t* it); \ + STC_API _cx_value* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter* out); \ + STC_API _cx_iter _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey); \ + STC_API _cx_value* _cx_memb(_front)(const _cx_self* self); \ + STC_API _cx_value* _cx_memb(_back)(const _cx_self* self); \ + STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); \ + STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); \ + STC_API _cx_node* _cx_memb(_erase_r_)(_cx_node *tn, const _cx_rawkey* rkey, int *erased); \ + STC_API void _cx_memb(_del_r_)(_cx_node* tn); \ + STC_API _cx_node* _cx_memb(_clone_r_)(_cx_node *tn); \ + STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); \ + STC_API void _cx_memb(_next)(_cx_iter* it); \ \ STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return cx.size == 0; } \ STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cx.size; } \ @@ -95,28 +95,28 @@ int main(void) { STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_del)(self); *self = _cx_memb(_init)(); } \ STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) {c_swap(_cx_self, *a, *b); } \ STC_INLINE _cx_self _cx_memb(_clone)(_cx_self cx) { return c_make(_cx_self){ _cx_memb(_clone_r_)(cx.root), cx.size}; } \ - STC_INLINE _cx_iter_t _cx_memb(_find)(const _cx_self* self, i_keyraw rkey) \ - {_cx_iter_t it; _cx_memb(_find_it)(self, rkey, &it); return it; } \ + STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_keyraw rkey) \ + {_cx_iter it; _cx_memb(_find_it)(self, rkey, &it); return it; } \ STC_INLINE bool _cx_memb(_contains)(const _cx_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 _cx_self* self, i_keyraw rkey) \ - {_cx_iter_t it; return _cx_memb(_find_it)(self, rkey, &it); } \ + {_cx_iter it; return _cx_memb(_find_it)(self, rkey, &it) != NULL; } \ + STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_keyraw rkey) \ + {_cx_iter it; return _cx_memb(_find_it)(self, rkey, &it); } \ \ STC_INLINE void \ - _cx_memb(_value_del)(_cx_value_t* val) { \ + _cx_memb(_value_del)(_cx_value* val) { \ 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_memb(_value_clone)(_cx_value* dst, _cx_value* val) { \ *cx_keyref(dst) = i_keyfrom(i_keyto(cx_keyref(val))); \ cx_MAP_ONLY( dst->second = i_valfrom(i_valto(&val->second)); ) \ } \ \ - STC_INLINE _cx_result_t \ + STC_INLINE _cx_result \ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { \ - _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey); \ + _cx_result 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);) \ @@ -125,56 +125,56 @@ int main(void) { } \ \ STC_INLINE void \ - _cx_memb(_emplace_items)(_cx_self* self, const _cx_rawvalue_t arr[], size_t n) { \ + _cx_memb(_emplace_items)(_cx_self* self, const _cx_rawvalue arr[], size_t n) { \ for (size_t i=0; isecond = mapped; )} \ else {i_keydel(&key); cx_MAP_ONLY( i_valdel(&mapped); )} \ return res; \ } \ \ cx_MAP_ONLY( \ - STC_INLINE _cx_result_t \ + STC_INLINE _cx_result \ _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) { \ - _cx_result_t res = _cx_memb(_insert_entry_)(self, i_keyto(&key)); \ + _cx_result 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); } \ res.ref->second = mapped; return res; \ } \ \ - STC_INLINE _cx_result_t \ + STC_INLINE _cx_result \ _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped) { \ return _cx_memb(_insert_or_assign)(self, key, mapped); \ } \ \ - STC_INLINE _cx_result_t \ + STC_INLINE _cx_result \ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { \ - _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey); \ + _cx_result 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; \ } \ \ - STC_INLINE _cx_mapped_t* \ + STC_INLINE _cx_mapped* \ _cx_memb(_at)(const _cx_self* self, i_keyraw rkey) { \ - _cx_iter_t it; \ + _cx_iter it; \ return &_cx_memb(_find_it)(self, rkey, &it)->second; \ }) \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_begin)(const _cx_self* self) { \ - _cx_iter_t it = {NULL, 0, self->root}; \ + _cx_iter it = {NULL, 0, self->root}; \ _cx_memb(_next)(&it); return it; \ } \ \ - STC_INLINE _cx_iter_t \ + STC_INLINE _cx_iter \ _cx_memb(_end)(const _cx_self* self) {\ - _cx_iter_t it = {NULL}; return it; \ + _cx_iter it = {NULL}; return it; \ } \ \ STC_INLINE size_t \ @@ -184,8 +184,8 @@ int main(void) { self->size -= erased; return erased; \ } \ \ - STC_INLINE _cx_iter_t \ - _cx_memb(_advance)(_cx_iter_t it, size_t n) { \ + STC_INLINE _cx_iter \ + _cx_memb(_advance)(_cx_iter it, size_t n) { \ while (n-- && it.ref) _cx_memb(_next)(&it); \ return it; \ } \ @@ -208,30 +208,30 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen i_keydel, i_keyfrom, i_keyto, i_keyraw) \ STC_DEF _cx_self \ _cx_memb(_init)(void) { \ - _cx_self cx = {(_cx_node_t *) &_aatree_sentinel, 0}; \ + _cx_self cx = {(_cx_node *) &_aatree_sentinel, 0}; \ return cx; \ } \ \ - STC_DEF _cx_value_t* \ + STC_DEF _cx_value* \ _cx_memb(_front)(const _cx_self* self) { \ - _cx_node_t *tn = self->root; \ + _cx_node *tn = self->root; \ while (tn->link[0]->level) tn = tn->link[0]; \ return &tn->value; \ } \ \ - STC_DEF _cx_value_t* \ + STC_DEF _cx_value* \ _cx_memb(_back)(const _cx_self* self) { \ - _cx_node_t *tn = self->root; \ + _cx_node *tn = self->root; \ while (tn->link[1]->level) tn = tn->link[1]; \ return &tn->value; \ } \ \ - STC_DEF _cx_value_t* \ - _cx_memb(_find_it)(const _cx_self* self, _cx_rawkey_t rkey, _cx_iter_t* out) { \ - _cx_node_t *tn = self->root; \ + STC_DEF _cx_value* \ + _cx_memb(_find_it)(const _cx_self* self, _cx_rawkey rkey, _cx_iter* out) { \ + _cx_node *tn = self->root; \ out->_top = 0; \ while (tn->level) { \ - int c; _cx_rawkey_t rx = i_keyto(cx_keyref(&tn->value)); \ + int c; _cx_rawkey rx = i_keyto(cx_keyref(&tn->value)); \ if ((c = i_cmp(&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); } \ @@ -239,12 +239,12 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen return (out->ref = NULL); \ } \ \ - STC_DEF _cx_iter_t \ + STC_DEF _cx_iter \ _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) { \ - _cx_iter_t it; \ + _cx_iter it; \ _cx_memb(_find_it)(self, rkey, &it); \ if (!it.ref && it._top) { \ - _cx_node_t *tn = it._st[--it._top]; \ + _cx_node *tn = it._st[--it._top]; \ it._tn = tn->link[1]; \ it.ref = &tn->value; \ } \ @@ -252,8 +252,8 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen } \ \ STC_DEF void \ - _cx_memb(_next)(_cx_iter_t *it) { \ - _cx_node_t *tn = it->_tn; \ + _cx_memb(_next)(_cx_iter *it) { \ + _cx_node *tn = it->_tn; \ if (it->_top || tn->level) { \ while (tn->level) { \ it->_st[it->_top++] = tn; \ @@ -266,10 +266,10 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen it->ref = NULL; \ } \ \ - static _cx_node_t * \ - _cx_memb(_skew_)(_cx_node_t *tn) { \ + static _cx_node * \ + _cx_memb(_skew_)(_cx_node *tn) { \ if (tn && tn->link[0]->level == tn->level && tn->level) { \ - _cx_node_t *tmp = tn->link[0]; \ + _cx_node *tmp = tn->link[0]; \ tn->link[0] = tmp->link[1]; \ tmp->link[1] = tn; \ tn = tmp; \ @@ -277,10 +277,10 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen return tn; \ } \ \ - static _cx_node_t * \ - _cx_memb(_split_)(_cx_node_t *tn) { \ + static _cx_node * \ + _cx_memb(_split_)(_cx_node *tn) { \ if (tn->link[1]->link[1]->level == tn->level && tn->level) { \ - _cx_node_t *tmp = tn->link[1]; \ + _cx_node *tmp = tn->link[1]; \ tn->link[1] = tmp->link[0]; \ tmp->link[0] = tn; \ tn = tmp; \ @@ -289,19 +289,19 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen return tn; \ } \ \ - static inline _cx_node_t* \ - _cx_memb(_insert_entry_i_)(_cx_node_t* tn, const _cx_rawkey_t* rkey, _cx_result_t* res) { \ - _cx_node_t *up[64], *tx = tn; \ + static inline _cx_node* \ + _cx_memb(_insert_entry_i_)(_cx_node* tn, const _cx_rawkey* rkey, _cx_result* res) { \ + _cx_node *up[64], *tx = tn; \ int c, top = 0, dir = 0; \ while (tx->level) { \ up[top++] = tx; \ - _cx_rawkey_t r = i_keyto(cx_keyref(&tx->value)); \ + _cx_rawkey r = i_keyto(cx_keyref(&tx->value)); \ if (!(c = i_cmp(&r, rkey))) {res->ref = &tx->value; return tn; } \ tx = tx->link[(dir = (c < 0))]; \ } \ - tn = c_new(_cx_node_t); \ + tn = c_new(_cx_node); \ res->ref = &tn->value, res->inserted = true; \ - tn->link[0] = tn->link[1] = (_cx_node_t*) &_aatree_sentinel, tn->level = 1; \ + tn->link[0] = tn->link[1] = (_cx_node*) &_aatree_sentinel, tn->level = 1; \ if (top == 0) return tn; \ up[top - 1]->link[dir] = tn; \ while (top--) { \ @@ -313,20 +313,20 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen return up[0]; \ } \ \ - STC_DEF _cx_result_t \ + STC_DEF _cx_result \ _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { \ - _cx_result_t res = {NULL, false}; \ + _cx_result res = {NULL, false}; \ self->root = _cx_memb(_insert_entry_i_)(self->root, &rkey, &res); \ self->size += res.inserted; \ return res; \ } \ \ - STC_DEF _cx_node_t* \ - _cx_memb(_erase_r_)(_cx_node_t *tn, const _cx_rawkey_t* rkey, int *erased) { \ + STC_DEF _cx_node* \ + _cx_memb(_erase_r_)(_cx_node *tn, const _cx_rawkey* rkey, int *erased) { \ if (tn->level == 0) \ return tn; \ - _cx_rawkey_t raw = i_keyto(cx_keyref(&tn->value)); \ - _cx_node_t *tx; int c = i_cmp(&raw, rkey); \ + _cx_rawkey raw = i_keyto(cx_keyref(&tn->value)); \ + _cx_node *tx; int c = i_cmp(&raw, rkey); \ if (c != 0) \ tn->link[c < 0] = _cx_memb(_erase_r_)(tn->link[c < 0], rkey, erased); \ else { \ @@ -355,9 +355,9 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen } \ return tn; \ } \ - STC_DEF _cx_iter_t \ - _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { \ - _cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt; \ + STC_DEF _cx_iter \ + _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { \ + _cx_rawkey raw = i_keyto(cx_keyref(it.ref)), nxt; \ _cx_memb(_next)(&it); \ if (it.ref) nxt = i_keyto(cx_keyref(it.ref)); \ _cx_memb(_erase)(self, raw); \ @@ -365,12 +365,12 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen return it; \ } \ \ - STC_DEF _cx_iter_t \ - _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { \ + STC_DEF _cx_iter \ + _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { \ 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_key k1 = *cx_keyref(it1.ref), k2 = *cx_keyref(it2.ref); \ + _cx_rawkey r1 = i_keyto(&k1); \ for (;;) { \ if (memcmp(&k1, &k2, sizeof k1) == 0) return it1; \ _cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref); \ @@ -379,10 +379,10 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen } \ } \ \ - STC_DEF _cx_node_t* \ - _cx_memb(_clone_r_)(_cx_node_t *tn) { \ + STC_DEF _cx_node* \ + _cx_memb(_clone_r_)(_cx_node *tn) { \ if (! tn->level) return tn; \ - _cx_node_t *cn = c_new(_cx_node_t); \ + _cx_node *cn = c_new(_cx_node); \ cn->link[0] = _cx_memb(_clone_r_)(tn->link[0]); \ cn->link[1] = _cx_memb(_clone_r_)(tn->link[1]); \ cn->level = tn->level; \ @@ -391,7 +391,7 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen } \ \ STC_DEF void \ - _cx_memb(_del_r_)(_cx_node_t* tn) { \ + _cx_memb(_del_r_)(_cx_node* tn) { \ if (tn->level != 0) { \ _cx_memb(_del_r_)(tn->link[0]); \ _cx_memb(_del_r_)(tn->link[1]); \ diff --git a/include/stc/carr2.h b/include/stc/carr2.h index 80a47a34..3f9d1540 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -62,21 +62,21 @@ _cx_deftypes(_c_carr2_types, _cx_self, i_val); #endif STC_API _cx_self _cx_memb(_with_values)(size_t xdim, size_t ydim, i_val value); -STC_API _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value_t* storage); +STC_API _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value* storage); STC_API _cx_self _cx_memb(_clone)(_cx_self src); -STC_API _cx_value_t* _cx_memb(_release)(_cx_self* self); +STC_API _cx_value* _cx_memb(_release)(_cx_self* self); STC_API void _cx_memb(_del)(_cx_self* self); STC_INLINE _cx_self _cx_memb(_init)(size_t xdim, size_t ydim) { - return _cx_memb(_with_storage)(xdim, ydim, c_new_n(_cx_value_t, xdim*ydim)); + return _cx_memb(_with_storage)(xdim, ydim, c_new_n(_cx_value, xdim*ydim)); } STC_INLINE size_t _cx_memb(_size)(_cx_self arr) { return arr.xdim*arr.ydim; } -STC_INLINE _cx_value_t *_cx_memb(_data)(_cx_self* self) +STC_INLINE _cx_value *_cx_memb(_data)(_cx_self* self) { return *self->data; } -STC_INLINE _cx_value_t *_cx_memb(_at)(_cx_self* self, size_t x, size_t y) +STC_INLINE _cx_value *_cx_memb(_at)(_cx_self* self, size_t x, size_t y) { return *self->data + self->ydim*x + y; } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { @@ -84,20 +84,20 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter_t){*self->data}; } +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter){*self->data}; } -STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){*self->data + self->xdim*self->ydim}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){*self->data + self->xdim*self->ydim}; } -STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp) -STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value_t* block) { - _cx_self _arr = {c_new_n(_cx_value_t*, xdim), xdim, ydim}; +STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value* block) { + _cx_self _arr = {c_new_n(_cx_value*, xdim), xdim, ydim}; for (size_t x = 0; x < xdim; ++x, block += ydim) _arr.data[x] = block; return _arr; @@ -105,20 +105,20 @@ STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value_t* STC_DEF _cx_self _cx_memb(_with_values)(size_t xdim, size_t ydim, i_val value) { _cx_self _arr = _cx_memb(_init)(xdim, ydim); - for (_cx_value_t* p = _arr.data[0], *e = p + xdim*ydim; p != e; ++p) + for (_cx_value* p = _arr.data[0], *e = p + xdim*ydim; p != e; ++p) *p = value; return _arr; } STC_DEF _cx_self _cx_memb(_clone)(_cx_self src) { _cx_self _arr = _cx_memb(_init)(src.xdim, src.ydim); - for (_cx_value_t* p = _arr.data[0], *q = src.data[0], *e = p + _cx_memb(_size)(src); p != e; ++p, ++q) + for (_cx_value* p = _arr.data[0], *q = src.data[0], *e = p + _cx_memb(_size)(src); p != e; ++p, ++q) *p = i_valfrom(i_valto(q)); return _arr; } -STC_DEF _cx_value_t *_cx_memb(_release)(_cx_self* self) { - _cx_value_t *values = self->data[0]; +STC_DEF _cx_value *_cx_memb(_release)(_cx_self* self) { + _cx_value *values = self->data[0]; c_free(self->data); self->data = NULL; return values; @@ -126,7 +126,7 @@ STC_DEF _cx_value_t *_cx_memb(_release)(_cx_self* self) { STC_DEF void _cx_memb(_del)(_cx_self* self) { if (!self->data) return; - for (_cx_value_t* p = self->data[0], *e = p + _cx_memb(_size)(*self); p != e; ++p) + for (_cx_value* p = self->data[0], *e = p + _cx_memb(_size)(*self); p != e; ++p) i_valdel(p); c_free(self->data[0]); /* values */ c_free(self->data); /* pointers */ diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 135acda0..1133dcc3 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -63,22 +63,22 @@ _cx_deftypes(_c_carr3_types, _cx_self, i_val); #endif STC_API _cx_self _cx_memb(_with_values)(size_t xdim, size_t ydim, size_t zdim, i_val value); -STC_API _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, _cx_value_t* storage); +STC_API _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, _cx_value* storage); STC_API _cx_self _cx_memb(_clone)(_cx_self src); -STC_API _cx_value_t* _cx_memb(_release)(_cx_self* self); +STC_API _cx_value* _cx_memb(_release)(_cx_self* self); STC_API void _cx_memb(_del)(_cx_self* self); STC_INLINE _cx_self _cx_memb(_init)(size_t xdim, size_t ydim, size_t zdim) { - return _cx_memb(_with_storage)(xdim, ydim, zdim, c_new_n(_cx_value_t, xdim*ydim*zdim)); + return _cx_memb(_with_storage)(xdim, ydim, zdim, c_new_n(_cx_value, xdim*ydim*zdim)); } STC_INLINE size_t _cx_memb(_size)(_cx_self arr) { return arr.xdim*arr.ydim*arr.zdim; } -STC_INLINE _cx_value_t* _cx_memb(_data)(_cx_self* self) +STC_INLINE _cx_value* _cx_memb(_data)(_cx_self* self) { return **self->data; } -STC_INLINE _cx_value_t* _cx_memb(_at)(_cx_self* self, size_t x, size_t y, size_t z) +STC_INLINE _cx_value* _cx_memb(_at)(_cx_self* self, size_t x, size_t y, size_t z) { return **self->data + self->zdim*(self->ydim*x + y) + z; } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { @@ -86,21 +86,21 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter_t){**self->data}; } +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter){**self->data}; } -STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){**self->data + _cx_memb(_size)(*self)}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){**self->data + _cx_memb(_size)(*self)}; } -STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp) -STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, _cx_value_t* block) { - _cx_self _arr = {c_new_n(_cx_value_t**, xdim*(ydim + 1)), xdim, ydim, zdim}; - _cx_value_t** p = (_cx_value_t**) &_arr.data[xdim]; +STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, _cx_value* block) { + _cx_self _arr = {c_new_n(_cx_value**, xdim*(ydim + 1)), xdim, ydim, zdim}; + _cx_value** p = (_cx_value**) &_arr.data[xdim]; for (size_t x = 0, y; x < xdim; ++x, p += ydim) for (_arr.data[x] = p, y = 0; y < ydim; ++y, block += zdim) _arr.data[x][y] = block; @@ -109,20 +109,20 @@ STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, STC_DEF _cx_self _cx_memb(_with_values)(size_t xdim, size_t ydim, size_t zdim, i_val value) { _cx_self _arr = _cx_memb(_init)(xdim, ydim, zdim); - for (_cx_value_t* p = **_arr.data, *e = p + xdim*ydim*zdim; p != e; ++p) + for (_cx_value* p = **_arr.data, *e = p + xdim*ydim*zdim; p != e; ++p) *p = value; return _arr; } STC_DEF _cx_self _cx_memb(_clone)(_cx_self src) { _cx_self _arr = _cx_memb(_init)(src.xdim, src.ydim, src.zdim); - for (_cx_value_t* p = **_arr.data, *q = **src.data, *e = p + _cx_memb(_size)(src); p != e; ++p, ++q) + for (_cx_value* p = **_arr.data, *q = **src.data, *e = p + _cx_memb(_size)(src); p != e; ++p, ++q) *p = i_valfrom(i_valto(q)); return _arr; } -STC_DEF _cx_value_t* _cx_memb(_release)(_cx_self* self) { - _cx_value_t *values = self->data[0][0]; +STC_DEF _cx_value* _cx_memb(_release)(_cx_self* self) { + _cx_value *values = self->data[0][0]; c_free(self->data); self->data = NULL; return values; @@ -130,7 +130,7 @@ STC_DEF _cx_value_t* _cx_memb(_release)(_cx_self* self) { STC_DEF void _cx_memb(_del)(_cx_self* self) { if (!self->data) return; - for (_cx_value_t* p = **self->data, *e = p + _cx_memb(_size)(*self); p != e; ++p) + for (_cx_value* p = **self->data, *e = p + _cx_memb(_size)(*self); p != e; ++p) i_valdel(p); c_free(self->data[0][0]); /* data */ c_free(self->data); /* pointers */ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 0f09238c..e5e0fe67 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -39,24 +39,24 @@ struct cdeq_rep { size_t size, cap; void* base[]; }; #if !defined i_fwd _cx_deftypes(_c_cdeq_types, _cx_self, i_val); #endif -typedef i_valraw _cx_rawvalue_t; +typedef i_valraw _cx_rawvalue; STC_API _cx_self _cx_memb(_init)(void); STC_API _cx_self _cx_memb(_clone)(_cx_self cx); STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_del)(_cx_self* self); -STC_API _cx_value_t* _cx_memb(_push_back)(_cx_self* self, i_val value); +STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); STC_API void _cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n); #ifndef i_queue -STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t p1, _cx_iter_t p2, i_valraw raw); -STC_API int _cx_memb(_value_compare)(const _cx_value_t* x, const _cx_value_t* y); -STC_API _cx_value_t* _cx_memb(_push_front)(_cx_self* self, i_val value); -STC_API _cx_iter_t _cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2); -STC_API _cx_iter_t _cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_value_t* p1, const _cx_value_t* p2, bool clone); -STC_API _cx_iter_t _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_rawvalue_t* p1, const _cx_rawvalue_t* p2); +STC_API _cx_iter _cx_memb(_find_in)(_cx_iter p1, _cx_iter p2, i_valraw raw); +STC_API int _cx_memb(_value_compare)(const _cx_value* x, const _cx_value* y); +STC_API _cx_value* _cx_memb(_push_front)(_cx_self* self, i_val value); +STC_API _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2); +STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, + const _cx_value* p1, const _cx_value* p2, bool clone); +STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, + const _cx_rawvalue* p1, const _cx_rawvalue* p2); #endif // i_queue STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return !cdeq_rep_(&cx)->size; } @@ -64,26 +64,26 @@ STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cdeq_rep_(&cx)->si STC_INLINE size_t _cx_memb(_capacity)(_cx_self cx) { return cdeq_rep_(&cx)->cap; } STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) {c_swap(_cx_self, *a, *b); } STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } -STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* pval) { return i_valto(pval); } +STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* pval) { return i_valto(pval); } STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_value_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) { i_valdel(self->data); ++self->data; --cdeq_rep_(self)->size; } -STC_INLINE _cx_value_t* _cx_memb(_back)(const _cx_self* self) +STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + cdeq_rep_(self)->size - 1; } -STC_INLINE _cx_value_t* _cx_memb(_front)(const _cx_self* self) { return self->data; } -STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data}; } -STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data + cdeq_rep_(self)->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; } -STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs) +STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; } +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter){self->data}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){self->data + cdeq_rep_(self)->size}; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) { it.ref += offs; return it; } STC_INLINE _cx_self @@ -103,21 +103,21 @@ _cx_memb(_shrink_to_fit)(_cx_self *self) { #ifndef i_queue -STC_INLINE _cx_value_t* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) { +STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_front)(self, i_valfrom(raw)); } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { - _cx_value_t* p = &self->data[--cdeq_rep_(self)->size]; + _cx_value* p = &self->data[--cdeq_rep_(self)->size]; i_valdel(p); } -STC_INLINE _cx_value_t* _cx_memb(_at)(const _cx_self* self, size_t idx) { +STC_INLINE _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < cdeq_rep_(self)->size); return self->data + idx; } -STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter_t it) { +STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) { return it.ref - cx.data; } @@ -127,64 +127,64 @@ _cx_memb(_reserve)(_cx_self* self, size_t n) { if (n > sz) _cx_memb(_expand_right_half_)(self, sz, n - sz); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_insert)(_cx_self* self, size_t idx, i_val value) { return _cx_memb(_insert_range_p)(self, self->data + idx, &value, &value + 1, false); } -STC_INLINE _cx_iter_t -_cx_memb(_insert_n)(_cx_self* self, size_t idx, const _cx_value_t arr[], size_t n) { +STC_INLINE _cx_iter +_cx_memb(_insert_n)(_cx_self* self, size_t idx, const _cx_value arr[], size_t n) { return _cx_memb(_insert_range_p)(self, self->data + idx, arr, arr + n, false); } -STC_INLINE _cx_iter_t -_cx_memb(_insert_at)(_cx_self* self, _cx_iter_t it, i_val value) { +STC_INLINE _cx_iter +_cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_val value) { return _cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1, false); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, size_t idx, i_valraw raw) { return _cx_memb(_emplace_range_p)(self, self->data + idx, &raw, &raw + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_n)(_cx_self* self, size_t idx, const _cx_rawvalue_t arr[], size_t n) { +STC_INLINE _cx_iter +_cx_memb(_emplace_n)(_cx_self* self, size_t idx, const _cx_rawvalue arr[], size_t n) { return _cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + n); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_at)(_cx_self* self, _cx_iter_t it, i_valraw raw) { +STC_INLINE _cx_iter +_cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, i_valraw raw) { return _cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_range)(_cx_self* self, _cx_iter_t it, _cx_iter_t it1, _cx_iter_t it2) { +STC_INLINE _cx_iter +_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { return _cx_memb(_insert_range_p)(self, it.ref, it1.ref, it2.ref, true); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_erase_n)(_cx_self* self, size_t idx, size_t n) { return _cx_memb(_erase_range_p)(self, self->data + idx, self->data + idx + n); } -STC_INLINE _cx_iter_t -_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { +STC_INLINE _cx_iter +_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { return _cx_memb(_erase_range_p)(self, it.ref, it.ref + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { +STC_INLINE _cx_iter +_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_valraw raw) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw); } -STC_INLINE _cx_value_t* +STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_valraw raw) { - _cx_iter_t end = _cx_memb(_end)(self); - _cx_value_t* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref; + _cx_iter end = _cx_memb(_end)(self); + _cx_value* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref; return val == end.ref ? NULL : val; } STC_INLINE void -_cx_memb(_sort_range)(_cx_iter_t i1, _cx_iter_t i2, - int(*_cmp_)(const _cx_value_t*, const _cx_value_t*)) { +_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, + int(*_cmp_)(const _cx_value*, const _cx_value*)) { qsort(i1.ref, i2.ref - i1.ref, sizeof *i1.ref, (int(*)(const void*, const void*)) _cmp_); } @@ -204,7 +204,7 @@ static struct cdeq_rep _cdeq_sentinel = {0, 0}; STC_DEF _cx_self _cx_memb(_init)(void) { - _cx_value_t *b = (_cx_value_t *) _cdeq_sentinel.base; + _cx_value *b = (_cx_value *) _cdeq_sentinel.base; return c_make(_cx_self){b, b}; } @@ -212,7 +212,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { struct cdeq_rep* rep = cdeq_rep_(self); if (rep->cap) { - for (_cx_value_t *p = self->data, *q = p + rep->size; p != q; ++p) + for (_cx_value *p = self->data, *q = p + rep->size; p != q; ++p) i_valdel(p); rep->size = 0; } @@ -233,7 +233,7 @@ _cx_memb(_realloc_)(_cx_self* self, size_t n) { rep = (struct cdeq_rep*) c_realloc(rep->cap ? rep : NULL, offsetof(struct cdeq_rep, base) + cap*sizeof(i_val)); rep->size = sz, rep->cap = cap; - self->_base = (_cx_value_t *) rep->base; + self->_base = (_cx_value *) rep->base; self->data = self->_base + nfront; return cap; } @@ -258,12 +258,12 @@ _cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n) { } } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { struct cdeq_rep* rep = cdeq_rep_(self); if (_cdeq_nfront(self) + rep->size == rep->cap) _cx_memb(_expand_right_half_)(self, rep->size, 1); - _cx_value_t *v = self->data + cdeq_rep_(self)->size++; + _cx_value *v = self->data + cdeq_rep_(self)->size++; *v = value; return v; } @@ -284,18 +284,18 @@ _cx_memb(_expand_left_half_)(_cx_self* self, size_t idx, size_t n) { size_t sz = rep->size, cap = rep->cap; size_t nfront = _cdeq_nfront(self), nback = cap - sz - nfront; if (nfront >= n) { - self->data = (_cx_value_t *) memmove(self->data - n, self->data, idx*sizeof(i_val)); + self->data = (_cx_value *) memmove(self->data - n, self->data, idx*sizeof(i_val)); } else { if (sz*1.3 + n > cap) cap = _cx_memb(_realloc_)(self, n); size_t unused = cap - (sz + n); size_t pos = (nback*2 < unused) ? unused - nback : unused/2; memmove(self->_base + pos + idx + n, self->data + idx, (sz - idx)*sizeof(i_val)); - self->data = (_cx_value_t *) memmove(self->_base + pos, self->data, idx*sizeof(i_val)); + self->data = (_cx_value *) memmove(self->_base + pos, self->data, idx*sizeof(i_val)); } } -STC_DEF _cx_value_t* -_cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* pos, size_t n) { +STC_DEF _cx_value* +_cx_memb(_insert_space_)(_cx_self* self, _cx_value* pos, size_t n) { size_t idx = pos - self->data; if (idx*2 < cdeq_rep_(self)->size) _cx_memb(_expand_left_half_)(self, idx, n); else _cx_memb(_expand_right_half_)(self, idx, n); @@ -303,7 +303,7 @@ _cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* pos, size_t n) { return self->data + idx; } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_push_front)(_cx_self* self, i_val value) { if (self->data == self->_base) _cx_memb(_expand_left_half_)(self, 0, 1); @@ -314,39 +314,39 @@ _cx_memb(_push_front)(_cx_self* self, i_val value) { return self->data; } -STC_DEF _cx_iter_t -_cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_value_t* p1, const _cx_value_t* p2, bool clone) { +STC_DEF _cx_iter +_cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, + const _cx_value* p1, const _cx_value* p2, bool clone) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); - _cx_iter_t it = {pos}; + _cx_iter it = {pos}; if (clone) for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); else memcpy(pos, p1, (p2 - p1)*sizeof *p1); return it; } -STC_DEF _cx_iter_t -_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos, const _cx_rawvalue_t* p1, const _cx_rawvalue_t* p2) { +STC_DEF _cx_iter +_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_rawvalue* p1, const _cx_rawvalue* p2) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); - _cx_iter_t it = {pos}; + _cx_iter it = {pos}; for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } -STC_DEF _cx_iter_t -_cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2) { +STC_DEF _cx_iter +_cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { size_t n = p2 - p1; if (n > 0) { - _cx_value_t* p = p1, *end = self->data + cdeq_rep_(self)->size; + _cx_value* p = p1, *end = self->data + cdeq_rep_(self)->size; for (; p != p2; ++p) i_valdel(p); if (p1 == self->data) self->data += n; else memmove(p1, p2, (end - p2) * sizeof(i_val)); cdeq_rep_(self)->size -= n; } - return c_make(_cx_iter_t){p1}; + return c_make(_cx_iter){p1}; } -STC_DEF _cx_iter_t -_cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { +STC_DEF _cx_iter +_cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, i_valraw raw) { for (; i1.ref != i2.ref; ++i1.ref) { i_valraw r = i_valto(i1.ref); if (i_cmp(&raw, &r) == 0) return i1; @@ -355,7 +355,7 @@ _cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { } STC_DEF int -_cx_memb(_value_compare)(const _cx_value_t* x, const _cx_value_t* y) { +_cx_memb(_value_compare)(const _cx_value* x, const _cx_value* y) { i_valraw rx = i_valto(x); i_valraw ry = i_valto(y); return i_cmp(&rx, &ry); diff --git a/include/stc/clist.h b/include/stc/clist.h index 85f14378..4d5cbd8d 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -64,13 +64,13 @@ SELF##_value_t value; \ } -#define clist_node_(vp) c_container_of(vp, _cx_node_t, value) +#define clist_node_(vp) c_container_of(vp, _cx_node, value) _c_clist_types(clist_VOID, int); _c_clist_complete_types(clist_VOID, dummy); #define _c_clist_insert_after(self, _cx_self, node, val) \ - _cx_node_t *entry = c_new (_cx_node_t); \ + _cx_node *entry = c_new (_cx_node); \ if (node) entry->next = node->next, node->next = entry; \ else entry->next = entry; \ entry->value = val @@ -87,23 +87,23 @@ _c_clist_complete_types(clist_VOID, dummy); _cx_deftypes(_c_clist_types, _cx_self, i_val); #endif _cx_deftypes(_c_clist_complete_types, _cx_self, dummy); -typedef i_valraw _cx_rawvalue_t; +typedef i_valraw _cx_rawvalue; STC_API size_t _clist_count(const clist_VOID* self); STC_API _cx_self _cx_memb(_clone)(_cx_self cx); STC_API void _cx_memb(_del)(_cx_self* self); -STC_API _cx_value_t* _cx_memb(_push_back)(_cx_self* self, i_val value); -STC_API _cx_value_t* _cx_memb(_push_front)(_cx_self* self, i_val value); -STC_API _cx_iter_t _cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value); -STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it); -STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2); +STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); +STC_API _cx_value* _cx_memb(_push_front)(_cx_self* self, i_val value); +STC_API _cx_iter _cx_memb(_insert)(_cx_self* self, _cx_iter it, i_val value); +STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); +STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); STC_API size_t _cx_memb(_remove)(_cx_self* self, i_valraw val); -STC_API _cx_iter_t _cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other); -STC_API _cx_self _cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2); +STC_API _cx_iter _cx_memb(_splice)(_cx_self* self, _cx_iter it, _cx_self* other); +STC_API _cx_self _cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2); STC_API void _cx_memb(_sort)(_cx_self* self); -STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val); -STC_API _cx_node_t* _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node); +STC_API _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, i_valraw val); +STC_API _cx_node* _cx_memb(_erase_after_)(_cx_self* self, _cx_node* node); STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; } STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return cx.last == NULL; } @@ -111,19 +111,19 @@ STC_INLINE size_t _cx_memb(_count)(_cx_self cx) { return _clist_count((const clist_VOID*) &cx); } STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_del)(self); } STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } -STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* pval) { return i_valto(pval); } +STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* pval) { return i_valto(pval); } STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) { _cx_memb(_erase_after_)(self, self->last); } -STC_INLINE _cx_value_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_back)(self, i_valfrom(raw)); } -STC_INLINE _cx_value_t* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) +STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_front)(self, i_valfrom(raw)); } -STC_INLINE _cx_iter_t _cx_memb(_emplace)(_cx_self* self, _cx_iter_t it, i_valraw raw) +STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw) { return _cx_memb(_insert)(self, it, i_valfrom(raw)); } -STC_INLINE _cx_value_t* _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; } -STC_INLINE _cx_value_t* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; } +STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; } +STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { @@ -131,47 +131,47 @@ _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_iter_t -_cx_memb(_iterator)(const _cx_self* self, _cx_node_t* prev) { - return c_make(_cx_iter_t){&prev->next->value, &self->last, prev}; +STC_INLINE _cx_iter +_cx_memb(_iterator)(const _cx_self* self, _cx_node* prev) { + return c_make(_cx_iter){&prev->next->value, &self->last, prev}; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - _cx_value_t* head = self->last ? &self->last->next->value : NULL; - return c_make(_cx_iter_t){head, &self->last, self->last}; + _cx_value* head = self->last ? &self->last->next->value : NULL; + return c_make(_cx_iter){head, &self->last, self->last}; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { - return c_make(_cx_iter_t){NULL}; + return c_make(_cx_iter){NULL}; } STC_INLINE void -_cx_memb(_next)(_cx_iter_t* it) { - _cx_node_t* node = it->prev = clist_node_(it->ref); +_cx_memb(_next)(_cx_iter* it) { + _cx_node* node = it->prev = clist_node_(it->ref); it->ref = (node == *it->_last ? NULL : &node->next->value); } -STC_INLINE _cx_iter_t -_cx_memb(_advance)(_cx_iter_t it, size_t n) { +STC_INLINE _cx_iter +_cx_memb(_advance)(_cx_iter it, size_t n) { while (n-- && it.ref) _cx_memb(_next)(&it); return it; } -STC_INLINE _cx_iter_t -_cx_memb(_splice_range)(_cx_self* self, _cx_iter_t it, - _cx_self* other, _cx_iter_t it1, _cx_iter_t it2) { +STC_INLINE _cx_iter +_cx_memb(_splice_range)(_cx_self* self, _cx_iter it, + _cx_self* other, _cx_iter it1, _cx_iter it2) { _cx_self tmp = _cx_memb(_split_off)(other, it1, it2); return _cx_memb(_splice)(self, it, &tmp); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_valraw val) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val); } -STC_INLINE _cx_value_t* +STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_valraw val) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val).ref; } @@ -192,23 +192,23 @@ _cx_memb(_del)(_cx_self* self) { while (self->last) _cx_memb(_erase_after_)(self, self->last); } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { _c_clist_insert_after(self, _cx_self, self->last, value); self->last = entry; return &entry->value; } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_push_front)(_cx_self* self, i_val value) { _c_clist_insert_after(self, _cx_self, self->last, value); if (!self->last) self->last = entry; return &entry->value; } -STC_DEF _cx_iter_t -_cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value) { - _cx_node_t* node = it.ref ? it.prev : self->last; +STC_DEF _cx_iter +_cx_memb(_insert)(_cx_self* self, _cx_iter it, i_val value) { + _cx_node* node = it.ref ? it.prev : self->last; _c_clist_insert_after(self, _cx_self, node, value); if (!self->last || !it.ref) { it.prev = self->last ? self->last : entry; @@ -218,25 +218,25 @@ _cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value) { return it; } -STC_DEF _cx_iter_t -_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { - _cx_node_t *node = clist_node_(it.ref); +STC_DEF _cx_iter +_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { + _cx_node *node = clist_node_(it.ref); it.ref = (node == self->last) ? NULL : &node->next->value; _cx_memb(_erase_after_)(self, it.prev); return it; } -STC_DEF _cx_iter_t -_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { - _cx_node_t *node = it1.ref ? it1.prev : NULL, +STC_DEF _cx_iter +_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { + _cx_node *node = it1.ref ? it1.prev : NULL, *done = it2.ref ? clist_node_(it2.ref) : NULL; while (node && node->next != done) node = _cx_memb(_erase_after_)(self, node); return it2; } -STC_DEF _cx_iter_t -_cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val) { +STC_DEF _cx_iter +_cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, i_valraw val) { c_foreach (it, _cx_self, it1, it2) { i_valraw r = i_valto(it.ref); if (i_cmp(&r, &val) == 0) return it; @@ -244,9 +244,9 @@ _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val) { it2.ref = NULL; return it2; } -STC_DEF _cx_node_t* -_cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node) { - _cx_node_t* del = node->next, *next = del->next; +STC_DEF _cx_node* +_cx_memb(_erase_after_)(_cx_self* self, _cx_node* node) { + _cx_node* del = node->next, *next = del->next; node->next = next; if (del == next) self->last = node = NULL; else if (self->last == del) self->last = node, node = NULL; @@ -257,7 +257,7 @@ _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node) { STC_DEF size_t _cx_memb(_remove)(_cx_self* self, i_valraw val) { size_t n = 0; - _cx_node_t* prev = self->last, *node; + _cx_node* prev = self->last, *node; while (prev) { node = prev->next; i_valraw r = i_valto(&node->value); @@ -269,12 +269,12 @@ _cx_memb(_remove)(_cx_self* self, i_valraw val) { return n; } -STC_DEF _cx_iter_t -_cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other) { +STC_DEF _cx_iter +_cx_memb(_splice)(_cx_self* self, _cx_iter it, _cx_self* other) { if (!self->last) self->last = other->last; else if (other->last) { - _cx_node_t *p = it.ref ? it.prev : self->last, *next = p->next; + _cx_node *p = it.ref ? it.prev : self->last, *next = p->next; it.prev = other->last; p->next = it.prev->next; it.prev->next = next; @@ -284,10 +284,10 @@ _cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other) { } STC_DEF _cx_self -_cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { +_cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2) { _cx_self cx = {NULL}; if (it1.ref == it2.ref) return cx; - _cx_node_t *p1 = it1.prev, + _cx_node *p1 = it1.prev, *p2 = it2.ref ? it2.prev : self->last; p1->next = p2->next, p2->next = clist_node_(it1.ref); if (self->last == p2) self->last = (p1 == p2) ? NULL : p1; @@ -297,8 +297,8 @@ _cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { STC_DEF int _cx_memb(_sort_cmp_)(const clist_VOID_node_t* x, const clist_VOID_node_t* y) { - i_valraw a = i_valto(&((const _cx_node_t *) x)->value); - i_valraw b = i_valto(&((const _cx_node_t *) y)->value); + i_valraw a = i_valto(&((const _cx_node *) x)->value); + i_valraw b = i_valto(&((const _cx_node *) y)->value); return i_cmp(&a, &b); } @@ -308,7 +308,7 @@ _clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const clist_VOID_node_t*, c STC_DEF void _cx_memb(_sort)(_cx_self* self) { if (self->last) - self->last = (_cx_node_t *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_)); + self->last = (_cx_node *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_)); } #endif // TEMPLATE IMPLEMENTATION diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 61147345..df0f43c9 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -75,26 +75,26 @@ typedef struct { MAP_SIZE_T idx; uint_fast8_t hx; } chash_bucket_t; _cx_deftypes(_c_chash_types, _cx_self, i_key, i_val, cx_MAP_ONLY, cx_SET_ONLY); #endif -cx_MAP_ONLY( struct _cx_value_t { - _cx_key_t first; - _cx_mapped_t second; +cx_MAP_ONLY( struct _cx_value { + _cx_key first; + _cx_mapped second; }; ) -typedef i_keyraw _cx_rawkey_t; +typedef i_keyraw _cx_rawkey; 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; +_cx_rawvalue; STC_API _cx_self _cx_memb(_with_capacity)(size_t cap); STC_API _cx_self _cx_memb(_clone)(_cx_self map); STC_API void _cx_memb(_del)(_cx_self* self); STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_reserve)(_cx_self* self, size_t capacity); -STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey_t* rkeyptr); -STC_API _cx_result_t _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); -STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value_t* val); +STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr); +STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); +STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self)_cmap_inits; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } @@ -109,15 +109,15 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } cx_MAP_ONLY( - STC_API _cx_result_t _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); - STC_API _cx_result_t _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); + STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); + STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); - STC_INLINE _cx_result_t /* short-form, like operator[]: */ + STC_INLINE _cx_result /* short-form, like operator[]: */ _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped) { return _cx_memb(_insert_or_assign)(self, key, mapped); } - STC_INLINE _cx_mapped_t* + STC_INLINE _cx_mapped* _cx_memb(_at)(const _cx_self* self, i_keyraw rkey) { chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey); assert(self->_hashx[b.idx]); @@ -126,26 +126,26 @@ cx_MAP_ONLY( ) STC_INLINE void -_cx_memb(_value_clone)(_cx_value_t* _dst, _cx_value_t* _val) { +_cx_memb(_value_clone)(_cx_value* _dst, _cx_value* _val) { *cx_keyref(_dst) = i_keyfrom(i_keyto(cx_keyref(_val))); cx_MAP_ONLY( _dst->second = i_valfrom(i_valto(&_val->second)); ) } -STC_INLINE _cx_rawvalue_t -_cx_memb(_value_toraw)(_cx_value_t* val) { +STC_INLINE _cx_rawvalue +_cx_memb(_value_toraw)(_cx_value* val) { return cx_SET_ONLY( i_keyto(val) ) - cx_MAP_ONLY( c_make(_cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} ); + cx_MAP_ONLY( c_make(_cx_rawvalue){i_keyto(&val->first), i_valto(&val->second)} ); } STC_INLINE void -_cx_memb(_value_del)(_cx_value_t* _val) { +_cx_memb(_value_del)(_cx_value* _val) { i_keydel(cx_keyref(_val)); cx_MAP_ONLY( i_valdel(&_val->second); ) } -STC_INLINE _cx_result_t +STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { - _cx_result_t _res = _cx_memb(_insert_entry_)(self, rkey); + _cx_result _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); ) @@ -153,46 +153,46 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped) return _res; } -STC_INLINE _cx_result_t +STC_INLINE _cx_result _cx_memb(_insert)(_cx_self* self, i_key _key cx_MAP_ONLY(, i_val _mapped)) { - _cx_result_t _res = _cx_memb(_insert_entry_)(self, i_keyto(&_key)); + _cx_result _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); )} return _res; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_keyraw rkey) { - _cx_size_t idx; + _cx_size idx; if (!(self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])) idx = self->bucket_count; - return c_make(_cx_iter_t){self->table+idx, self->_hashx+idx}; + return c_make(_cx_iter){self->table+idx, self->_hashx+idx}; } -STC_INLINE _cx_value_t* +STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_keyraw rkey) { - _cx_size_t idx; + _cx_size idx; return self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx] ? self->table + idx : NULL; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - _cx_iter_t it = {self->table, self->_hashx}; + _cx_iter it = {self->table, self->_hashx}; if (it._hx) while (*it._hx == 0) ++it.ref, ++it._hx; return it; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){self->table + self->bucket_count}; } + { return c_make(_cx_iter){self->table + self->bucket_count}; } STC_INLINE void -_cx_memb(_next)(_cx_iter_t* it) +_cx_memb(_next)(_cx_iter* it) { while ((++it->ref, *++it->_hx == 0)) ; } -STC_INLINE _cx_iter_t -_cx_memb(_advance)(_cx_iter_t it, size_t n) { +STC_INLINE _cx_iter +_cx_memb(_advance)(_cx_iter it, size_t n) { // UB if n > elements left while (n--) _cx_memb(_next)(&it); return it; @@ -205,8 +205,8 @@ _cx_memb(_erase)(_cx_self* self, i_keyraw rkey) { return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1 : 0; } -STC_INLINE _cx_iter_t -_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { +STC_INLINE _cx_iter +_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { _cx_memb(_erase_entry)(self, it.ref); if (*it._hx == 0) _cx_memb(_next)(&it); return it; @@ -239,7 +239,7 @@ _cx_memb(_with_capacity)(size_t cap) { STC_INLINE void _cx_memb(_wipe_)(_cx_self* self) { if (self->size == 0) return; - _cx_value_t* e = self->table, *end = e + self->bucket_count; + _cx_value* e = self->table, *end = e + self->bucket_count; uint8_t *hx = self->_hashx; for (; e != end; ++e) if (*hx++) _cx_memb(_value_del)(e); } @@ -262,17 +262,17 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { } cx_MAP_ONLY( - STC_DEF _cx_result_t + STC_DEF _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped) { - _cx_result_t _res = _cx_memb(_insert_entry_)(self, i_keyto(&_key)); + _cx_result _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); } _res.ref->second = _mapped; return _res; } - STC_DEF _cx_result_t + STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { - _cx_result_t _res = _cx_memb(_insert_entry_)(self, rkey); + _cx_result _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; @@ -280,14 +280,14 @@ cx_MAP_ONLY( ) STC_DEF chash_bucket_t -_cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey_t* rkeyptr) { +_cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) { const uint64_t _hash = i_hash(rkeyptr, sizeof *rkeyptr); - uint_fast8_t _hx; _cx_size_t _cap = self->bucket_count; + uint_fast8_t _hx; _cx_size _cap = self->bucket_count; chash_bucket_t b = {c_PASTE(fastrange_,MAP_SIZE_T)(_hash, _cap), (uint_fast8_t)(_hash | 0x80)}; const uint8_t* _hashx = self->_hashx; while ((_hx = _hashx[b.idx])) { if (_hx == b.hx) { - _cx_rawkey_t _raw = i_keyto(cx_keyref(self->table + b.idx)); + _cx_rawkey _raw = i_keyto(cx_keyref(self->table + b.idx)); if (i_equ(&_raw, rkeyptr)) break; } if (++b.idx == _cap) b.idx = 0; @@ -295,12 +295,12 @@ _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey_t* rkeyptr) { return b; } -STC_DEF _cx_result_t +STC_DEF _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { - if (self->size + 1 >= (_cx_size_t) (self->bucket_count * self->max_load_factor)) + if (self->size + 1 >= (_cx_size) (self->bucket_count * self->max_load_factor)) _cx_memb(_reserve)(self, 8 + (self->size*13ull >> 3)); chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey); - _cx_result_t res = {&self->table[b.idx], !self->_hashx[b.idx]}; + _cx_result res = {&self->table[b.idx], !self->_hashx[b.idx]}; if (res.inserted) { self->_hashx[b.idx] = b.hx; ++self->size; @@ -311,12 +311,12 @@ _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self m) { _cx_self clone = { - c_new_n(_cx_value_t, m.bucket_count), + c_new_n(_cx_value, m.bucket_count), (uint8_t *) memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1), m.size, m.bucket_count, m.max_load_factor }; - _cx_value_t *e = m.table, *end = e + m.bucket_count, *dst = clone.table; + _cx_value *e = m.table, *end = e + m.bucket_count, *dst = clone.table; for (uint8_t *hx = m._hashx; e != end; ++hx, ++e, ++dst) if (*hx) _cx_memb(_value_clone)(dst, e); return clone; @@ -328,18 +328,18 @@ _cx_memb(_reserve)(_cx_self* self, size_t _newcap) { size_t _oldcap = self->bucket_count; _newcap = (size_t) (2 + _newcap / self->max_load_factor) | 1; _cx_self _tmp = { - c_new_n(_cx_value_t, _newcap), + c_new_n(_cx_value, _newcap), (uint8_t *) c_calloc(_newcap + 1, sizeof(uint8_t)), - self->size, (_cx_size_t) _newcap, + self->size, (_cx_size) _newcap, self->max_load_factor }; /* Rehash: */ _tmp._hashx[_newcap] = 0xff; c_swap(_cx_self, *self, _tmp); - _cx_value_t* e = _tmp.table, *_slot = self->table; + _cx_value* e = _tmp.table, *_slot = self->table; uint8_t* _hashx = self->_hashx; for (size_t i = 0; i < _oldcap; ++i, ++e) if (_tmp._hashx[i]) { - _cx_rawkey_t _raw = i_keyto(cx_keyref(e)); + _cx_rawkey _raw = i_keyto(cx_keyref(e)); chash_bucket_t b = _cx_memb(_bucket_)(self, &_raw); _slot[b.idx] = *e; _hashx[b.idx] = (uint8_t) b.hx; @@ -349,16 +349,16 @@ _cx_memb(_reserve)(_cx_self* self, size_t _newcap) { } STC_DEF void -_cx_memb(_erase_entry)(_cx_self* self, _cx_value_t* _val) { +_cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { size_t i = chash_index_(*self, _val), j = i, k, _cap = self->bucket_count; - _cx_value_t* _slot = self->table; + _cx_value* _slot = self->table; uint8_t* _hashx = self->_hashx; _cx_memb(_value_del)(&_slot[i]); for (;;) { /* delete without leaving tombstone */ if (++j == _cap) j = 0; if (! _hashx[j]) break; - _cx_rawkey_t _raw = i_keyto(cx_keyref(_slot + j)); + _cx_rawkey _raw = i_keyto(cx_keyref(_slot + j)); k = c_PASTE(fastrange_,MAP_SIZE_T)(i_hash(&_raw, sizeof _raw), _cap); if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ _slot[i] = _slot[j], _hashx[i] = _hashx[j], i = j; diff --git a/include/stc/cpque.h b/include/stc/cpque.h index f4404af1..964a7058 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -36,24 +36,24 @@ #if !defined i_fwd _cx_deftypes(_c_cpque_types, _cx_self, i_val); #endif -typedef i_valraw _cx_rawvalue_t; +typedef i_valraw _cx_rawvalue; STC_API void _cx_memb(_make_heap)(_cx_self* self); STC_API void _cx_memb(_erase_at)(_cx_self* self, size_t idx); -STC_API void _cx_memb(_push)(_cx_self* self, _cx_value_t value); +STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value); STC_API _cx_self _cx_memb(_clone)(_cx_self q); STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){0, 0, 0}; } STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) { - _cx_self out = {(_cx_value_t *) c_malloc(cap*sizeof(_cx_value_t)), 0, cap}; + _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(_cx_value)), 0, cap}; return out; } STC_INLINE void _cx_memb(_reserve)(_cx_self* self, size_t n) { if (n >= self->size) - self->data = (_cx_value_t *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value_t)); + self->data = (_cx_value *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value)); } STC_INLINE void _cx_memb(_clear)(_cx_self* self) { @@ -78,50 +78,50 @@ STC_INLINE bool _cx_memb(_empty)(_cx_self q) STC_INLINE size_t _cx_memb(_capacity)(_cx_self q) { return q.capacity; } -STC_INLINE _cx_value_t* _cx_memb(_top)(const _cx_self* self) +STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self) { return &self->data[0]; } STC_INLINE void _cx_memb(_pop)(_cx_self* self) { _cx_memb(_erase_at)(self, 0); } -STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_rawvalue_t raw) +STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_rawvalue raw) { _cx_memb(_push)(self, i_valfrom(raw)); } -STC_INLINE i_val _cx_memb(_value_clone)(_cx_value_t val) +STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(i_valto(&val)); } STC_INLINE void -_cx_memb(_push_back)(_cx_self* self, _cx_value_t value) { +_cx_memb(_push_back)(_cx_self* self, _cx_value value) { if (self->size == self->capacity) _cx_memb(_reserve)(self, self->size*3/2 + 4); self->data[ self->size++ ] = value; } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) - { _cx_value_t* p = &self->data[--self->size]; i_valdel(p); } + { _cx_value* p = &self->data[--self->size]; i_valdel(p); } /* -------------------------- IMPLEMENTATION ------------------------- */ #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp) STC_DEF void -_cx_memb(_sift_down_)(_cx_value_t* arr, size_t idx, size_t n) { +_cx_memb(_sift_down_)(_cx_value* arr, size_t idx, size_t n) { for (size_t r = idx, c = idx << 1; c <= n; c <<= 1) { c += (c < n && i_cmp(&arr[c], &arr[c + 1]) < 0); if (i_cmp(&arr[r], &arr[c]) >= 0) return; - _cx_value_t t = arr[r]; arr[r] = arr[c]; arr[r = c] = t; + _cx_value t = arr[r]; arr[r] = arr[c]; arr[r = c] = t; } } STC_DEF void _cx_memb(_make_heap)(_cx_self* self) { size_t n = _cx_memb(_size)(*self); - _cx_value_t *arr = self->data - 1; + _cx_value *arr = self->data - 1; for (size_t k = n >> 1; k != 0; --k) _cx_memb(_sift_down_)(arr, k, n); } STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) { - _cx_self out = {(_cx_value_t *) c_malloc(q.size*sizeof(_cx_value_t)), q.size, q.size}; + _cx_self out = {(_cx_value *) c_malloc(q.size*sizeof(_cx_value)), q.size, q.size}; for (size_t i = 0; i < q.size; ++i, ++q.data) out.data[i] = i_valfrom(i_valto(q.data)); return out; } @@ -135,10 +135,10 @@ _cx_memb(_erase_at)(_cx_self* self, size_t idx) { } STC_DEF void -_cx_memb(_push)(_cx_self* self, _cx_value_t value) { +_cx_memb(_push)(_cx_self* self, _cx_value value) { if (self->size == self->capacity) _cx_memb(_reserve)(self, self->size*3/2 + 4); - _cx_value_t *arr = self->data - 1; /* base 1 */ + _cx_value *arr = self->data - 1; /* base 1 */ size_t c = ++self->size; for (; c > 1 && i_cmp(&arr[c >> 1], &value) < 0; c >>= 1) arr[c] = arr[c >> 1]; diff --git a/include/stc/csmap.h b/include/stc/csmap.h index db7a0a8c..b74dccd0 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -77,35 +77,35 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; _cx_deftypes(_c_aatree_types, _cx_self, i_key, i_val, cx_MAP_ONLY, cx_SET_ONLY); #endif -cx_MAP_ONLY( struct _cx_value_t { - _cx_key_t first; - _cx_mapped_t second; +cx_MAP_ONLY( struct _cx_value { + _cx_key first; + _cx_mapped second; }; ) -struct _cx_node_t { - _cx_size_t link[2]; +struct _cx_node { + _cx_size link[2]; int8_t level; - _cx_value_t value; + _cx_value value; }; -typedef i_keyraw _cx_rawkey_t; +typedef i_keyraw _cx_rawkey; 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; + _cx_rawvalue; STC_API _cx_self _cx_memb(_init)(void); STC_API _cx_self _cx_memb(_clone)(_cx_self tree); STC_API void _cx_memb(_del)(_cx_self* self); STC_API void _cx_memb(_reserve)(_cx_self* self, size_t cap); -STC_API _cx_value_t* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out); -STC_API _cx_iter_t _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey); -STC_API _cx_value_t* _cx_memb(_front)(const _cx_self* self); -STC_API _cx_value_t* _cx_memb(_back)(const _cx_self* self); +STC_API _cx_value* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter* out); +STC_API _cx_iter _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey); +STC_API _cx_value* _cx_memb(_front)(const _cx_self* self); +STC_API _cx_value* _cx_memb(_back)(const _cx_self* self); STC_API int _cx_memb(_erase)(_cx_self* self, i_keyraw rkey); -STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it); -STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2); -STC_API _cx_result_t _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); -STC_API void _cx_memb(_next)(_cx_iter_t* it); +STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); +STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); +STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); +STC_API void _cx_memb(_next)(_cx_iter* it); STC_INLINE bool _cx_memb(_empty)(_cx_self tree) { return _csmap_rep(&tree)->size == 0; } STC_INLINE size_t _cx_memb(_size)(_cx_self tree) { return _csmap_rep(&tree)->size; } @@ -113,9 +113,9 @@ STC_INLINE size_t _cx_memb(_capacity)(_cx_self tree) { return _csmap_rep(& STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_del)(self); *self = _cx_memb(_init)(); } STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); } STC_INLINE bool _cx_memb(_contains)(const _cx_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 _cx_self* self, i_keyraw rkey) - { _cx_iter_t it; return _cx_memb(_find_it)(self, rkey, &it); } + { _cx_iter it; return _cx_memb(_find_it)(self, rkey, &it) != NULL; } +STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_keyraw rkey) + { _cx_iter it; return _cx_memb(_find_it)(self, rkey, &it); } STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t size) { @@ -130,47 +130,47 @@ _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_rawvalue_t -_cx_memb(_value_toraw)(_cx_value_t* val) { +STC_INLINE _cx_rawvalue +_cx_memb(_value_toraw)(_cx_value* val) { return cx_SET_ONLY( i_keyto(val) ) - cx_MAP_ONLY( c_make(_cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} ); + cx_MAP_ONLY( c_make(_cx_rawvalue){i_keyto(&val->first), i_valto(&val->second)} ); } STC_INLINE void -_cx_memb(_value_del)(_cx_value_t* val) { +_cx_memb(_value_del)(_cx_value* val) { 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_memb(_value_clone)(_cx_value* dst, _cx_value* val) { *cx_keyref(dst) = i_keyfrom(i_keyto(cx_keyref(val))); cx_MAP_ONLY( dst->second = i_valfrom(i_valto(&val->second)); ) } cx_MAP_ONLY( - STC_API _cx_result_t _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped); - STC_API _cx_result_t _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); + STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped); + STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); - STC_INLINE _cx_result_t + STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped) { return _cx_memb(_insert_or_assign)(self, key, mapped); } - STC_INLINE _cx_mapped_t* + STC_INLINE _cx_mapped* _cx_memb(_at)(const _cx_self* self, i_keyraw rkey) - { _cx_iter_t it; return &_cx_memb(_find_it)(self, rkey, &it)->second; } + { _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; } ) -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_keyraw rkey) { - _cx_iter_t it; + _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); return it; } -STC_INLINE _cx_result_t +STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { - _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey); + _cx_result 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);) @@ -178,30 +178,30 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped) return res; } -STC_INLINE _cx_result_t +STC_INLINE _cx_result _cx_memb(_insert)(_cx_self* self, i_key key cx_MAP_ONLY(, i_val mapped)) { - _cx_result_t res = _cx_memb(_insert_entry_)(self, i_keyto(&key)); + _cx_result 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); )} return res; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - _cx_iter_t it; it._d = self->nodes, it._top = 0; - it._tn = (_cx_size_t) _csmap_rep(self)->root; + _cx_iter it; it._d = self->nodes, it._top = 0; + it._tn = (_cx_size) _csmap_rep(self)->root; if (it._tn) _cx_memb(_next)(&it); return it; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { (void)self; - return c_make(_cx_iter_t){.ref = NULL}; + return c_make(_cx_iter){.ref = NULL}; } -STC_INLINE _cx_iter_t -_cx_memb(_advance)(_cx_iter_t it, size_t n) { +STC_INLINE _cx_iter +_cx_memb(_advance)(_cx_iter it, size_t n) { while (n-- && it.ref) _cx_memb(_next)(&it); return it; } @@ -215,22 +215,22 @@ static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0}; STC_DEF _cx_self _cx_memb(_init)(void) { - _cx_self tree = {(_cx_node_t *) _csmap_sentinel.nodes}; + _cx_self tree = {(_cx_node *) _csmap_sentinel.nodes}; return tree; } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_front)(const _cx_self* self) { - _cx_node_t *d = self->nodes; - _cx_size_t tn = (_cx_size_t) _csmap_rep(self)->root; + _cx_node *d = self->nodes; + _cx_size tn = (_cx_size) _csmap_rep(self)->root; while (d[tn].link[0]) tn = d[tn].link[0]; return &d[tn].value; } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_back)(const _cx_self* self) { - _cx_node_t *d = self->nodes; - _cx_size_t tn = (_cx_size_t) _csmap_rep(self)->root; + _cx_node *d = self->nodes; + _cx_size tn = (_cx_size) _csmap_rep(self)->root; while (d[tn].link[1]) tn = d[tn].link[1]; return &d[tn].value; } @@ -238,18 +238,18 @@ _cx_memb(_back)(const _cx_self* self) { STC_DEF void _cx_memb(_reserve)(_cx_self* self, size_t cap) { struct csmap_rep* rep = _csmap_rep(self); - _cx_size_t oldcap = rep->cap; + _cx_size oldcap = rep->cap; if (cap > oldcap) { rep = (struct csmap_rep*) c_realloc(oldcap ? rep : NULL, - sizeof(struct csmap_rep) + (cap + 1)*sizeof(_cx_node_t)); + sizeof(struct csmap_rep) + (cap + 1)*sizeof(_cx_node)); if (oldcap == 0) - memset(rep, 0, sizeof(struct csmap_rep) + sizeof(_cx_node_t)); + memset(rep, 0, sizeof(struct csmap_rep) + sizeof(_cx_node)); rep->cap = cap; - self->nodes = (_cx_node_t *) rep->nodes; + self->nodes = (_cx_node *) rep->nodes; } } -STC_DEF _cx_size_t +STC_DEF _cx_size _cx_memb(_node_new_)(_cx_self* self, int level) { size_t tn; struct csmap_rep *rep = _csmap_rep(self); if (rep->disp) { @@ -259,36 +259,36 @@ _cx_memb(_node_new_)(_cx_self* self, int level) { if ((tn = rep->head + 1) > rep->cap) _cx_memb(_reserve)(self, 4 + (tn*13 >> 3)); ++_csmap_rep(self)->head; /* do after reserve */ } - _cx_node_t* dn = &self->nodes[tn]; + _cx_node* dn = &self->nodes[tn]; dn->link[0] = dn->link[1] = 0; dn->level = level; - return (_cx_size_t) tn; + return (_cx_size) tn; } cx_MAP_ONLY( - STC_DEF _cx_result_t + STC_DEF _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) { - _cx_result_t res = _cx_memb(_insert_entry_)(self, i_keyto(&key)); + _cx_result 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); } res.ref->second = mapped; return res; } - STC_DEF _cx_result_t + STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { - _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey); + _cx_result 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; } ) -STC_DEF _cx_value_t* -_cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out) { - _cx_size_t tn = _csmap_rep(self)->root; - _cx_node_t *d = out->_d = self->nodes; +STC_DEF _cx_value* +_cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter* out) { + _cx_size tn = _csmap_rep(self)->root; + _cx_node *d = out->_d = self->nodes; out->_top = 0; while (tn) { - int c; _cx_rawkey_t raw = i_keyto(cx_keyref(&d[tn].value)); + int c; _cx_rawkey raw = i_keyto(cx_keyref(&d[tn].value)); if ((c = i_cmp(&raw, &rkey)) < 0) tn = d[tn].link[1]; else if (c > 0) @@ -299,12 +299,12 @@ _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out) { return (out->ref = NULL); } -STC_DEF _cx_iter_t +STC_DEF _cx_iter _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) { - _cx_iter_t it; + _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); if (!it.ref && it._top) { - _cx_size_t tn = it._st[--it._top]; + _cx_size tn = it._st[--it._top]; it._tn = it._d[tn].link[1]; it.ref = &it._d[tn].value; } @@ -312,8 +312,8 @@ _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) { } STC_DEF void -_cx_memb(_next)(_cx_iter_t *it) { - _cx_size_t tn = it->_tn; +_cx_memb(_next)(_cx_iter *it) { + _cx_size tn = it->_tn; if (it->_top || tn) { while (tn) { it->_st[it->_top++] = tn; @@ -326,10 +326,10 @@ _cx_memb(_next)(_cx_iter_t *it) { it->ref = NULL; } -STC_DEF _cx_size_t -_cx_memb(_skew_)(_cx_node_t *d, _cx_size_t tn) { +STC_DEF _cx_size +_cx_memb(_skew_)(_cx_node *d, _cx_size tn) { if (tn && d[d[tn].link[0]].level == d[tn].level) { - _cx_size_t tmp = d[tn].link[0]; + _cx_size tmp = d[tn].link[0]; d[tn].link[0] = d[tmp].link[1]; d[tmp].link[1] = tn; tn = tmp; @@ -337,10 +337,10 @@ _cx_memb(_skew_)(_cx_node_t *d, _cx_size_t tn) { return tn; } -STC_DEF _cx_size_t -_cx_memb(_split_)(_cx_node_t *d, _cx_size_t tn) { +STC_DEF _cx_size +_cx_memb(_split_)(_cx_node *d, _cx_size tn) { if (d[d[d[tn].link[1]].link[1]].level == d[tn].level) { - _cx_size_t tmp = d[tn].link[1]; + _cx_size tmp = d[tn].link[1]; d[tn].link[1] = d[tmp].link[0]; d[tmp].link[0] = tn; tn = tmp; @@ -349,10 +349,10 @@ _cx_memb(_split_)(_cx_node_t *d, _cx_size_t tn) { return tn; } -STC_DEF _cx_size_t -_cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size_t tn, const _cx_rawkey_t* rkey, _cx_result_t* res) { - _cx_size_t up[64], tx = tn; - _cx_node_t* d = self->nodes; +STC_DEF _cx_size +_cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size tn, const _cx_rawkey* rkey, _cx_result* res) { + _cx_size up[64], tx = tn; + _cx_node* d = self->nodes; int c, top = 0, dir = 0; while (tx) { up[top++] = tx; @@ -374,21 +374,21 @@ _cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size_t tn, const _cx_rawkey_t* rk return up[0]; } -STC_DEF _cx_result_t +STC_DEF _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { - _cx_result_t res = {NULL, false}; - _cx_size_t tn = _cx_memb(_insert_entry_i_)(self, (_cx_size_t) _csmap_rep(self)->root, &rkey, &res); + _cx_result res = {NULL, false}; + _cx_size tn = _cx_memb(_insert_entry_i_)(self, (_cx_size) _csmap_rep(self)->root, &rkey, &res); _csmap_rep(self)->root = tn; _csmap_rep(self)->size += res.inserted; return res; } -STC_DEF _cx_size_t -_cx_memb(_erase_r_)(_cx_node_t *d, _cx_size_t tn, const _cx_rawkey_t* rkey, int *erased) { +STC_DEF _cx_size +_cx_memb(_erase_r_)(_cx_node *d, _cx_size tn, const _cx_rawkey* rkey, int *erased) { if (tn == 0) return 0; i_keyraw raw = i_keyto(cx_keyref(&d[tn].value)); - _cx_size_t tx; int c = i_cmp(&raw, rkey); + _cx_size 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 { @@ -406,7 +406,7 @@ _cx_memb(_erase_r_)(_cx_node_t *d, _cx_size_t tn, const _cx_rawkey_t* rkey, int tn = d[tn].link[ d[tn].link[0] == 0 ]; /* move it to disposed nodes list */ struct csmap_rep *rep = c_container_of(d, struct csmap_rep, nodes); - d[tx].link[1] = (_cx_size_t) rep->disp; + d[tx].link[1] = (_cx_size) rep->disp; rep->disp = tx; } } @@ -426,13 +426,13 @@ _cx_memb(_erase_r_)(_cx_node_t *d, _cx_size_t tn, const _cx_rawkey_t* rkey, int STC_DEF int _cx_memb(_erase)(_cx_self* self, i_keyraw rkey) { int erased = 0; - _cx_size_t root = _cx_memb(_erase_r_)(self->nodes, (_cx_size_t) _csmap_rep(self)->root, &rkey, &erased); + _cx_size root = _cx_memb(_erase_r_)(self->nodes, (_cx_size) _csmap_rep(self)->root, &rkey, &erased); return erased ? (_csmap_rep(self)->root = root, --_csmap_rep(self)->size, 1) : 0; } -STC_DEF _cx_iter_t -_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { - _cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt; +STC_DEF _cx_iter +_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { + _cx_rawkey raw = i_keyto(cx_keyref(it.ref)), nxt; _cx_memb(_next)(&it); if (it.ref) nxt = i_keyto(cx_keyref(it.ref)); _cx_memb(_erase)(self, raw); @@ -440,12 +440,12 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { return it; } -STC_DEF _cx_iter_t -_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { +STC_DEF _cx_iter +_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { 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_key k1 = *cx_keyref(it1.ref), k2 = *cx_keyref(it2.ref); + _cx_rawkey r1 = i_keyto(&k1); for (;;) { if (memcmp(&k1, &k2, sizeof k1) == 0) return it1; _cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref); @@ -454,10 +454,10 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { } } -STC_DEF _cx_size_t -_cx_memb(_clone_r_)(_cx_self* self, _cx_node_t* src, _cx_size_t sn) { +STC_DEF _cx_size +_cx_memb(_clone_r_)(_cx_self* self, _cx_node* src, _cx_size sn) { if (sn == 0) return 0; - _cx_size_t tx, tn = _cx_memb(_node_new_)(self, src[sn].level); + _cx_size tx, tn = _cx_memb(_node_new_)(self, src[sn].level); _cx_memb(_value_clone)(&self->nodes[tn].value, &src[sn].value); tx = _cx_memb(_clone_r_)(self, src, src[sn].link[0]); self->nodes[tn].link[0] = tx; tx = _cx_memb(_clone_r_)(self, src, src[sn].link[1]); self->nodes[tn].link[1] = tx; @@ -467,14 +467,14 @@ _cx_memb(_clone_r_)(_cx_self* self, _cx_node_t* src, _cx_size_t sn) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self tree) { _cx_self clone = _cx_memb(_with_capacity)(_csmap_rep(&tree)->size); - _cx_size_t root = _cx_memb(_clone_r_)(&clone, tree.nodes, (_cx_size_t) _csmap_rep(&tree)->root); + _cx_size root = _cx_memb(_clone_r_)(&clone, tree.nodes, (_cx_size) _csmap_rep(&tree)->root); _csmap_rep(&clone)->root = root; _csmap_rep(&clone)->size = _csmap_rep(&tree)->size; return clone; } STC_DEF void -_cx_memb(_del_r_)(_cx_node_t* d, _cx_size_t tn) { +_cx_memb(_del_r_)(_cx_node* d, _cx_size tn) { if (tn) { _cx_memb(_del_r_)(d, d[tn].link[0]); _cx_memb(_del_r_)(d, d[tn].link[1]); @@ -485,7 +485,7 @@ _cx_memb(_del_r_)(_cx_node_t* d, _cx_size_t tn) { STC_DEF void _cx_memb(_del)(_cx_self* self) { if (_csmap_rep(self)->root) { - _cx_memb(_del_r_)(self->nodes, (_cx_size_t) _csmap_rep(self)->root); + _cx_memb(_del_r_)(self->nodes, (_cx_size) _csmap_rep(self)->root); c_free(_csmap_rep(self)); } } diff --git a/include/stc/csptr.h b/include/stc/csptr.h index 9c946e03..5db626a4 100644 --- a/include/stc/csptr.h +++ b/include/stc/csptr.h @@ -91,7 +91,7 @@ typedef long atomic_count_t; _cx_deftypes(_c_csptr_types, _cx_self, i_val); #endif #define cx_csptr_rep struct _cx_memb(_rep_) -cx_csptr_rep { atomic_count_t counter; _cx_value_t value; }; +cx_csptr_rep { atomic_count_t counter; _cx_value value; }; STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; } @@ -100,14 +100,14 @@ STC_INLINE atomic_count_t _cx_memb(_use_count)(_cx_self ptr) { return ptr.use_count ? *ptr.use_count : 0; } STC_INLINE _cx_self -_cx_memb(_from)(_cx_value_t* p) { +_cx_memb(_from)(_cx_value* p) { _cx_self ptr = {p}; if (p) *(ptr.use_count = c_new(atomic_count_t)) = 1; return ptr; } STC_INLINE _cx_self -_cx_memb(_make)(_cx_value_t val) { +_cx_memb(_make)(_cx_value val) { _cx_self ptr; cx_csptr_rep *rep = c_new(cx_csptr_rep); *(ptr.use_count = &rep->counter) = 1; *(ptr.get = &rep->value) = val; @@ -144,13 +144,13 @@ _cx_memb(_reset)(_cx_self* self) { } STC_INLINE void -_cx_memb(_reset_from)(_cx_self* self, _cx_value_t* p) { +_cx_memb(_reset_from)(_cx_self* self, _cx_value* p) { _cx_memb(_del)(self); *self = _cx_memb(_from)(p); } STC_INLINE void -_cx_memb(_reset_with)(_cx_self* self, _cx_value_t val) { +_cx_memb(_reset_with)(_cx_self* self, _cx_value val) { _cx_memb(_del)(self); *self = _cx_memb(_make)(val); } diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 03a9f1d2..a57dfcb8 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -36,24 +36,24 @@ #if !defined i_fwd _cx_deftypes(_c_cstack_types, _cx_self, i_val); #endif -typedef i_valraw _cx_rawvalue_t; +typedef i_valraw _cx_rawvalue; STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){0, 0, 0}; } STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) { - _cx_self out = {(_cx_value_t *) c_malloc(cap*sizeof(i_val)), 0, cap}; + _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(i_val)), 0, cap}; return out; } STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_val fill) { - _cx_self out = {(_cx_value_t *) c_malloc(size*sizeof fill), size, size}; + _cx_self out = {(_cx_value *) c_malloc(size*sizeof fill), size, size}; while (size) out.data[--size] = fill; return out; } STC_INLINE void _cx_memb(_clear)(_cx_self* self) { - _cx_value_t *p = self->data + self->size; + _cx_value *p = self->data + self->size; while (p-- != self->data) i_valdel(p); self->size = 0; } @@ -70,34 +70,34 @@ STC_INLINE bool _cx_memb(_empty)(_cx_self v) STC_INLINE size_t _cx_memb(_capacity)(_cx_self v) { return v.capacity; } -STC_INLINE _cx_value_t* _cx_memb(_top)(const _cx_self* self) +STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self) { return &self->data[self->size - 1]; } STC_INLINE void _cx_memb(_pop)(_cx_self* self) - { _cx_value_t* p = &self->data[--self->size]; i_valdel(p); } + { _cx_value* p = &self->data[--self->size]; i_valdel(p); } STC_INLINE void _cx_memb(_reserve)(_cx_self* self, size_t n) { if (n >= self->size) - self->data = (_cx_value_t *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value_t)); + self->data = (_cx_value *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value)); } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } -STC_INLINE _cx_value_t* _cx_memb(_push)(_cx_self* self, _cx_value_t val) { +STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) { if (self->size == self->capacity) _cx_memb(_reserve)(self, self->size*3/2 + 4); - _cx_value_t* vp = self->data + self->size++; + _cx_value* vp = self->data + self->size++; *vp = val; return vp; } -STC_INLINE _cx_value_t* _cx_memb(_emplace)(_cx_self* self, _cx_rawvalue_t raw) +STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_rawvalue raw) { return _cx_memb(_push)(self, i_valfrom(raw)); } -STC_INLINE _cx_value_t* _cx_memb(_at)(const _cx_self* self, size_t idx) +STC_INLINE _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < self->size); return self->data + idx; } STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { - _cx_self out = {(_cx_value_t *) c_malloc(v.size*sizeof(_cx_value_t)), v.size, v.size}; + _cx_self out = {(_cx_value *) c_malloc(v.size*sizeof(_cx_value)), v.size, v.size}; for (size_t i = 0; i < v.size; ++i, ++v.data) out.data[i] = i_valfrom(i_valto(v.data)); return out; } @@ -107,17 +107,17 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE i_val _cx_memb(_value_clone)(_cx_value_t val) +STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(i_valto(&val)); } -STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* val) +STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* val) { return i_valto(val); } -STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data}; } -STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data + self->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; } -STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs) +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter){self->data}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){self->data + self->size}; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) { it.ref += offs; return it; } #include "template.h" diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 0b0313d9..3237f095 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -76,7 +76,7 @@ struct cvec_rep { size_t size, cap; void* data[]; }; #if !defined i_fwd _cx_deftypes(_c_cvec_types, _cx_self, i_val); #endif -typedef i_valraw _cx_rawvalue_t; +typedef i_valraw _cx_rawvalue; STC_API _cx_self _cx_memb(_init)(void); STC_API _cx_self _cx_memb(_clone)(_cx_self cx); @@ -84,39 +84,39 @@ STC_API void _cx_memb(_del)(_cx_self* self); STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_reserve)(_cx_self* self, size_t cap); STC_API void _cx_memb(_resize)(_cx_self* self, size_t size, i_val fill_val); -STC_API int _cx_memb(_value_compare)(const _cx_value_t* x, const _cx_value_t* y); -STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw raw); -STC_API _cx_iter_t _cx_memb(_bsearch_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw raw); -STC_API _cx_value_t* _cx_memb(_push_back)(_cx_self* self, i_val value); -STC_API _cx_iter_t _cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2); -STC_API _cx_iter_t _cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_value_t* p1, const _cx_value_t* p2, bool clone); -STC_API _cx_iter_t _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_rawvalue_t* p1, const _cx_rawvalue_t* p2); +STC_API int _cx_memb(_value_compare)(const _cx_value* x, const _cx_value* y); +STC_API _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, i_valraw raw); +STC_API _cx_iter _cx_memb(_bsearch_in)(_cx_iter it1, _cx_iter it2, i_valraw raw); +STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); +STC_API _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2); +STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, + const _cx_value* p1, const _cx_value* p2, bool clone); +STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, + const _cx_rawvalue* p1, const _cx_rawvalue* p2); STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cvec_rep_(&cx)->size; } STC_INLINE size_t _cx_memb(_capacity)(_cx_self cx) { return cvec_rep_(&cx)->cap; } STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return !cvec_rep_(&cx)->size; } STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } -STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* val) { return i_valto(val); } -STC_INLINE i_val _cx_memb(_value_clone)(_cx_value_t val) +STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* val) { return i_valto(val); } +STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(i_valto(&val)); } STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); } -STC_INLINE _cx_value_t* _cx_memb(_front)(const _cx_self* self) { return self->data; } -STC_INLINE _cx_value_t* _cx_memb(_back)(const _cx_self* self) +STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; } +STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + cvec_rep_(self)->size - 1; } -STC_INLINE _cx_value_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) - { _cx_value_t* p = &self->data[--cvec_rep_(self)->size]; i_valdel(p); } -STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data}; } -STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter_t){self->data + cvec_rep_(self)->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; } -STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs) + { _cx_value* p = &self->data[--cvec_rep_(self)->size]; i_valdel(p); } +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter){self->data}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){self->data + cvec_rep_(self)->size}; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) { it.ref += offs; return it; } -STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter_t it) { return it.ref - cx.data; } +STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) { return it.ref - cx.data; } STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_val null_val) { @@ -143,75 +143,75 @@ _cx_memb(_copy)(_cx_self *self, _cx_self other) { _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_insert)(_cx_self* self, size_t idx, i_val value) { return _cx_memb(_insert_range_p)(self, self->data + idx, &value, &value + 1, false); } -STC_INLINE _cx_iter_t -_cx_memb(_insert_n)(_cx_self* self, size_t idx, const _cx_value_t arr[], size_t n) { +STC_INLINE _cx_iter +_cx_memb(_insert_n)(_cx_self* self, size_t idx, const _cx_value arr[], size_t n) { return _cx_memb(_insert_range_p)(self, self->data + idx, arr, arr + n, false); } -STC_INLINE _cx_iter_t -_cx_memb(_insert_at)(_cx_self* self, _cx_iter_t it, i_val value) { +STC_INLINE _cx_iter +_cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_val value) { return _cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1, false); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, size_t idx, i_valraw raw) { return _cx_memb(_emplace_range_p)(self, self->data + idx, &raw, &raw + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_n)(_cx_self* self, size_t idx, const _cx_rawvalue_t arr[], size_t n) { +STC_INLINE _cx_iter +_cx_memb(_emplace_n)(_cx_self* self, size_t idx, const _cx_rawvalue arr[], size_t n) { return _cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + n); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_at)(_cx_self* self, _cx_iter_t it, i_valraw raw) { +STC_INLINE _cx_iter +_cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, i_valraw raw) { return _cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_emplace_range)(_cx_self* self, _cx_iter_t it, _cx_iter_t it1, _cx_iter_t it2) { +STC_INLINE _cx_iter +_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { return _cx_memb(_insert_range_p)(self, it.ref, it1.ref, it2.ref, true); } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_erase_n)(_cx_self* self, size_t idx, size_t n) { return _cx_memb(_erase_range_p)(self, self->data + idx, self->data + idx + n); } -STC_INLINE _cx_iter_t -_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) { +STC_INLINE _cx_iter +_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { return _cx_memb(_erase_range_p)(self, it.ref, it.ref + 1); } -STC_INLINE _cx_iter_t -_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) { +STC_INLINE _cx_iter +_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); } -STC_INLINE _cx_value_t* +STC_INLINE _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < cvec_rep_(self)->size); return self->data + idx; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, i_valraw raw) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw); } -STC_INLINE _cx_value_t* +STC_INLINE _cx_value* _cx_memb(_get)(const _cx_self* self, i_valraw raw) { - _cx_iter_t end = _cx_memb(_end)(self); - _cx_value_t* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref; + _cx_iter end = _cx_memb(_end)(self); + _cx_value* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref; return val == end.ref ? NULL : val; } -STC_INLINE _cx_iter_t +STC_INLINE _cx_iter _cx_memb(_bsearch)(const _cx_self* self, i_valraw raw) { return _cx_memb(_bsearch_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw); } STC_INLINE void -_cx_memb(_sort_range)(_cx_iter_t i1, _cx_iter_t i2, - int(*_cmp_)(const _cx_value_t*, const _cx_value_t*)) { - qsort(i1.ref, i2.ref - i1.ref, sizeof(_cx_value_t), (int(*)(const void*, const void*)) _cmp_); +_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, + int(*_cmp_)(const _cx_value*, const _cx_value*)) { + qsort(i1.ref, i2.ref - i1.ref, sizeof(_cx_value), (int(*)(const void*, const void*)) _cmp_); } STC_INLINE void _cx_memb(_sort)(_cx_self* self) { @@ -227,7 +227,7 @@ static struct cvec_rep _cvec_sentinel = {0, 0}; STC_DEF _cx_self _cx_memb(_init)(void) { - _cx_self cx = {(_cx_value_t *) _cvec_sentinel.data}; + _cx_self cx = {(_cx_value *) _cvec_sentinel.data}; return cx; } @@ -235,7 +235,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { struct cvec_rep* rep = cvec_rep_(self); if (rep->cap) { - for (_cx_value_t *p = self->data, *q = p + rep->size; p != q; ++p) + for (_cx_value *p = self->data, *q = p + rep->size; p != q; ++p) i_valdel(p); rep->size = 0; } @@ -255,7 +255,7 @@ _cx_memb(_reserve)(_cx_self* self, size_t cap) { if (cap >= len && cap != rep->cap) { rep = (struct cvec_rep*) c_realloc(rep->cap ? rep : NULL, offsetof(struct cvec_rep, data) + cap*sizeof(i_val)); - self->data = (_cx_value_t*) rep->data; + self->data = (_cx_value*) rep->data; rep->size = len; rep->cap = cap; } @@ -272,12 +272,12 @@ _cx_memb(_resize)(_cx_self* self, size_t len, i_val fill) { if (rep->cap) rep->size = len; } -STC_DEF _cx_value_t* +STC_DEF _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { size_t len = cvec_rep_(self)->size; if (len == _cx_memb(_capacity)(*self)) _cx_memb(_reserve)(self, (len*13 >> 3) + 4); - _cx_value_t *v = self->data + cvec_rep_(self)->size++; + _cx_value *v = self->data + cvec_rep_(self)->size++; *v = value; return v; } @@ -289,8 +289,8 @@ _cx_memb(_clone)(_cx_self cx) { return out; } -STC_DEF _cx_value_t* -_cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* pos, size_t len) { +STC_DEF _cx_value* +_cx_memb(_insert_space_)(_cx_self* self, _cx_value* pos, size_t len) { size_t idx = pos - self->data, size = cvec_rep_(self)->size; if (len == 0) return pos; if (size + len > _cx_memb(_capacity)(*self)) @@ -301,39 +301,39 @@ _cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* pos, size_t len) { return pos; } -STC_DEF _cx_iter_t -_cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos, - const _cx_value_t* p1, const _cx_value_t* p2, bool clone) { +STC_DEF _cx_iter +_cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, + const _cx_value* p1, const _cx_value* p2, bool clone) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); - _cx_iter_t it = {pos}; + _cx_iter it = {pos}; if (clone) for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); else memcpy(pos, p1, (p2 - p1)*sizeof *p1); return it; } -STC_DEF _cx_iter_t -_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos, const _cx_rawvalue_t* p1, - const _cx_rawvalue_t* p2) { +STC_DEF _cx_iter +_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_rawvalue* p1, + const _cx_rawvalue* p2) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); - _cx_iter_t it = {pos}; + _cx_iter it = {pos}; for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } -STC_DEF _cx_iter_t -_cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2) { +STC_DEF _cx_iter +_cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { intptr_t len = p2 - p1; if (len > 0) { - _cx_value_t* p = p1, *end = self->data + cvec_rep_(self)->size; + _cx_value* p = p1, *end = self->data + cvec_rep_(self)->size; for (; p != p2; ++p) i_valdel(p); memmove(p1, p2, (end - p2) * sizeof(i_val)); cvec_rep_(self)->size -= len; } - return c_make(_cx_iter_t){.ref = p1}; + return c_make(_cx_iter){.ref = p1}; } -STC_DEF _cx_iter_t -_cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { +STC_DEF _cx_iter +_cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, i_valraw raw) { for (; i1.ref != i2.ref; ++i1.ref) { i_valraw r = i_valto(i1.ref); if (i_cmp(&raw, &r) == 0) return i1; @@ -341,9 +341,9 @@ _cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { return i2; } -STC_DEF _cx_iter_t -_cx_memb(_bsearch_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { - _cx_iter_t mid, last = i2; +STC_DEF _cx_iter +_cx_memb(_bsearch_in)(_cx_iter i1, _cx_iter i2, i_valraw raw) { + _cx_iter mid, last = i2; while (i1.ref != i2.ref) { mid.ref = i1.ref + ((i2.ref - i1.ref)>>1); int c; i_valraw m = i_valto(mid.ref); @@ -355,7 +355,7 @@ _cx_memb(_bsearch_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) { } STC_DEF int -_cx_memb(_value_compare)(const _cx_value_t* x, const _cx_value_t* y) { +_cx_memb(_value_compare)(const _cx_value* x, const _cx_value* y) { i_valraw rx = i_valto(x); i_valraw ry = i_valto(y); return i_cmp(&rx, &ry); diff --git a/include/stc/template.h b/include/stc/template.h index 592b5bad..d65fda32 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -28,16 +28,16 @@ #define _cx_self c_PASTE(i_prefix, i_tag) #define _cx_memb(name) c_PASTE(_cx_self, name) #define _cx_deftypes(macro, SELF, ...) c_EXPAND(macro(SELF, __VA_ARGS__)) - #define _cx_value_t _cx_memb(_value_t) - #define _cx_key_t _cx_memb(_key_t) - #define _cx_mapped_t _cx_memb(_mapped_t) - #define _cx_rawvalue_t _cx_memb(_rawvalue_t) - #define _cx_rawkey_t _cx_memb(_rawkey_t) - #define _cx_rawmapped_t _cx_memb(_rawmapped_t) - #define _cx_iter_t _cx_memb(_iter_t) - #define _cx_result_t _cx_memb(_result_t) - #define _cx_node_t _cx_memb(_node_t) - #define _cx_size_t _cx_memb(_size_t) + #define _cx_value _cx_memb(_value_t) + #define _cx_key _cx_memb(_key_t) + #define _cx_mapped _cx_memb(_mapped_t) + #define _cx_rawvalue _cx_memb(_rawvalue_t) + #define _cx_rawkey _cx_memb(_rawkey_t) + #define _cx_rawmapped _cx_memb(_rawmapped_t) + #define _cx_iter _cx_memb(_iter_t) + #define _cx_result _cx_memb(_result_t) + #define _cx_node _cx_memb(_node_t) + #define _cx_size _cx_memb(_size_t) #endif #if defined i_valraw && !(defined i_valto && defined i_valfrom) -- cgit v1.2.3