diff options
64 files changed, 1674 insertions, 1679 deletions
@@ -165,11 +165,11 @@ int main(void) { csmap_int_insert(&map, 40, 4); // find an element in each container - cset_int_iter_t i1 = cset_int_find(&set, 20); - cvec_pnt_iter_t i2 = cvec_pnt_find(&vec, (struct Point) {20, 2}); - cdeq_int_iter_t i3 = cdeq_int_find(&deq, 20); - clist_int_iter_t i4 = clist_int_find(&lst, 20); - csmap_int_iter_t i5 = csmap_int_find(&map, 20); + cset_int_iter i1 = cset_int_find(&set, 20); + cvec_pnt_iter i2 = cvec_pnt_find(&vec, (struct Point) {20, 2}); + cdeq_int_iter i3 = cdeq_int_find(&deq, 20); + clist_int_iter i4 = clist_int_find(&lst, 20); + csmap_int_iter i5 = csmap_int_find(&map, 20); printf("\nFound: %d, (%g, %g), %d, %d, [%d: %d]\n", *i1.ref, i2.ref->x, i2.ref->y, *i3.ref, *i4.ref, i5.ref->first, i5.ref->second); @@ -322,7 +322,7 @@ but still not expose or include the full implementation / API of the container. ```c // Header file #include <stc/forward.h> // only include data structures -forward_cstack(cstack_pnt, struct Point); // declare cstack_pnt and cstack_pnt_value_t, cstack_pnt_iter_t; +forward_cstack(cstack_pnt, struct Point); // declare cstack_pnt and cstack_pnt_value, cstack_pnt_iter; // the element may be forward declared type as well typedef struct Dataset { cstack_pnt vertices; diff --git a/benchmarks/cdeq_benchmark.cpp b/benchmarks/cdeq_benchmark.cpp index 0c4def50..6db167b0 100644 --- a/benchmarks/cdeq_benchmark.cpp +++ b/benchmarks/cdeq_benchmark.cpp @@ -88,7 +88,7 @@ Sample test_stc_deque() { c_forrange (N) cdeq_x_push_back(&con, stc64_random() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //cdeq_x_iter_t it, end = cdeq_x_end(&con);
+ //cdeq_x_iter it, end = cdeq_x_end(&con);
//c_forrange (S) if ((it = cdeq_x_find(&con, stc64_random() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
diff --git a/benchmarks/clist_benchmark.cpp b/benchmarks/clist_benchmark.cpp index 525bcc5a..676d31e7 100644 --- a/benchmarks/clist_benchmark.cpp +++ b/benchmarks/clist_benchmark.cpp @@ -85,7 +85,7 @@ Sample test_stc_forward_list() { c_forrange (N) clist_x_push_front(&con, stc64_random() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //clist_x_iter_t it, end = clist_x_end(&con);
+ //clist_x_iter it, end = clist_x_end(&con);
//c_forrange (S) if ((it = clist_x_find(&con, stc64_random() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
diff --git a/benchmarks/cmap_benchmark.cpp b/benchmarks/cmap_benchmark.cpp index d94f2f24..dc104c2d 100644 --- a/benchmarks/cmap_benchmark.cpp +++ b/benchmarks/cmap_benchmark.cpp @@ -91,7 +91,7 @@ Sample test_stc_unordered_map() { stc64_srandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
- cmap_x_value_t* val;
+ cmap_x_value* val;
c_forrange (N)
if ((val = cmap_x_get(&con, stc64_random() & mask1)))
sum += val->second;
diff --git a/benchmarks/csmap_benchmark.cpp b/benchmarks/csmap_benchmark.cpp index fa1e10cf..bb055367 100644 --- a/benchmarks/csmap_benchmark.cpp +++ b/benchmarks/csmap_benchmark.cpp @@ -91,7 +91,7 @@ Sample test_stc_map() { stc64_srandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
- csmap_x_value_t* val;
+ csmap_x_value* val;
c_forrange (N)
if ((val = csmap_x_get(&con, stc64_random() & mask1)))
sum += val->second;
diff --git a/benchmarks/cvec_benchmark.cpp b/benchmarks/cvec_benchmark.cpp index f7755cf6..c4648e34 100644 --- a/benchmarks/cvec_benchmark.cpp +++ b/benchmarks/cvec_benchmark.cpp @@ -84,7 +84,7 @@ Sample test_stc_vector() { c_forrange (N) cvec_x_push_back(&con, stc64_random() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //cvec_x_iter_t it, end = cvec_x_end(&con);
+ //cvec_x_iter it, end = cvec_x_end(&con);
//c_forrange (S) if ((it = cvec_x_find(&con, stc64_random() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
diff --git a/benchmarks/others/old/carray_v1.h b/benchmarks/others/old/carray_v1.h index 65777416..c4f294cf 100644 --- a/benchmarks/others/old/carray_v1.h +++ b/benchmarks/others/old/carray_v1.h @@ -53,15 +53,15 @@ int main() #define using_carray2_4(X, Value, valueDel, valueClone) \
\
- typedef Value carray1##X##_value_t, carray2##X##_value_t; \
+ typedef Value carray1##X##_value, carray2##X##_value; \
\
typedef struct { \
- carray1##X##_value_t *data; \
+ carray1##X##_value *data; \
size_t _xdim; \
} carray1##X; \
\
typedef struct { \
- carray2##X##_value_t *data; \
+ carray2##X##_value *data; \
size_t _xdim, _ydim; \
} carray2##X; \
\
@@ -77,7 +77,7 @@ int main() \
STC_INLINE carray1##X \
carray1##X##_init(size_t xdim, Value val) { \
- carray1##X##_value_t* m = c_new_n(carray1##X##_value_t, xdim); \
+ carray1##X##_value* m = c_new_n(carray1##X##_value, xdim); \
for (size_t i=0; i<xdim; ++i) m[i] = val; \
carray1##X a = {m, xdim | _carray_OWN}; \
return a; \
@@ -85,24 +85,24 @@ int main() STC_INLINE carray2##X \
carray2##X##_init(size_t ydim, size_t xdim, Value val) { \
const size_t n = ydim * xdim; \
- carray2##X##_value_t* m = c_new_n(carray2##X##_value_t, n); \
+ carray2##X##_value* m = c_new_n(carray2##X##_value, n); \
for (size_t i=0; i<n; ++i) m[i] = val; \
carray2##X a = {m, xdim | _carray_OWN, ydim}; \
return a; \
} \
\
STC_INLINE carray1##X \
- carray1##X##_from(carray1##X##_value_t* array, size_t xdim) { \
+ carray1##X##_from(carray1##X##_value* array, size_t xdim) { \
carray1##X a = {array, xdim}; \
return a; \
} \
STC_INLINE carray2##X \
- carray2##X##_from(carray2##X##_value_t* array, size_t ydim, size_t xdim) { \
+ carray2##X##_from(carray2##X##_value* array, size_t ydim, size_t xdim) { \
carray2##X a = {array, xdim, ydim}; \
return a; \
} \
\
- STC_INLINE carray1##X##_value_t* \
+ STC_INLINE carray1##X##_value* \
carray1##X##_at(const carray1##X *a, size_t x) { return a->data + x; } \
\
STC_INLINE carray1##X \
@@ -110,7 +110,7 @@ int main() carray1##X sub = {a->data + y*_carray_xdim(*a), _carray_xdim(*a)}; \
return sub; \
} \
- STC_INLINE carray2##X##_value_t* \
+ STC_INLINE carray2##X##_value* \
carray2##X##_at(const carray2##X *a, size_t y, size_t x) { \
return a->data + y*_carray_xdim(*a) + x; \
} \
@@ -125,10 +125,10 @@ int main() #define using_carray3_4(X, Value, valueDel, valueClone) \
\
using_carray2_4(X, Value, valueDel, valueClone); \
- typedef Value carray3##X##_value_t; \
+ typedef Value carray3##X##_value; \
\
typedef struct { \
- carray3##X##_value_t *data; \
+ carray3##X##_value *data; \
size_t _xdim, _ydim, _zdim; \
} carray3##X; \
\
@@ -144,14 +144,14 @@ int main() STC_INLINE carray3##X \
carray3##X##_init(size_t zdim, size_t ydim, size_t xdim, Value val) { \
const size_t n = zdim * ydim * xdim; \
- carray3##X##_value_t* m = c_new_n(carray3##X##_value_t, n); \
+ carray3##X##_value* m = c_new_n(carray3##X##_value, n); \
for (size_t i=0; i<n; ++i) m[i] = val; \
carray3##X a = {m, xdim | _carray_OWN, ydim, zdim}; \
return a; \
} \
\
STC_INLINE carray3##X \
- carray3##X##_from(carray3##X##_value_t* array, size_t zdim, size_t ydim, size_t xdim) { \
+ carray3##X##_from(carray3##X##_value* array, size_t zdim, size_t ydim, size_t xdim) { \
carray3##X a = {array, xdim, ydim, zdim}; \
return a; \
} \
@@ -166,7 +166,7 @@ int main() carray1##X sub = {a->data + (z*_carray_ydim(*a) + y)*_carray_xdim(*a), _carray_xdim(*a)}; \
return sub; \
} \
- STC_INLINE carray3##X##_value_t* \
+ STC_INLINE carray3##X##_value* \
carray3##X##_at(const carray3##X *a, size_t z, size_t y, size_t x) { \
return a->data + (z*_carray_ydim(*a) + y)*_carray_xdim(*a) + x; \
} \
@@ -180,18 +180,18 @@ int main() #define _carray_zdim(a) (a)._zdim
#define _using_carray_common(D, X, Value, valueDel, valueClone) \
- typedef struct { carray1##X##_value_t *ref; } carray##D##X##_iter_t; \
+ typedef struct { carray1##X##_value *ref; } carray##D##X##_iter; \
\
- STC_INLINE carray##D##X##_iter_t \
+ STC_INLINE carray##D##X##_iter \
carray##D##X##_begin(const carray##D##X* a) { \
- carray##D##X##_iter_t it = {a->data}; return it; \
+ carray##D##X##_iter it = {a->data}; return it; \
} \
- STC_INLINE carray##D##X##_iter_t \
+ STC_INLINE carray##D##X##_iter \
carray##D##X##_end(const carray##D##X* a) { \
- carray##D##X##_iter_t it = {a->data + carray##D##X##_size(*a)}; return it; \
+ carray##D##X##_iter it = {a->data + carray##D##X##_size(*a)}; return it; \
} \
STC_INLINE void \
- carray##D##X##_next(carray##D##X##_iter_t* it) {++it->ref;} \
+ carray##D##X##_next(carray##D##X##_iter* it) {++it->ref;} \
\
STC_INLINE void \
carray##D##X##_del(carray##D##X* self) { \
@@ -204,7 +204,7 @@ int main() STC_INLINE carray##D##X \
carray##D##X##_clone(carray##D##X arr) { \
carray##D##X cp = arr; size_t k = 0; \
- cp.data = c_new_n(carray1##X##_value_t, carray##D##X##_size(arr)); \
+ cp.data = c_new_n(carray1##X##_value, carray##D##X##_size(arr)); \
c_foreach_3 (i, carray##D##X, arr) \
cp.data[k++] = valueClone(*i.ref); \
return cp; \
diff --git a/benchmarks/others/old/clist.h b/benchmarks/others/old/clist.h index 10d8092e..ea1bb9a5 100644 --- a/benchmarks/others/old/clist.h +++ b/benchmarks/others/old/clist.h @@ -59,153 +59,153 @@ _c_clist_types(clist_VOID, int);
STC_API size_t _clist_count(const clist_VOID* self);
-#define _clist_node(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(Self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw, defTypes) \
+#define _c_using_clist(_cx_self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw, defTypes) \
\
- defTypes( _c_clist_types(Self, i_val); ) \
- typedef i_valraw cx_rawvalue_t; \
+ defTypes( _c_clist_types(_cx_self, i_val); ) \
+ typedef i_valraw _cx_rawvalue; \
\
- STC_API Self cx_memb(_clone)(Self lst); \
- STC_API void cx_memb(_del)(Self* self); \
- STC_API void cx_memb(_push_back)(Self* self, i_val value); \
- STC_API void cx_memb(_push_front)(Self* self, i_val value); \
- STC_API void cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n); \
- STC_API Self cx_memb(_split_after)(Self* self, cx_iter_t pos1, cx_iter_t pos2); \
- STC_API void cx_memb(_splice_after)(Self* self, cx_iter_t pos, Self* other); \
- STC_DEF void cx_memb(_splice_after_range)(Self* self, cx_iter_t pos, Self* other, cx_iter_t i1, cx_iter_t i2); \
- STC_API cx_iter_t cx_memb(_find)(const Self* self, i_valraw val); \
- STC_API cx_iter_t cx_memb(_find_before)(const 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(_sort)(Self* self); \
- STC_API size_t cx_memb(_remove)(Self* self, i_valraw val); \
- STC_API cx_iter_t cx_memb(_insert_after)(Self* self, cx_iter_t pos, i_val value); \
- STC_API cx_iter_t cx_memb(_erase_after)(Self* self, cx_iter_t pos); \
- STC_API cx_iter_t cx_memb(_erase_range_after)(Self* self, cx_iter_t pos, cx_iter_t it2); \
- STC_API cx_node_t* cx_memb(_erase_after_)(Self* self, cx_node_t* node); \
+ 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 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 _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 Self cx_memb(_init)(void) {Self lst = {NULL}; return lst; } \
- STC_INLINE bool cx_memb(_empty)(Self lst) { return lst.last == NULL; } \
- STC_INLINE size_t cx_memb(_count)(Self lst) { return _clist_count((const clist_VOID*) &lst); } \
- STC_INLINE i_val cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } \
- STC_INLINE i_val cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } \
- STC_INLINE void cx_memb(_clear)(Self* self) { cx_memb(_del)(self); } \
- STC_INLINE void cx_memb(_emplace_back)(Self* self, i_valraw raw) \
- { cx_memb(_push_back)(self, i_valfrom(raw)); } \
- STC_INLINE void cx_memb(_emplace_front)(Self* self, i_valraw raw) \
- { cx_memb(_push_front)(self, i_valfrom(raw)); } \
- STC_INLINE cx_value_t* \
- cx_memb(_front)(const Self* self) { return &self->last->next->value; } \
- STC_INLINE cx_value_t* \
- cx_memb(_back)(const Self* self) { return &self->last->value; } \
- STC_INLINE void cx_memb(_pop_front)(Self* self) { cx_memb(_erase_after_)(self, self->last); } \
- STC_INLINE void cx_memb(_splice_front)(Self* self, Self* other) \
- { cx_memb(_splice_after)(self, cx_memb(_before_begin)(self), other); } \
- STC_INLINE void cx_memb(_splice_back)(Self* self, Self* other) \
- { cx_memb(_splice_after)(self, cx_memb(_last)(self), other); } \
+ 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; } \
+ STC_INLINE size_t _cx_memb(_count)(_cx_self lst) { return _clist_count((const clist_VOID*) &lst); } \
+ STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } \
+ STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } \
+ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_del)(self); } \
+ STC_INLINE void _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) \
+ { _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* \
+ _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(_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) \
+ { _cx_memb(_splice_after)(self, _cx_memb(_before_begin)(self), other); } \
+ 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)(Self* self, cx_iter_t pos, i_valraw raw) { \
- return cx_memb(_insert_after)(self, pos, i_valfrom(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 \
- cx_memb(_before_begin)(const Self* self) { \
- cx_value_t *last = self->last ? &self->last->value : NULL; \
- cx_iter_t it = {&self->last, last, -1}; return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_before_begin)(const _cx_self* self) { \
+ _cx_value *last = self->last ? &self->last->value : NULL; \
+ _cx_iter it = {&self->last, last, -1}; return it; \
} \
\
- STC_INLINE cx_iter_t \
- cx_memb(_begin)(const Self* self) { \
- cx_value_t* head = self->last ? &self->last->next->value : NULL; \
- cx_iter_t it = {&self->last, head, 0}; return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_begin)(const _cx_self* self) { \
+ _cx_value* head = self->last ? &self->last->next->value : NULL; \
+ _cx_iter it = {&self->last, head, 0}; return it; \
} \
\
- STC_INLINE cx_iter_t \
- cx_memb(_last)(const Self* self) { \
- cx_value_t *last = self->last ? &self->last->value : NULL; \
- cx_iter_t it = {&self->last, last, 0}; return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_last)(const _cx_self* self) { \
+ _cx_value *last = self->last ? &self->last->value : NULL; \
+ _cx_iter it = {&self->last, last, 0}; return it; \
} \
\
- STC_INLINE cx_iter_t \
- cx_memb(_end)(const Self* self) { \
- cx_iter_t it = {NULL, NULL}; return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_end)(const _cx_self* self) { \
+ _cx_iter it = {NULL, NULL}; return it; \
} \
\
STC_INLINE void \
- cx_memb(_next)(cx_iter_t* it) { \
- cx_node_t* node = _clist_node(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) { \
- while (n-- && it.ref) cx_memb(_next)(&it); return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_advance)(_cx_iter it, size_t n) { \
+ while (n-- && it.ref) _cx_memb(_next)(&it); return it; \
} \
\
- _c_implement_clist(Self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw) \
+ _c_implement_clist(_cx_self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw) \
struct stc_trailing_semicolon
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-#define _c_implement_clist(Self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw) \
+#define _c_implement_clist(_cx_self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw) \
\
- STC_DEF Self \
- cx_memb(_clone)(Self lst) { \
- Self out = cx_memb(_init)(); \
- c_foreach_3 (i, Self, lst) \
- cx_memb(_emplace_back)(&out, i_valto(i.ref)); \
+ STC_DEF _cx_self \
+ _cx_memb(_clone)(_cx_self lst) { \
+ _cx_self out = _cx_memb(_init)(); \
+ c_foreach_3 (i, _cx_self, lst) \
+ _cx_memb(_emplace_back)(&out, i_valto(i.ref)); \
return out; \
} \
\
STC_DEF void \
- cx_memb(_del)(Self* self) { \
- while (self->last) cx_memb(_erase_after_)(self, self->last); \
+ _cx_memb(_del)(_cx_self* self) { \
+ while (self->last) _cx_memb(_erase_after_)(self, self->last); \
} \
\
STC_DEF void \
- cx_memb(_push_back)(Self* self, i_val value) { \
- _c_clist_insert_after(self, Self, self->last, value); \
+ _cx_memb(_push_back)(_cx_self* self, i_val value) { \
+ _c_clist_insert_after(self, _cx_self, self->last, value); \
self->last = entry; \
} \
STC_DEF void \
- cx_memb(_push_front)(Self* self, i_val value) { \
- _c_clist_insert_after(self, Self, self->last, 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; \
} \
\
STC_DEF void \
- cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n) { \
- for (size_t i=0; i<n; ++i) cx_memb(_push_back)(self, i_valfrom(arr[i])); \
+ _cx_memb(_emplace_items)(_cx_self *self, const _cx_rawvalue arr[], size_t n) { \
+ for (size_t i=0; i<n; ++i) _cx_memb(_push_back)(self, i_valfrom(arr[i])); \
} \
\
- STC_DEF cx_iter_t \
- cx_memb(_insert_after)(Self* self, cx_iter_t pos, i_val value) { \
- cx_node_t* node = pos.ref ? _clist_node(Self, pos.ref) : NULL; \
- _c_clist_insert_after(self, Self, node, value); \
+ STC_DEF _cx_iter \
+ _cx_memb(_insert_after)(_cx_self* self, _cx_iter pos, i_val value) { \
+ _cx_node* node = pos.ref ? _clist_node(_cx_self, pos.ref) : NULL; \
+ _c_clist_insert_after(self, _cx_self, node, value); \
if (!node || node == self->last && pos._state == 0) self->last = entry; \
pos.ref = &entry->value, pos._state = 0; return pos; \
} \
\
- STC_DEF cx_iter_t \
- cx_memb(_erase_after)(Self* self, cx_iter_t pos) { \
- cx_memb(_erase_after_)(self, _clist_node(Self, pos.ref)); \
- cx_memb(_next)(&pos); return 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)(Self* self, cx_iter_t it1, cx_iter_t it2) { \
- cx_node_t* node = _clist_node(Self, it1.ref), *done = it2.ref ? _clist_node(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; \
+ 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; \
- for (cx_memb(_next)(&i); i.ref != it2.ref; cx_memb(_next)(&i)) { \
+ 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; \
it1 = i; \
@@ -213,22 +213,22 @@ STC_API size_t _clist_count(const clist_VOID* self); it1.ref = NULL; return it1; \
} \
\
- STC_DEF cx_iter_t \
- cx_memb(_find_before)(const Self* self, i_valraw val) { \
- cx_iter_t it = cx_memb(_find_before_in)(cx_memb(_before_begin)(self), cx_memb(_end)(self), val); \
+ STC_DEF _cx_iter \
+ _cx_memb(_find_before)(const _cx_self* self, i_valraw 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 \
- cx_memb(_find)(const Self* self, i_valraw val) { \
- cx_iter_t 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); \
+ STC_DEF _cx_iter \
+ _cx_memb(_find)(const _cx_self* self, i_valraw 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_)(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; \
@@ -237,35 +237,35 @@ STC_API size_t _clist_count(const clist_VOID* self); } \
\
STC_DEF size_t \
- cx_memb(_remove)(Self* self, i_valraw val) { \
+ _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); \
if (i_cmp(&r, &val) == 0) \
- prev = cx_memb(_erase_after_)(self, prev), ++n; \
+ prev = _cx_memb(_erase_after_)(self, prev), ++n; \
else \
prev = (node == self->last ? NULL : node); \
} \
return n; \
} \
\
- STC_DEF Self \
- cx_memb(_split_after)(Self* self, cx_iter_t pos1, cx_iter_t pos2) { \
- cx_node_t *node1 = _clist_node(Self, pos1.ref), *next1 = node1->next, \
- *node2 = _clist_node(Self, pos2.ref); \
+ STC_DEF _cx_self \
+ _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; \
- Self lst = {node2}; return lst; \
+ _cx_self lst = {node2}; return lst; \
} \
\
STC_DEF void \
- cx_memb(_splice_after)(Self* self, cx_iter_t pos, 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(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)(Self* self, cx_iter_t pos, Self* other, cx_iter_t pos1, cx_iter_t pos2) { \
- Self tmp = cx_memb(_split_after)(other, pos1, pos2); \
- cx_memb(_splice_after)(self, pos, &tmp); \
+ _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); \
+ _cx_memb(_sort_cmp_)(const void* x, const void* y) { \
+ 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)(Self* self) { \
+ _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 *) self->last->next, _cx_memb(_sort_cmp_)); \
}
-#define _c_clist_insert_after(self, Self, node, val) \
- cx_node_t *entry = c_new (cx_node_t); \
+#define _c_clist_insert_after(self, _cx_self, node, val) \
+ _cx_node *entry = c_new (_cx_node); \
if (node) entry->next = node->next, node->next = entry; \
else entry->next = entry; \
entry->value = val
@@ -302,7 +302,7 @@ STC_API size_t _clist_count(const clist_VOID* self); STC_DEF size_t
_clist_count(const clist_VOID* self) {
- const clist_VOID_node_t *nd = self->last;
+ const clist_VOID_node *nd = self->last;
if (!nd) return 0;
size_t n = 1;
while ((nd = nd->next) != self->last) ++n;
@@ -312,9 +312,9 @@ _clist_count(const clist_VOID* self) { /* Singly linked list Mergesort implementation by Simon Tatham. O(n*log n).
* https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
*/
-STC_DEF clist_VOID_node_t *
-_clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const void*, const void*)) {
- clist_VOID_node_t *p, *q, *e, *tail, *oldhead;
+STC_DEF clist_VOID_node *
+_clist_mergesort(clist_VOID_node *list, int (*cmp)(const void*, const void*)) {
+ clist_VOID_node *p, *q, *e, *tail, *oldhead;
int insize = 1, nmerges, psize, qsize, i;
while (1) {
@@ -361,7 +361,7 @@ _clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const void*, const void*)) }
#else
-#define _c_implement_clist(Self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw)
+#define _c_implement_clist(_cx_self, i_val, i_cmp, i_valdel, i_valfrom, i_valto, i_valraw)
#endif
#endif
diff --git a/benchmarks/others/old/csmap.h b/benchmarks/others/old/csmap.h index 4a380614..699e18c1 100644 --- a/benchmarks/others/old/csmap.h +++ b/benchmarks/others/old/csmap.h @@ -36,7 +36,7 @@ int main(void) { csmap_mx_insert(&m, 8, 'b');
csmap_mx_insert(&m, 12, 'c');
- csmap_mx_iter_t it = csmap_mx_find(&m, 10); // none
+ csmap_mx_iter it = csmap_mx_find(&m, 10); // none
char val = csmap_mx_find(&m, 5).ref->second;
csmap_mx_put(&m, 5, 'd'); // update
csmap_mx_erase(&m, 8);
@@ -52,71 +52,71 @@ int main(void) { #include <string.h>
#define KEY_REF_csmap_(vp) (&(vp)->first)
-#define _c_aatree_complete_types(Self, C) \
- cx_MAP_ONLY( struct cx_value_t { \
- cx_key_t first; \
- cx_mapped_t second; \
+#define _c_aatree_complete_types(_cx_self, C) \
+ 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
- _c_aatree_types(Self, C, i_key, i_val);
+ _c_aatree_types(_cx_self, C, i_key, i_val);
#endif
- _c_aatree_complete_types(Self, C); \
+ _c_aatree_complete_types(_cx_self, C); \
\
- typedef i_keyraw cx_rawkey_t; \
- typedef i_valraw cx_memb(_rawmapped_t); \
- typedef cx_SET_ONLY( cx_rawkey_t ) \
- cx_MAP_ONLY( struct { cx_rawkey_t first; \
- cx_memb(_rawmapped_t) second; } ) \
- cx_rawvalue_t; \
+ typedef i_keyraw _cx_rawkey; \
+ typedef i_valraw _cx_memb(_rawmapped); \
+ typedef cx_SET_ONLY( _cx_rawkey ) \
+ cx_MAP_ONLY( struct { _cx_rawkey first; \
+ _cx_memb(_rawmapped) second; } ) \
+ _cx_rawvalue; \
\
- STC_API Self cx_memb(_init)(void); \
- STC_API cx_value_t* cx_memb(_find_it)(const Self* self, i_keyraw rkey, cx_iter_t* out); \
- STC_API cx_iter_t cx_memb(_lower_bound)(const Self* self, i_keyraw rkey); \
- STC_API cx_value_t* cx_memb(_front)(const Self* self); \
- STC_API cx_value_t* cx_memb(_back)(const Self* self); \
- STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it); \
- STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2); \
- STC_API cx_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_)(Self* self, i_keyraw rkey); \
- STC_API void cx_memb(_next)(cx_iter_t* it); \
+ STC_API _cx_self _cx_memb(_init)(void); \
+ 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)(Self cx) { return cx.size == 0; } \
- STC_INLINE size_t cx_memb(_size)(Self cx) { return cx.size; } \
- STC_INLINE void cx_memb(_del)(Self* self) { cx_memb(_del_r_)(self->root); } \
- STC_INLINE void cx_memb(_clear)(Self* self) { cx_memb(_del)(self); *self = cx_memb(_init)(); } \
- STC_INLINE void cx_memb(_swap)(Self* a, Self* b) {c_swap(Self, *a, *b); } \
- STC_INLINE Self cx_memb(_clone)(Self cx) { return c_make(Self){ cx_memb(_clone_r_)(cx.root), cx.size}; } \
- STC_INLINE cx_iter_t cx_memb(_find)(const Self* self, i_keyraw rkey) \
- {cx_iter_t it; cx_memb(_find_it)(self, rkey, &it); return it; } \
- STC_INLINE bool cx_memb(_contains)(const Self* self, i_keyraw rkey) \
- {cx_iter_t it; return cx_memb(_find_it)(self, rkey, &it) != NULL; } \
- STC_INLINE cx_value_t* cx_memb(_get)(const Self* self, i_keyraw rkey) \
- {cx_iter_t it; return cx_memb(_find_it)(self, rkey, &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; } \
+ STC_INLINE void _cx_memb(_del)(_cx_self* self) { _cx_memb(_del_r_)(self->root); } \
+ 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 _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 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 \
- cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, rkey); \
+ STC_INLINE _cx_result \
+ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { \
+ _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,72 +125,72 @@ int main(void) { } \
\
STC_INLINE void \
- cx_memb(_emplace_items)(Self* self, const cx_rawvalue_t arr[], size_t n) { \
- for (size_t i=0; i<n; ++i) cx_SET_ONLY( cx_memb(_emplace)(self, arr[i]); ) \
- cx_MAP_ONLY( cx_memb(_emplace)(self, arr[i].first, arr[i].second); ) \
+ _cx_memb(_emplace_items)(_cx_self* self, const _cx_rawvalue arr[], size_t n) { \
+ for (size_t i=0; i<n; ++i) cx_SET_ONLY( _cx_memb(_emplace)(self, arr[i]); ) \
+ cx_MAP_ONLY( _cx_memb(_emplace)(self, arr[i].first, arr[i].second); ) \
} \
\
- STC_INLINE cx_result_t \
- cx_memb(_insert)(Self* self, i_key key cx_MAP_ONLY(, i_val mapped)) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key)); \
+ STC_INLINE _cx_result \
+ _cx_memb(_insert)(_cx_self* self, i_key key cx_MAP_ONLY(, i_val mapped)) { \
+ _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; \
} \
\
cx_MAP_ONLY( \
- STC_INLINE cx_result_t \
- cx_memb(_insert_or_assign)(Self* self, i_key key, i_val mapped) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key)); \
+ STC_INLINE _cx_result \
+ _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) { \
+ _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 \
- cx_memb(_put)(Self* self, i_key key, i_val mapped) { \
- return cx_memb(_insert_or_assign)(self, key, mapped); \
+ 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 \
- cx_memb(_emplace_or_assign)(Self* self, i_keyraw rkey, i_valraw rmapped) { \
- cx_result_t res = cx_memb(_insert_entry_)(self, rkey); \
+ STC_INLINE _cx_result \
+ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { \
+ _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* \
- cx_memb(_at)(const Self* self, i_keyraw rkey) { \
- cx_iter_t it; \
- return &cx_memb(_find_it)(self, rkey, &it)->second; \
+ STC_INLINE _cx_mapped* \
+ _cx_memb(_at)(const _cx_self* self, i_keyraw rkey) { \
+ _cx_iter it; \
+ return &_cx_memb(_find_it)(self, rkey, &it)->second; \
}) \
\
- STC_INLINE cx_iter_t \
- cx_memb(_begin)(const Self* self) { \
- cx_iter_t it = {NULL, 0, self->root}; \
- cx_memb(_next)(&it); return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_begin)(const _cx_self* self) { \
+ _cx_iter it = {NULL, 0, self->root}; \
+ _cx_memb(_next)(&it); return it; \
} \
\
- STC_INLINE cx_iter_t \
- cx_memb(_end)(const Self* self) {\
- cx_iter_t it = {NULL}; return it; \
+ STC_INLINE _cx_iter \
+ _cx_memb(_end)(const _cx_self* self) {\
+ _cx_iter it = {NULL}; return it; \
} \
\
STC_INLINE size_t \
- cx_memb(_erase)(Self* self, i_keyraw rkey) { \
+ _cx_memb(_erase)(_cx_self* self, i_keyraw rkey) { \
int erased = 0; \
- self->root = cx_memb(_erase_r_)(self->root, &rkey, &erased); \
+ self->root = _cx_memb(_erase_r_)(self->root, &rkey, &erased); \
self->size -= erased; return erased; \
} \
\
- STC_INLINE cx_iter_t \
- cx_memb(_advance)(cx_iter_t it, size_t n) { \
- while (n-- && it.ref) cx_memb(_next)(&it); \
+ STC_INLINE _cx_iter \
+ _cx_memb(_advance)(_cx_iter it, size_t n) { \
+ while (n-- && it.ref) _cx_memb(_next)(&it); \
return it; \
} \
\
- _c_implement_aatree(Self, C, i_key, i_val, i_cmp, \
+ _c_implement_aatree(_cx_self, C, i_key, i_val, i_cmp, \
i_valdel, i_valfrom, i_valto, i_valraw, \
i_keydel, i_keyfrom, i_keyto, i_keyraw) \
struct stc_trailing_semicolon
@@ -201,37 +201,37 @@ int main(void) { _c_aatree_types(csmap_SENTINEL, csmap_, int, int);
_c_aatree_complete_types(csmap_SENTINEL, csmap_);
-static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sentinel, 0};
+static csmap_SENTINEL_node _aatree_sentinel = {&_aatree_sentinel, &_aatree_sentinel, 0};
-#define _c_implement_aatree(Self, C, i_key, i_val, i_cmp, \
+#define _c_implement_aatree(_cx_self, C, i_key, i_val, i_cmp, \
i_valdel, i_valfrom, i_valto, i_valraw, \
i_keydel, i_keyfrom, i_keyto, i_keyraw) \
- STC_DEF Self \
- cx_memb(_init)(void) { \
- Self cx = {(cx_node_t *) &_aatree_sentinel, 0}; \
+ STC_DEF _cx_self \
+ _cx_memb(_init)(void) { \
+ _cx_self cx = {(_cx_node *) &_aatree_sentinel, 0}; \
return cx; \
} \
\
- STC_DEF cx_value_t* \
- cx_memb(_front)(const Self* self) { \
- cx_node_t *tn = self->root; \
+ STC_DEF _cx_value* \
+ _cx_memb(_front)(const _cx_self* self) { \
+ _cx_node *tn = self->root; \
while (tn->link[0]->level) tn = tn->link[0]; \
return &tn->value; \
} \
\
- STC_DEF cx_value_t* \
- cx_memb(_back)(const Self* self) { \
- cx_node_t *tn = self->root; \
+ STC_DEF _cx_value* \
+ _cx_memb(_back)(const _cx_self* self) { \
+ _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 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 \
- cx_memb(_lower_bound)(const Self* self, i_keyraw rkey) { \
- cx_iter_t it; \
- cx_memb(_find_it)(self, rkey, &it); \
+ STC_DEF _cx_iter \
+ _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) { \
+ _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,55 +289,55 @@ 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--) { \
if (top) dir = (up[top - 1]->link[1] == up[top]); \
- up[top] = cx_memb(_skew_)(up[top]); \
- up[top] = cx_memb(_split_)(up[top]); \
+ up[top] = _cx_memb(_skew_)(up[top]); \
+ up[top] = _cx_memb(_split_)(up[top]); \
if (top) up[top - 1]->link[dir] = up[top]; \
} \
return up[0]; \
} \
\
- STC_DEF cx_result_t \
- cx_memb(_insert_entry_)(Self* self, i_keyraw rkey) { \
- cx_result_t res = {NULL, false}; \
- self->root = cx_memb(_insert_entry_i_)(self->root, &rkey, &res); \
+ STC_DEF _cx_result \
+ _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { \
+ _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); \
+ tn->link[c < 0] = _cx_memb(_erase_r_)(tn->link[c < 0], rkey, erased); \
else { \
- if (!*erased) { cx_memb(_value_del)(&tn->value); *erased = 1; } \
+ if (!*erased) { _cx_memb(_value_del)(&tn->value); *erased = 1; } \
if (tn->link[0]->level && tn->link[1]->level) { \
tx = tn->link[0]; \
while (tx->link[1]->level) \
tx = tx->link[1]; \
tn->value = tx->value; \
raw = i_keyto(cx_keyref(&tn->value)); \
- tn->link[0] = cx_memb(_erase_r_)(tn->link[0], &raw, erased); \
+ tn->link[0] = _cx_memb(_erase_r_)(tn->link[0], &raw, erased); \
} else { \
tx = tn; \
tn = tn->link[tn->link[0]->level == 0]; \
@@ -347,55 +347,55 @@ static csmap_SENTINEL_node_t _aatree_sentinel = {&_aatree_sentinel, &_aatree_sen if (tn->link[0]->level < tn->level - 1 || tn->link[1]->level < tn->level - 1) { \
if (tn->link[1]->level > --tn->level) \
tn->link[1]->level = tn->level; \
- tn = cx_memb(_skew_)(tn); \
- tx = tn->link[0] = cx_memb(_skew_)(tn->link[0]); \
- tx->link[0] = cx_memb(_skew_)(tx->link[0]); \
- tn = cx_memb(_split_)(tn); \
- tn->link[0] = cx_memb(_split_)(tn->link[0]); \
+ tn = _cx_memb(_skew_)(tn); \
+ tx = tn->link[0] = _cx_memb(_skew_)(tn->link[0]); \
+ tx->link[0] = _cx_memb(_skew_)(tx->link[0]); \
+ tn = _cx_memb(_split_)(tn); \
+ tn->link[0] = _cx_memb(_split_)(tn->link[0]); \
} \
return tn; \
} \
- STC_DEF cx_iter_t \
- cx_memb(_erase_at)(Self* self, cx_iter_t it) { \
- cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt; \
- cx_memb(_next)(&it); \
+ 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); \
- if (it.ref) cx_memb(_find_it)(self, nxt, &it); \
+ _cx_memb(_erase)(self, raw); \
+ if (it.ref) _cx_memb(_find_it)(self, nxt, &it); \
return it; \
} \
\
- STC_DEF cx_iter_t \
- cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2) { \
- if (!it2.ref) { while (it1.ref) it1 = cx_memb(_erase_at)(self, it1); \
+ 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); \
- cx_memb(_erase)(self, r1); \
- cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1); \
+ _cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref); \
+ _cx_memb(_erase)(self, r1); \
+ _cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1); \
} \
} \
\
- 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); \
- cn->link[0] = cx_memb(_clone_r_)(tn->link[0]); \
- cn->link[1] = cx_memb(_clone_r_)(tn->link[1]); \
+ _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; \
- cx_memb(_value_clone)(&cn->value, &tn->value); \
+ _cx_memb(_value_clone)(&cn->value, &tn->value); \
return cn; \
} \
\
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]); \
- cx_memb(_value_del)(&tn->value); \
+ _cx_memb(_del_r_)(tn->link[0]); \
+ _cx_memb(_del_r_)(tn->link[1]); \
+ _cx_memb(_value_del)(&tn->value); \
c_free(tn); \
} \
}
diff --git a/benchmarks/others/old/sstr.h b/benchmarks/others/old/sstr.h index 5301978a..68b724a8 100644 --- a/benchmarks/others/old/sstr.h +++ b/benchmarks/others/old/sstr.h @@ -163,15 +163,15 @@ STC_INLINE sstr_size_t sstr_capacity(sstr s) { return sstr_select_(&s, cap(&s));
}
-STC_INLINE bool sstr_equalto(sstr s1, const char* str) {
+STC_INLINE bool sstr_equals(sstr s1, const char* str) {
return strcmp(sstr_str(&s1), str) == 0;
}
-STC_INLINE bool sstr_equalto_s(sstr s1, sstr s2) {
+STC_INLINE bool sstr_equals_s(sstr s1, sstr s2) {
return strcmp(sstr_str(&s1), sstr_str(&s2)) == 0;
}
-STC_INLINE int sstr_equals(const sstr* s1, const sstr* s2) {
+STC_INLINE bool sstr_equalto(const sstr* s1, const sstr* s2) {
return strcmp(sstr_str(s1), sstr_str(s2)) == 0;
}
diff --git a/benchmarks/others/parallel_hashmap/btree.h b/benchmarks/others/parallel_hashmap/btree.h index ae1aec5b..b8c95433 100644 --- a/benchmarks/others/parallel_hashmap/btree.h +++ b/benchmarks/others/parallel_hashmap/btree.h @@ -699,7 +699,7 @@ namespace phmap { template < typename Compare, typename K, typename LK, - phmap::enable_if_t<!std::is_same<bool, phmap::invoke_result_t< + phmap::enable_if_t<!std::is_same<bool, phmap::invoke_result< Compare, const K &, const LK &>>::value, int> = 0> constexpr phmap::weak_ordering do_three_way_comparison(const Compare &compare, @@ -708,7 +708,7 @@ namespace phmap { } template < typename Compare, typename K, typename LK, - phmap::enable_if_t<std::is_same<bool, phmap::invoke_result_t<Compare, + phmap::enable_if_t<std::is_same<bool, phmap::invoke_result<Compare, const K &, const LK &>>::value, int> = 0> constexpr phmap::weak_ordering do_three_way_comparison(const Compare &compare, @@ -730,7 +730,7 @@ namespace priv { // comparator. template <typename Compare, typename T> using btree_is_key_compare_to = - std::is_convertible<phmap::invoke_result_t<Compare, const T &, const T &>, + std::is_convertible<phmap::invoke_result<Compare, const T &, const T &>, phmap::weak_ordering>; struct StringBtreeDefaultLess { @@ -2494,7 +2494,7 @@ namespace priv { // Verify that key_compare returns an phmap::{weak,strong}_ordering or bool. using compare_result_type = - phmap::invoke_result_t<key_compare, key_type, key_type>; + phmap::invoke_result<key_compare, key_type, key_type>; static_assert( std::is_same<compare_result_type, bool>::value || std::is_convertible<compare_result_type, phmap::weak_ordering>::value, diff --git a/benchmarks/others/parallel_hashmap/phmap_base.h b/benchmarks/others/parallel_hashmap/phmap_base.h index 6b9ea9ee..d0c6f3ce 100644 --- a/benchmarks/others/parallel_hashmap/phmap_base.h +++ b/benchmarks/others/parallel_hashmap/phmap_base.h @@ -330,9 +330,9 @@ using underlying_type_t = typename std::underlying_type<T>::type; template< class F, class... ArgTypes> #if PHMAP_HAVE_CC17 - using invoke_result_t = typename std::invoke_result_t<F, ArgTypes...>; + using invoke_result = typename std::invoke_result<F, ArgTypes...>; #else - using invoke_result_t = typename std::result_of<F(ArgTypes...)>::type; + using invoke_result = typename std::result_of<F(ArgTypes...)>::type; #endif namespace type_traits_internal { diff --git a/benchmarks/shootout3_csmap.cpp b/benchmarks/shootout3_csmap.cpp index 3682c874..dfa0ab1b 100644 --- a/benchmarks/shootout3_csmap.cpp +++ b/benchmarks/shootout3_csmap.cpp @@ -179,7 +179,7 @@ static void ins_and_access_csmap_i(picobench::state& s) picobench::scope scope(s);
c_forrange (s.iterations()) {
result += ++csmap_i_emplace(&map, stc64_random() & mask, 0).ref->second;
- csmap_i_value_t* val = csmap_i_get(&map, stc64_random() & mask);
+ csmap_i_value* val = csmap_i_get(&map, stc64_random() & mask);
if (val) csmap_i_erase(&map, val->first);
}
s.set_result(result + csmap_i_size(map));
@@ -236,7 +236,7 @@ static void ins_and_access_csmap_s(picobench::state& s) c_forrange (s.iterations()) {
randomize(str.str, cstr_size(str));
result += csmap_str_erase(&map, str.str);
- /*csmap_str_iter_t it = csmap_str_find(&map, str.str);
+ /*csmap_str_iter it = csmap_str_find(&map, str.str);
if (it.ref) {
++result;
csmap_str_erase(&map, it.ref->first.str);
diff --git a/benchmarks/string_bench.c b/benchmarks/string_bench.c index 7da3b838..8e639aa2 100644 --- a/benchmarks/string_bench.c +++ b/benchmarks/string_bench.c @@ -119,7 +119,7 @@ void benchmark(cvec_str vec_string, struct Maps maps) stopwatch = clock();
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- csmap_str_iter_t it, end = csmap_str_end(maps.snormal);
+ csmap_str_iter it, end = csmap_str_end(maps.snormal);
for (size_t j = 0; j < cvec_str_size(vec_string); ++j)
{
csmap_str_find_it(maps.snormal, vec_string.data[j].str, &it);
@@ -136,7 +136,7 @@ void benchmark(cvec_str vec_string, struct Maps maps) stopwatch = clock();
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- cmap_str_iter_t it, end = cmap_str_end(maps.unormal);
+ cmap_str_iter it, end = cmap_str_end(maps.unormal);
for (size_t j = 0; j < cvec_str_size(vec_string); ++j)
{
it = cmap_str_find(maps.unormal, vec_string.data[j].str);
diff --git a/docs/carray_api.md b/docs/carray_api.md index d7ece0fa..a6870b91 100644 --- a/docs/carray_api.md +++ b/docs/carray_api.md @@ -35,9 +35,9 @@ size_t carr2_X_size(carr2_X arr); i_val* carr2_X_data(carr2_X* self); // access storage data i_val* carr2_X_at(carr2_X* self, size_t x, size_t y); -carr2_X_iter_t carr2_X_begin(const carr2_X* self); -carr2_X_iter_t carr2_X_end(const carr2_X* self); -void carr2_X_next(carr2_X_iter_t* it); +carr2_X_iter carr2_X_begin(const carr2_X* self); +carr2_X_iter carr2_X_end(const carr2_X* self); +void carr2_X_next(carr2_X_iter* it); ``` carr3: ```c @@ -53,21 +53,21 @@ size_t carr3_X_size(carr3_X arr); i_val* carr3_X_data(carr3_X* self); // access storage data i_val* carr3_X_at(carr3_X* self, size_t x, size_t y, size_t z); -carr3_X_iter_t carr3_X_begin(const carr3_X* self); -carr3_X_iter_t carr3_X_end(const carr3_X* self); -void carr3_X_next(carr3_X_iter_t* it); +carr3_X_iter carr3_X_begin(const carr3_X* self); +carr3_X_iter carr3_X_end(const carr3_X* self); +void carr3_X_next(carr3_X_iter* it); ``` ## Types | Type name | Type definition | Used to represent... | |:------------------|:-----------------------------------------------------|:---------------------| | `carr2_X` | `struct { i_val **data; size_t xdim, ydim; }` | The array 2D type | -| `carr2_X_value_t` | `i_val` | The value type | -| `carr2_X_iter_t` | `struct { i_val *ref; }` | Iterator type | +| `carr2_X_value` | `i_val` | The value type | +| `carr2_X_iter` | `struct { i_val *ref; }` | Iterator type | | | | | | `carr3_X` | `struct { i_val ***data; size_t xdim, ydim, zdim; }` | The array 3D type | -| `carr3_X_value_t` | `i_val` | The value type | -| `carr3_X_iter_t` | `struct { i_val *ref; }` | Iterator type | +| `carr3_X_value` | `i_val` | The value type | +| `carr3_X_iter` | `struct { i_val *ref; }` | Iterator type | The **carr3** elements can be accessed like `carr3_i arr = ...; int val = arr.data[x][y][z];`, or with `carr3_i_at(&arr, x, y, z)`. diff --git a/docs/cbits_api.md b/docs/cbits_api.md index 4264b1d4..f13c5e8c 100644 --- a/docs/cbits_api.md +++ b/docs/cbits_api.md @@ -58,7 +58,7 @@ void cbits_xor(cbits *self, cbits other); // set of disjoint | cbits | Type definition | Used to represent... | |:--------------------|:--------------------------|:-----------------------------| | `cbits` | `struct { ... }` | The cbits type | -| `cbits_iter_t` | `struct { ... }` | The cbits iterator type | +| `cbits_iter` | `struct { ... }` | The cbits iterator type | ## Example ```c diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 83f5dc6f..9a309835 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -95,7 +95,7 @@ c_apply(csset_x, insert, &set, {23, 3, 7, 5, 12}); c_foreach (i, csset_x, set) printf(" %d", *i.ref); // 3 5 7 12 23 -csset_x_iter_t it = csset_x_find(&set, 7); +csset_x_iter it = csset_x_find(&set, 7); c_foreach (i, csset_x, it, csset_x_end(&set)) printf(" %d", *i.ref); // 7 12 23 diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index 4f188143..ab0a1b12 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -38,58 +38,58 @@ bool cdeq_X_empty(cdeq_X deq); size_t cdeq_X_size(cdeq_X deq); size_t cdeq_X_capacity(cdeq_X deq); -cdeq_X_value_t* cdeq_X_at(const cdeq_X* self, size_t idx); -cdeq_X_value_t* cdeq_X_front(const cdeq_X* self); -cdeq_X_value_t* cdeq_X_back(const cdeq_X* self); +cdeq_X_value* cdeq_X_at(const cdeq_X* self, size_t idx); +cdeq_X_value* cdeq_X_front(const cdeq_X* self); +cdeq_X_value* cdeq_X_back(const cdeq_X* self); -cdeq_X_value_t* cdeq_X_push_front(cdeq_X* self, i_val value); -cdeq_X_value_t* cdeq_X_emplace_front(cdeq_X* self, i_valraw raw); +cdeq_X_value* cdeq_X_push_front(cdeq_X* self, i_val value); +cdeq_X_value* cdeq_X_emplace_front(cdeq_X* self, i_valraw raw); void cdeq_X_pop_front(cdeq_X* self); -cdeq_X_value_t* cdeq_X_push_back(cdeq_X* self, i_val value); -cdeq_X_value_t* cdeq_X_emplace_back(cdeq_X* self, i_valraw raw); +cdeq_X_value* cdeq_X_push_back(cdeq_X* self, i_val value); +cdeq_X_value* cdeq_X_emplace_back(cdeq_X* self, i_valraw raw); void cdeq_X_pop_back(cdeq_X* self); -cdeq_X_iter_t cdeq_X_insert(cdeq_X* self, size_t idx, i_val value); // move value -cdeq_X_iter_t cdeq_X_insert_n(cdeq_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values -cdeq_X_iter_t cdeq_X_insert_at(cdeq_X* self, cdeq_X_iter_t it, i_val value); // move value +cdeq_X_iter cdeq_X_insert(cdeq_X* self, size_t idx, i_val value); // move value +cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values +cdeq_X_iter cdeq_X_insert_at(cdeq_X* self, cdeq_X_iter it, i_val value); // move value -cdeq_X_iter_t cdeq_X_emplace(cdeq_X* self, size_t idx, i_valraw raw); -cdeq_X_iter_t cdeq_X_emplace_n(cdeq_X* self, size_t idx, const i_valraw[] arr, size_t n); -cdeq_X_iter_t cdeq_X_emplace_at(cdeq_X* self, cdeq_X_iter_t it, i_valraw raw); -cdeq_X_iter_t cdeq_X_emplace_range(cdeq_X* self, cdeq_X_iter_t it, - cdeq_X_iter_t it1, cdeq_X_iter_t it2); // will clone -cdeq_X_iter_t cdeq_X_emplace_range_p(cdeq_X* self, i_val* pos, +cdeq_X_iter cdeq_X_emplace(cdeq_X* self, size_t idx, i_valraw raw); +cdeq_X_iter cdeq_X_emplace_n(cdeq_X* self, size_t idx, const i_valraw[] arr, size_t n); +cdeq_X_iter cdeq_X_emplace_at(cdeq_X* self, cdeq_X_iter it, i_valraw raw); +cdeq_X_iter cdeq_X_emplace_range(cdeq_X* self, cdeq_X_iter it, + cdeq_X_iter it1, cdeq_X_iter it2); // will clone +cdeq_X_iter cdeq_X_emplace_range_p(cdeq_X* self, i_val* pos, const i_val* p1, const i_val* p2); -cdeq_X_iter_t cdeq_X_erase_n(cdeq_X* self, size_t idx, size_t n); -cdeq_X_iter_t cdeq_X_erase_at(cdeq_X* self, cdeq_X_iter_t it); -cdeq_X_iter_t cdeq_X_erase_range(cdeq_X* self, cdeq_X_iter_t it1, cdeq_X_iter_t it2); +cdeq_X_iter cdeq_X_erase_n(cdeq_X* self, size_t idx, size_t n); +cdeq_X_iter cdeq_X_erase_at(cdeq_X* self, cdeq_X_iter it); +cdeq_X_iter cdeq_X_erase_range(cdeq_X* self, cdeq_X_iter it1, cdeq_X_iter it2); -cdeq_X_iter_t cdeq_X_find(const cdeq_X* self, i_valraw raw); -cdeq_X_iter_t cdeq_X_find_in(cdeq_X_iter_t i1, cdeq_X_iter_t i2, i_valraw raw); -cdeq_X_value_t* cdeq_X_get(const cdeq_X* self, i_valraw raw); // returns NULL if not found +cdeq_X_iter cdeq_X_find(const cdeq_X* self, i_valraw raw); +cdeq_X_iter cdeq_X_find_in(cdeq_X_iter i1, cdeq_X_iter i2, i_valraw raw); +cdeq_X_value* cdeq_X_get(const cdeq_X* self, i_valraw raw); // returns NULL if not found void cdeq_X_sort(cdeq_X* self); -void cdeq_X_sort_range(cdeq_X_iter_t i1, cdeq_X_iter_t i2, +void cdeq_X_sort_range(cdeq_X_iter i1, cdeq_X_iter i2, int(*cmp)(const i_val*, const i_val*)); -cdeq_X_iter_t cdeq_X_begin(const cdeq_X* self); -cdeq_X_iter_t cdeq_X_end(const cdeq_X* self); -void cdeq_X_next(cdeq_X_iter_t* it); +cdeq_X_iter cdeq_X_begin(const cdeq_X* self); +cdeq_X_iter cdeq_X_end(const cdeq_X* self); +void cdeq_X_next(cdeq_X_iter* it); -cdeq_X_rawvalue_t cdeq_X_value_toraw(cdeq_X_value_t* pval); -cdeq_X_value_t cdeq_X_value_clone(cdeq_X_value_t val); +cdeq_X_rawvalue cdeq_X_value_toraw(cdeq_X_value* pval); +cdeq_X_value cdeq_X_value_clone(cdeq_X_value val); ``` ## Types -| Type name | Type definition | Used to represent... | -|:---------------------|:------------------------------------|:-----------------------| -| `cdeq_X` | `struct { cdeq_X_value_t* data; }` | The cdeq type | -| `cdeq_X_value_t` | `i_val` | The cdeq value type | -| `cdeq_X_rawvalue_t` | `i_valraw` | The raw value type | -| `cdeq_X_iter_t` | `struct { cdeq_X_value_t* ref; }` | The iterator type | +| Type name | Type definition | Used to represent... | +|:-------------------|:------------------------------------|:-----------------------| +| `cdeq_X` | `struct { cdeq_X_value* data; }` | The cdeq type | +| `cdeq_X_value` | `i_val` | The cdeq value type | +| `cdeq_X_rawvalue` | `i_valraw` | The raw value type | +| `cdeq_X_iter` | `struct { cdeq_X_value* ref; }` | The iterator type | ## Examples ```c diff --git a/docs/clist_api.md b/docs/clist_api.md index 7ef12153..6bb241f9 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -47,8 +47,8 @@ void clist_X_del(clist_X* self); bool clist_X_empty(clist_X list); size_t clist_X_count(clist_X list); // size() in O(n) time -clist_X_value_t* clist_X_front(const clist_X* self); -clist_X_value_t* clist_X_back(const clist_X* self); +clist_X_value* clist_X_front(const clist_X* self); +clist_X_value* clist_X_back(const clist_X* self); void clist_X_push_front(clist_X* self, i_val value); void clist_X_emplace_front(clist_X* self, i_valraw raw); @@ -57,40 +57,40 @@ void clist_X_pop_front(clist_X* self); void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back(). void clist_X_emplace_back(clist_X* self, i_valraw raw); -clist_X_iter_t clist_X_insert(clist_X* self, clist_X_iter_t it, i_val value); // return iter to new elem -clist_X_iter_t clist_X_emplace(clist_X* self, clist_X_iter_t it, i_valraw raw); +clist_X_iter clist_X_insert(clist_X* self, clist_X_iter it, i_val value); // return iter to new elem +clist_X_iter clist_X_emplace(clist_X* self, clist_X_iter it, i_valraw raw); -clist_X_iter_t clist_X_erase_at(clist_X* self, clist_X_iter_t it); // return iter after it -clist_X_iter_t clist_X_erase_range(clist_X* self, clist_X_iter_t it1, clist_X_iter_t it2); +clist_X_iter clist_X_erase_at(clist_X* self, clist_X_iter it); // return iter after it +clist_X_iter clist_X_erase_range(clist_X* self, clist_X_iter it1, clist_X_iter it2); size_t clist_X_remove(clist_X* self, i_valraw raw); // removes matching elements -clist_X clist_X_split_off(clist_X* self, clist_X_iter_t i1, clist_X_iter_t i2); // split off [i1, i2) -clist_X_iter_t clist_X_splice(clist_X* self, clist_X_iter_t it, clist_X* other); // return updated valid it -clist_X_iter_t clist_X_splice_range(clist_X* self, clist_X_iter_t it, // return updated valid it - clist_X* other, clist_X_iter_t it1, clist_X_iter_t it2); +clist_X clist_X_split_off(clist_X* self, clist_X_iter i1, clist_X_iter i2); // split off [i1, i2) +clist_X_iter clist_X_splice(clist_X* self, clist_X_iter it, clist_X* other); // return updated valid it +clist_X_iter clist_X_splice_range(clist_X* self, clist_X_iter it, // return updated valid it + clist_X* other, clist_X_iter it1, clist_X_iter it2); -clist_X_iter_t clist_X_find(const clist_X* self, i_valraw raw); -clist_X_iter_t clist_X_find_in(clist_X_iter_t it1, clist_X_iter_t it2, i_valraw raw); +clist_X_iter clist_X_find(const clist_X* self, i_valraw raw); +clist_X_iter clist_X_find_in(clist_X_iter it1, clist_X_iter it2, i_valraw raw); void clist_X_sort(clist_X* self); -clist_X_iter_t clist_X_begin(const clist_X* self); -clist_X_iter_t clist_X_end(const clist_X* self); -void clist_X_next(clist_X_iter_t* it); -clist_X_iter_t clist_X_advance(clist_X_iter it, size_t n); // return it n elements ahead. End allowed. +clist_X_iter clist_X_begin(const clist_X* self); +clist_X_iter clist_X_end(const clist_X* self); +void clist_X_next(clist_X_iter* it); +clist_X_iter clist_X_advance(clist_X_iter it, size_t n); // return it n elements ahead. End allowed. -clist_X_rawvalue_t clist_X_value_toraw(clist_X_value_t* pval); -clist_X_value_t clist_X_value_clone(clist_X_value_t val); +clist_X_rawvalue clist_X_value_toraw(clist_X_value* pval); +clist_X_value clist_X_value_clone(clist_X_value val); ``` ## Types -| Type name | Type definition | Used to represent... | -|:----------------------|:------------------------------------|:--------------------------| -| `clist_X` | `struct { clist_X_node_t* last; }` | The clist type | -| `clist_X_value_t` | `i_val` | The clist element type | -| `clist_X_rawvalue_t` | `i_valraw` | clist raw value type | -| `clist_X_iter_t` | `struct { clist_value_t *ref; ... }`| clist iterator | +| Type name | Type definition | Used to represent... | +|:--------------------|:------------------------------------|:--------------------------| +| `clist_X` | `struct { clist_X_node* last; }` | The clist type | +| `clist_X_value` | `i_val` | The clist element type | +| `clist_X_rawvalue` | `i_valraw` | clist raw value type | +| `clist_X_iter` | `struct { clist_value *ref; ... }` | clist iterator | ## Example @@ -147,11 +147,11 @@ int main () clist_i L = clist_i_init(); c_apply(clist_i, push_back, &L, {10, 20, 30, 40, 50}); // 10 20 30 40 50 - clist_i_iter_t it = clist_i_begin(&L); // ^ + clist_i_iter it = clist_i_begin(&L); // ^ clist_i_next(&it); it = clist_i_erase_at(&L, it); // 10 30 40 50 // ^ - clist_i_iter_t end = clist_i_end(&L); // + clist_i_iter end = clist_i_end(&L); // clist_i_next(&it); it = clist_i_erase_range(&L, it, end); // 10 30 // ^ @@ -183,8 +183,8 @@ int main() { c_apply(clist_i, push_back, &L1, {1, 2, 3, 4, 5}); c_apply(clist_i, push_back, &L2, {10, 20, 30, 40, 50}); - clist_i_iter_t i = clist_i_advance(clist_i_begin(&L1), 2); - clist_i_iter_t j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2); + clist_i_iter i = clist_i_advance(clist_i_begin(&L1), 2); + clist_i_iter j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2); clist_i_splice_range(&L1, i, &L2, j1, j2); diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 31dd3f63..f8b24704 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -55,41 +55,41 @@ size_t cmap_X_capacity(cmap_X map); size_t cmap_X_bucket_count(cmap_X map); // num. of allocated buckets bool cmap_X_contains(const cmap_X* self, i_keyraw rkey); -cmap_X_mapped_t* cmap_X_at(const cmap_X* self, i_keyraw rkey); // rkey must be in map. -cmap_X_value_t* cmap_X_get(const cmap_X* self, i_keyraw rkey); // return NULL if not found -cmap_X_iter_t cmap_X_find(const cmap_X* self, i_keyraw rkey); +cmap_X_mapped* cmap_X_at(const cmap_X* self, i_keyraw rkey); // rkey must be in map. +cmap_X_value* cmap_X_get(const cmap_X* self, i_keyraw rkey); // return NULL if not found +cmap_X_iter cmap_X_find(const cmap_X* self, i_keyraw rkey); -cmap_X_result_t cmap_X_insert(cmap_X* self, i_key key, i_val mapped); // no change if key in map -cmap_X_result_t cmap_X_insert_or_assign(cmap_X* self, i_key key, i_val mapped); // always update mapped -cmap_X_result_t cmap_X_put(cmap_X* self, i_key key, i_val mapped); // alias for insert_or_assign +cmap_X_result cmap_X_insert(cmap_X* self, i_key key, i_val mapped); // no change if key in map +cmap_X_result cmap_X_insert_or_assign(cmap_X* self, i_key key, i_val mapped); // always update mapped +cmap_X_result cmap_X_put(cmap_X* self, i_key key, i_val mapped); // alias for insert_or_assign -cmap_X_result_t cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map -cmap_X_result_t cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped +cmap_X_result cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map +cmap_X_result cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped size_t cmap_X_erase(cmap_X* self, i_keyraw rkey); // return 0 or 1 -cmap_X_iter_t cmap_X_erase_at(cmap_X* self, cmap_X_iter_t it); // return iter after it -void cmap_X_erase_entry(cmap_X* self, cmap_X_value_t* entry); +cmap_X_iter cmap_X_erase_at(cmap_X* self, cmap_X_iter it); // return iter after it +void cmap_X_erase_entry(cmap_X* self, cmap_X_value* entry); -cmap_X_iter_t cmap_X_begin(const cmap_X* self); -cmap_X_iter_t cmap_X_end(const cmap_X* self); -void cmap_X_next(cmap_X_iter_t* it); +cmap_X_iter cmap_X_begin(const cmap_X* self); +cmap_X_iter cmap_X_end(const cmap_X* self); +void cmap_X_next(cmap_X_iter* it); -cmap_X_value_t cmap_X_value_clone(cmap_X_value_t val); -cmap_X_rawvalue_t cmap_X_value_toraw(cmap_X_value_t* pval); +cmap_X_value cmap_X_value_clone(cmap_X_value val); +cmap_X_rawvalue cmap_X_value_toraw(cmap_X_value* pval); ``` Helpers: ```c uint64_t c_strhash(const char *str); // utility function int c_rawstr_compare(const char* const* a, const char* const* b); -bool c_rawstr_equals(const char* const* a, const char* const* b); +bool c_rawstr_equalto(const char* const* a, const char* const* b); uint64_t c_rawstr_hash(const char* const* strp, ...); uint64_t c_default_hash(const void *data, size_t len); // key any trivial type uint64_t c_default_hash32(const void* data, size_t is4); // key one 32bit int uint64_t c_default_hash64(const void* data, size_t is8); // key one 64bit int -int c_default_equals(const i_keyraw* a, const i_keyraw* b); // the == operator -int c_memcmp_equals(const i_keyraw* a, const i_keyraw* b); // uses memcmp +bool c_default_equalto(const i_keyraw* a, const i_keyraw* b); // the == operator +bool c_memcmp_equalto(const i_keyraw* a, const i_keyraw* b); // uses memcmp Type c_no_clone(Type val); Type c_default_fromraw(Type val); // plain copy @@ -99,17 +99,17 @@ void c_default_del(Type* val); // d ## Types -| Type name | Type definition | Used to represent... | -|:---------------------|:------------------------------------------------|:------------------------------| -| `cmap_X` | `struct { ... }` | The cmap type | -| `cmap_X_rawkey_t` | `i_keyraw` | The raw key type | -| `cmap_X_rawmapped_t` | `i_valraw` | The raw mapped type | -| `cmap_X_rawvalue_t` | `struct { i_keyraw first; i_valraw second; }` | i_keyraw + i_valraw type | -| `cmap_X_key_t` | `i_key` | The key type | -| `cmap_X_mapped_t` | `i_val` | The mapped type | -| `cmap_X_value_t` | `struct { const i_key first; i_val second; }` | The value: key is immutable | -| `cmap_X_result_t` | `struct { cmap_X_value_t *ref; bool inserted; }`| Result of insert/put/emplace | -| `cmap_X_iter_t` | `struct { cmap_X_value_t *ref; ... }` | Iterator type | +| Type name | Type definition | Used to represent... | +|:-------------------|:------------------------------------------------|:------------------------------| +| `cmap_X` | `struct { ... }` | The cmap type | +| `cmap_X_rawkey` | `i_keyraw` | The raw key type | +| `cmap_X_rawmapped` | `i_valraw` | The raw mapped type | +| `cmap_X_rawvalue` | `struct { i_keyraw first; i_valraw second; }` | i_keyraw + i_valraw type | +| `cmap_X_key` | `i_key` | The key type | +| `cmap_X_mapped` | `i_val` | The mapped type | +| `cmap_X_value` | `struct { const i_key first; i_val second; }` | The value: key is immutable | +| `cmap_X_result` | `struct { cmap_X_value *ref; bool inserted; }` | Result of insert/put/emplace | +| `cmap_X_iter` | `struct { cmap_X_value *ref; ... }` | Iterator type | ## Examples @@ -203,7 +203,7 @@ typedef struct { int x, y, z; } Vec3i; #define i_key Vec3i #define i_val int -#define i_cmp c_memcmp_equals // bitwise compare, and use c_default_hash +#define i_cmp c_memcmp_equalto // bitwise compare, and use c_default_hash #define i_tag vi #include <stc/cmap.h> @@ -273,7 +273,7 @@ typedef struct { cstr country; } Viking; -static int Viking_equals(const Viking* a, const Viking* b) { +static bool Viking_equalto(const Viking* a, const Viking* b) { return cstr_equals_s(a->name, b->name) && cstr_equals_s(a->country, b->country); } @@ -287,7 +287,7 @@ static void Viking_del(Viking* v) { #define i_key Viking #define i_val int -#define i_equ Viking_equals +#define i_equ Viking_equalto #define i_hash Viking_hash #define i_del Viking_del #define i_tag vk @@ -346,7 +346,7 @@ typedef struct { const char* country; } RViking; -static int RViking_equals(const RViking* r1, const RViking* r2) +static bool RViking_equalto(const RViking* r1, const RViking* r2) { return !strcmp(r1->name, r2->name) && !strcmp(r1->country, r2->country); } static uint32_t RViking_hash(const RViking* r, int ignored) @@ -362,7 +362,7 @@ static RViking Viking_toR(const Viking* v) #define i_val int #define i_keydel Viking_del #define i_keyraw RViking -#define i_equ RViking_equals +#define i_equ RViking_equalto #define i_hash RViking_hash #define i_keyfrom Viking_fromR #define i_keyto Viking_toR diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 4f22fe0e..365ba4b9 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -32,26 +32,26 @@ void cpque_X_del(cpque_X* self); // destructor size_t cpque_X_size(cpque_X pq); bool cpque_X_empty(cpque_X pq); -cpque_X_value_t* cpque_X_top(const cpque_X* self); +cpque_X_value* cpque_X_top(const cpque_X* self); void cpque_X_make_heap(cpque_X* self); // call after using push_back(). -void cpque_X_push(cpque_X* self, cpque_X_value_t value); -void cpque_X_emplace(cpque_X* self, cpque_X_rawvalue_t raw); +void cpque_X_push(cpque_X* self, cpque_X_value value); +void cpque_X_emplace(cpque_X* self, cpque_X_rawvalue raw); void cpque_X_pop(cpque_X* self); void cpque_X_erase_at(cpque_X* self, size_t idx); -void cpque_X_push_back(cpque_X* self, cpque_X_value_t value); // breaks heap-property -cpque_X_value_t cpque_X_value_clone(cpque_X_value_t val); +void cpque_X_push_back(cpque_X* self, cpque_X_value value); // breaks heap-property +cpque_X_value cpque_X_value_clone(cpque_X_value val); ``` ## Types -| Type name | Type definition | Used to represent... | -|:---------------------|:--------------------------------------|:------------------------| -| `cpque_X` | `struct {cpque_X_value_t* data; ...}` | The cpque type | -| `cpque_X_value_t` | `i_val` | The cpque element type | -| `cpque_X_rawvalue_t` | `i_valraw` | cpque raw value type | +| Type name | Type definition | Used to represent... | +|:-------------------|:--------------------------------------|:------------------------| +| `cpque_X` | `struct {cpque_X_value* data; ...}` | The cpque type | +| `cpque_X_value` | `i_val` | The cpque element type | +| `cpque_X_rawvalue` | `i_valraw` | cpque raw value type | ## Example ```c diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md index 087f9da5..469b7c99 100644 --- a/docs/cqueue_api.md +++ b/docs/cqueue_api.md @@ -31,29 +31,29 @@ void cqueue_X_del(cqueue_X* self); // destructor size_t cqueue_X_size(cqueue_X q); bool cqueue_X_empty(cqueue_X q); -cqueue_X_value_t* cqueue_X_front(const cqueue_X* self); -cqueue_X_value_t* cqueue_X_back(const cqueue_X* self); +cqueue_X_value* cqueue_X_front(const cqueue_X* self); +cqueue_X_value* cqueue_X_back(const cqueue_X* self); -cqueue_X_value_t* cqueue_X_push(cqueue_X* self, i_val value); -cqueue_X_value_t* cqueue_X_emplace(cqueue_X* self, i_valraw raw); +cqueue_X_value* cqueue_X_push(cqueue_X* self, i_val value); +cqueue_X_value* cqueue_X_emplace(cqueue_X* self, i_valraw raw); void cqueue_X_pop(cqueue_X* self); -cqueue_X_iter_t cqueue_X_begin(const cqueue_X* self); -cqueue_X_iter_t cqueue_X_end(const cqueue_X* self); -void cqueue_X_next(cqueue_X_iter_t* it); +cqueue_X_iter cqueue_X_begin(const cqueue_X* self); +cqueue_X_iter cqueue_X_end(const cqueue_X* self); +void cqueue_X_next(cqueue_X_iter* it); i_val cqueue_X_value_clone(i_val value); ``` ## Types -| Type name | Type definition | Used to represent... | -|:----------------------|:---------------------|:-------------------------| -| `cqueue_X` | `cdeq_X` | The cqueue type | -| `cqueue_X_value_t` | `i_val` | The cqueue element type | -| `cqueue_X_rawvalue_t` | `i_valraw` | cqueue raw value type | -| `cqueue_X_iter_t` | `cdeq_X_iter_t` | cqueue iterator | +| Type name | Type definition | Used to represent... | +|:--------------------|:---------------------|:-------------------------| +| `cqueue_X` | `cdeq_X` | The cqueue type | +| `cqueue_X_value` | `i_val` | The cqueue element type | +| `cqueue_X_rawvalue` | `i_valraw` | cqueue raw value type | +| `cqueue_X_iter` | `cdeq_X_iter` | cqueue iterator | ## Examples ```c diff --git a/docs/cset_api.md b/docs/cset_api.md index e09436ea..c422fdb2 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -41,34 +41,34 @@ size_t cset_X_capacity(cset_X set); size_t cset_X_bucket_count(cset_X set);
bool cset_X_contains(const cset_X* self, i_keyraw rkey);
-cset_X_value_t* cset_X_get(const cset_X* self, i_keyraw rkey); // return NULL if not found
-cset_X_iter_t cset_X_find(const cset_X* self, i_keyraw rkey);
+cset_X_value* cset_X_get(const cset_X* self, i_keyraw rkey); // return NULL if not found
+cset_X_iter cset_X_find(const cset_X* self, i_keyraw rkey);
-cset_X_result_t cset_X_insert(cset_X* self, i_key key);
-cset_X_result_t cset_X_emplace(cset_X* self, i_keyraw rkey);
+cset_X_result cset_X_insert(cset_X* self, i_key key);
+cset_X_result cset_X_emplace(cset_X* self, i_keyraw rkey);
size_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1
-cset_X_iter_t cset_X_erase_at(cset_X* self, cset_X_iter_t it); // return iter after it
-void cset_X_erase_entry(cset_X* self, cset_X_value_t* entry);
+cset_X_iter cset_X_erase_at(cset_X* self, cset_X_iter it); // return iter after it
+void cset_X_erase_entry(cset_X* self, cset_X_value* entry);
-cset_X_iter_t cset_X_begin(const cset_X* self);
-cset_X_iter_t cset_X_end(const cset_X* self);
-void cset_X_next(cset_X_iter_t* it);
+cset_X_iter cset_X_begin(const cset_X* self);
+cset_X_iter cset_X_end(const cset_X* self);
+void cset_X_next(cset_X_iter* it);
-cset_X_value_t cset_X_value_clone(cset_X_value_t val);
+cset_X_value cset_X_value_clone(cset_X_value val);
```
## Types
-| Type name | Type definition | Used to represent... |
-|:---------------------|:-------------------------------------------------|:----------------------------|
-| `cset_X` | `struct { ... }` | The cset type |
-| `cset_X_rawkey_t` | `i_keyraw` | The raw key type |
-| `cset_X_rawvalue_t` | `i_keyraw` | The raw value type |
-| `cset_X_key_t` | `i_key` | The key type |
-| `cset_X_value_t` | `i_key` | The value |
-| `cset_X_result_t` | `struct { cset_X_value_t* ref; bool inserted; }` | Result of insert/emplace |
-| `cset_X_iter_t` | `struct { cset_X_value_t *ref; ... }` | Iterator type |
+| Type name | Type definition | Used to represent... |
+|:-------------------|:-------------------------------------------------|:----------------------------|
+| `cset_X` | `struct { ... }` | The cset type |
+| `cset_X_rawkey` | `i_keyraw` | The raw key type |
+| `cset_X_rawvalue` | `i_keyraw` | The raw value type |
+| `cset_X_key` | `i_key` | The key type |
+| `cset_X_value` | `i_key` | The value |
+| `cset_X_result` | `struct { cset_X_value* ref; bool inserted; }` | Result of insert/emplace |
+| `cset_X_iter` | `struct { cset_X_value *ref; ... }` | Iterator type |
## Example
```c
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index d76502b2..96d71d30 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -46,44 +46,44 @@ bool csmap_X_empty(csmap_X map); size_t csmap_X_size(csmap_X map); bool csmap_X_contains(const csmap_X* self, i_keyraw rkey); -csmap_X_mapped_t* csmap_X_at(const csmap_X* self, i_keyraw rkey); // rkey must be in map. -csmap_X_value_t* csmap_X_get(const csmap_X* self, i_keyraw rkey); // return NULL if not found -csmap_X_iter_t csmap_X_lower_bound(const csmap_X* self, i_keyraw rkey); // find closest entry >= rkey -csmap_X_iter_t csmap_X_find(const csmap_X* self, i_keyraw rkey); -csmap_X_value_t* csmap_X_find_it(const csmap_X* self, i_keyraw rkey, csmap_X_iter_t* out); // return NULL if not found +csmap_X_mapped* csmap_X_at(const csmap_X* self, i_keyraw rkey); // rkey must be in map. +csmap_X_value* csmap_X_get(const csmap_X* self, i_keyraw rkey); // return NULL if not found +csmap_X_iter csmap_X_lower_bound(const csmap_X* self, i_keyraw rkey); // find closest entry >= rkey +csmap_X_iter csmap_X_find(const csmap_X* self, i_keyraw rkey); +csmap_X_value* csmap_X_find_it(const csmap_X* self, i_keyraw rkey, csmap_X_iter* out); // return NULL if not found -csmap_X_result_t csmap_X_insert(csmap_X* self, i_key key, i_val mapped); // no change if key in map -csmap_X_result_t csmap_X_insert_or_assign(csmap_X* self, i_key key, i_val mapped); // always update mapped -csmap_X_result_t csmap_X_put(csmap_X* self, i_key key, i_val mapped); // same as insert_or_assign() +csmap_X_result csmap_X_insert(csmap_X* self, i_key key, i_val mapped); // no change if key in map +csmap_X_result csmap_X_insert_or_assign(csmap_X* self, i_key key, i_val mapped); // always update mapped +csmap_X_result csmap_X_put(csmap_X* self, i_key key, i_val mapped); // same as insert_or_assign() -csmap_X_result_t csmap_X_emplace(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map -csmap_X_result_t csmap_X_emplace_or_assign(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped +csmap_X_result csmap_X_emplace(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map +csmap_X_result csmap_X_emplace_or_assign(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped size_t csmap_X_erase(csmap_X* self, i_keyraw rkey); -csmap_X_iter_t csmap_X_erase_at(csmap_X* self, csmap_X_iter_t it); // returns iter after it -csmap_X_iter_t csmap_X_erase_range(csmap_X* self, csmap_X_iter_t it1, csmap_X_iter_t it2); // returns updated it2 +csmap_X_iter csmap_X_erase_at(csmap_X* self, csmap_X_iter it); // returns iter after it +csmap_X_iter csmap_X_erase_range(csmap_X* self, csmap_X_iter it1, csmap_X_iter it2); // returns updated it2 -csmap_X_iter_t csmap_X_begin(const csmap_X* self); -csmap_X_iter_t csmap_X_end(const csmap_X* self); -void csmap_X_next(csmap_X_iter_t* iter); -csmap_X_iter_t csmap_X_advance(csmap_X_iter_t it, size_t n); +csmap_X_iter csmap_X_begin(const csmap_X* self); +csmap_X_iter csmap_X_end(const csmap_X* self); +void csmap_X_next(csmap_X_iter* iter); +csmap_X_iter csmap_X_advance(csmap_X_iter it, size_t n); -csmap_X_value_t csmap_X_value_clone(csmap_X_value_t val); -csmap_X_rawvalue_t csmap_X_value_toraw(csmap_X_value_t* pval); +csmap_X_value csmap_X_value_clone(csmap_X_value val); +csmap_X_rawvalue csmap_X_value_toraw(csmap_X_value* pval); ``` ## Types -| Type name | Type definition | Used to represent... | -|:----------------------|:--------------------------------------------------|:-----------------------------| -| `csmap_X` | `struct { ... }` | The csmap type | -| `csmap_X_rawkey_t` | `i_keyraw` | The raw key type | -| `csmap_X_rawmapped_t` | `i_valraw` | The raw mapped type | -| `csmap_X_rawvalue_t` | `struct { i_keyraw first; i_valraw second; }` | i_keyraw+i_valraw type | -| `csmap_X_key_t` | `i_key` | The key type | -| `csmap_X_mapped_t` | `i_val` | The mapped type | -| `csmap_X_value_t` | `struct { const i_key first; i_val second; }` | The value: key is immutable | -| `csmap_X_result_t` | `struct { csmap_X_value_t *ref; bool inserted; }` | Result of insert/put/emplace | -| `csmap_X_iter_t` | `struct { csmap_X_value_t *ref; ... }` | Iterator type | +| Type name | Type definition | Used to represent... | +|:--------------------|:--------------------------------------------------|:-----------------------------| +| `csmap_X` | `struct { ... }` | The csmap type | +| `csmap_X_rawkey` | `i_keyraw` | The raw key type | +| `csmap_X_rawmapped` | `i_valraw` | The raw mapped type | +| `csmap_X_rawvalue` | `struct { i_keyraw first; i_valraw second; }` | i_keyraw+i_valraw type | +| `csmap_X_key` | `i_key` | The key type | +| `csmap_X_mapped` | `i_val` | The mapped type | +| `csmap_X_value` | `struct { const i_key first; i_val second; }` | The value: key is immutable | +| `csmap_X_result` | `struct { csmap_X_value *ref; bool inserted; }` | Result of insert/put/emplace | +| `csmap_X_iter` | `struct { csmap_X_value *ref; ... }` | Iterator type | ## Examples ```c diff --git a/docs/csptr_api.md b/docs/csptr_api.md index bd9bf7d2..ba85ba8c 100644 --- a/docs/csptr_api.md +++ b/docs/csptr_api.md @@ -52,7 +52,6 @@ void csptr_X_reset_with(csptr_X* self, i_val val); // make and as void csptr_X_reset_from(csptr_X* self, i_val* p); // create csptr from p. int csptr_X_compare(const csptr_X* x, const csptr_X* y); -bool csptr_X_equals(const csptr_X* x, const csptr_X* y); ``` ## Types and constants @@ -60,8 +59,8 @@ bool csptr_X_equals(const csptr_X* x, const csptr_X* y); | Type name | Type definition | Used to represent... | |:--------------------|:--------------------------------------------------------------|:-------------------------| | `csptr_null` | `{NULL, NULL}` | Init nullptr const | -| `csptr_X` | `struct { csptr_X_value_t* get; atomic_count_t* use_count; }` | The csptr type | -| `csptr_X_value_t` | `i_val` | The csptr element type | +| `csptr_X` | `struct { csptr_X_value* get; atomic_count_t* use_count; }` | The csptr type | +| `csptr_X_value` | `i_val` | The csptr element type | | `atomic_count_t` | `long` | The reference counter | ## Example diff --git a/docs/csset_api.md b/docs/csset_api.md index 67ff1911..22573b25 100644 --- a/docs/csset_api.md +++ b/docs/csset_api.md @@ -34,36 +34,36 @@ bool csset_X_empty(csset_X set); size_t csset_X_size(csset_X set);
bool csset_X_contains(const csset_X* self, i_keyraw rkey);
-csset_X_value_t* csset_X_get(const csset_X* self, i_keyraw rkey); // return NULL if not found
-csset_X_iter_t csset_X_lower_bound(const csset_X* self, i_keyraw rkey); // find closest entry >= rkey
-csset_X_iter_t csset_X_find(const csset_X* self, i_keyraw rkey);
-csset_X_value_t* csset_X_find_it(const csset_X* self, i_keyraw rkey, csset_X_iter_t* out); // return NULL if not found
+csset_X_value* csset_X_get(const csset_X* self, i_keyraw rkey); // return NULL if not found
+csset_X_iter csset_X_lower_bound(const csset_X* self, i_keyraw rkey); // find closest entry >= rkey
+csset_X_iter csset_X_find(const csset_X* self, i_keyraw rkey);
+csset_X_value* csset_X_find_it(const csset_X* self, i_keyraw rkey, csset_X_iter* out); // return NULL if not found
-csset_X_result_t csset_X_insert(csset_X* self, i_key key);
-csset_X_result_t csset_X_emplace(csset_X* self, i_keyraw rkey);
+csset_X_result csset_X_insert(csset_X* self, i_key key);
+csset_X_result csset_X_emplace(csset_X* self, i_keyraw rkey);
size_t csset_X_erase(csset_X* self, i_keyraw rkey);
-csset_X_iter_t csset_X_erase_at(csset_X* self, csset_X_iter_t it); // return iter after it
-csset_X_iter_t csset_X_erase_range(csset_X* self, csset_X_iter_t it1, csset_X_iter_t it2); // return updated it2
+csset_X_iter csset_X_erase_at(csset_X* self, csset_X_iter it); // return iter after it
+csset_X_iter csset_X_erase_range(csset_X* self, csset_X_iter it1, csset_X_iter it2); // return updated it2
-csset_X_iter_t csset_X_begin(const csset_X* self);
-csset_X_iter_t csset_X_end(const csset_X* self);
-void csset_X_next(csset_X_iter_t* it);
+csset_X_iter csset_X_begin(const csset_X* self);
+csset_X_iter csset_X_end(const csset_X* self);
+void csset_X_next(csset_X_iter* it);
-csset_X_value_t csset_X_value_clone(csset_X_value_t val);
+csset_X_value csset_X_value_clone(csset_X_value val);
```
## Types
-| Type name | Type definition | Used to represent... |
-|:---------------------|:--------------------------------------------------|:----------------------------|
-| `csset_X` | `struct { ... }` | The csset type |
-| `csset_X_rawkey_t` | `i_rawkey` | The raw key type |
-| `csset_X_rawvalue_t` | `i_rawkey` | The raw key type |
-| `csset_X_key_t` | `i_key` | The key type |
-| `csset_X_value_t` | `i_key ` | The value: key is immutable |
-| `csset_X_result_t` | `struct { csset_X_value_t* ref; bool inserted; }` | Result of insert/emplace |
-| `csset_X_iter_t` | `struct { csset_X_value_t *ref; ... }` | Iterator type |
+| Type name | Type definition | Used to represent... |
+|:-------------------|:--------------------------------------------------|:----------------------------|
+| `csset_X` | `struct { ... }` | The csset type |
+| `csset_X_rawkey` | `i_rawkey` | The raw key type |
+| `csset_X_rawvalue` | `i_rawkey` | The raw key type |
+| `csset_X_key` | `i_key` | The key type |
+| `csset_X_value` | `i_key ` | The value: key is immutable |
+| `csset_X_result` | `struct { csset_X_value* ref; bool inserted; }` | Result of insert/emplace |
+| `csset_X_iter` | `struct { csset_X_value *ref; ... }` | Iterator type |
## Example
```c
diff --git a/docs/cstack_api.md b/docs/cstack_api.md index c4a806e1..a1edf9ea 100644 --- a/docs/cstack_api.md +++ b/docs/cstack_api.md @@ -36,30 +36,30 @@ void cstack_X_del(cstack_X* self); // destructor size_t cstack_X_size(cstack_X st); size_t cstack_X_capacity(cstack_X st); bool cstack_X_empty(cstack_X st); -cstack_X_value_t* cstack_X_top(const cstack_X* self); -cstack_X_value_t* cstack_X_at(const cstack_X* self, size_t idx); +cstack_X_value* cstack_X_top(const cstack_X* self); +cstack_X_value* cstack_X_at(const cstack_X* self, size_t idx); -cstack_X_value_t* cstack_X_push(cstack_X* self, i_val value); -cstack_X_value_t* cstack_X_emplace(cstack_X* self, i_valraw raw); +cstack_X_value* cstack_X_push(cstack_X* self, i_val value); +cstack_X_value* cstack_X_emplace(cstack_X* self, i_valraw raw); void cstack_X_pop(cstack_X* self); -cstack_X_iter_t cstack_X_begin(const cstack_X* self); -cstack_X_iter_t cstack_X_end(const cstack_X* self); -void cstack_X_next(cstack_X_iter_t* it); +cstack_X_iter cstack_X_begin(const cstack_X* self); +cstack_X_iter cstack_X_end(const cstack_X* self); +void cstack_X_next(cstack_X_iter* it); -i_valraw cstack_X_value_toraw(cvec_X_value_t* pval); +i_valraw cstack_X_value_toraw(cvec_X_value* pval); i_val cstack_X_value_clone(i_val value); ``` ## Types -| Type name | Type definition | Used to represent... | -|:----------------------|:---------------------------------------|:----------------------------| -| `cstack_X` | `struct { cstack_value_t *data; ... }` | The cstack type | -| `cstack_X_value_t` | `i_val` | The cstack element type | -| `cstack_X_rawvalue_t` | `i_valraw` | cstack raw value type | -| `cstack_X_iter_t` | `struct { cstack_value_t *ref; }` | cstack iterator | +| Type name | Type definition | Used to represent... | +|:--------------------|:---------------------------------------|:----------------------------| +| `cstack_X` | `struct { cstack_value *data; ... }` | The cstack type | +| `cstack_X_value` | `i_val` | The cstack element type | +| `cstack_X_rawvalue` | `i_valraw` | cstack raw value type | +| `cstack_X_iter` | `struct { cstack_value *ref; }` | cstack iterator | ## Example ```c diff --git a/docs/cstr_api.md b/docs/cstr_api.md index ecb58637..acea7b6f 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -60,8 +60,8 @@ void cstr_replace_all(cstr* self, const char* find, const char* replace) void cstr_erase(cstr* self, size_t pos); void cstr_erase_n(cstr* self, size_t pos, size_t n); -bool cstr_equalto(cstr s, const char* str); -bool cstr_equalto_s(cstr s, cstr s2); +bool cstr_equals(cstr s, const char* str); +bool cstr_equals_s(cstr s, cstr s2); size_t cstr_find(cstr s, const char* needle); size_t cstr_find_n(cstr s, const char* needle, size_t pos, size_t nmax); bool cstr_contains(cstr s, const char* needle); @@ -73,9 +73,9 @@ void cstr_pop_back(cstr* self); char* cstr_front(cstr* self); char* cstr_back(cstr* self); -cstr_iter_t cstr_begin(cstr* self); -cstr_iter_t cstr_end(cstr* self); -void cstr_next(cstr_iter_t* it); +cstr_iter cstr_begin(cstr* self); +cstr_iter cstr_end(cstr* self); +void cstr_next(cstr_iter* it); bool cstr_getline(cstr *self, FILE *stream); // cstr_getdelim(self, '\n', stream) bool cstr_getdelim(cstr *self, int delim, FILE *stream); // does not append delim to result @@ -86,11 +86,11 @@ Note that all methods with arguments `(..., const char* str, size_t n)`, `n` mus #### Helper methods: ```c int cstr_compare(const cstr *s1, const cstr *s2); -bool cstr_equals(const cstr *s1, const cstr *s2); +bool cstr_equalto(const cstr *s1, const cstr *s2); bool cstr_hash(const cstr *s, ...); int c_rawstr_compare(const char** x, const char** y); -bool c_rawstr_equals(const char** x, const char** y); +bool c_rawstr_equalto(const char** x, const char** y); uint64_t c_rawstr_hash(const char* const* x, ...); uint64_t c_strhash(const char* str); @@ -100,11 +100,11 @@ int c_strncasecmp(const char* str1, const char* str2, size_t n); ## Types -| Type name | Type definition | Used to represent... | -|:------------------|:---------------------------------|:-------------------------| -| `cstr` | `struct { char *str; }` | The string type | -| `cstr_value_t` | `char` | The string element type | -| `cstr_iter_t` | `struct { cstr_value_t *ref; }` | cstr iterator | +| Type name | Type definition | Used to represent... | +|:----------------|:-------------------------------|:-------------------------| +| `cstr` | `struct { char *str; }` | The string type | +| `cstr_value` | `char` | The string element type | +| `cstr_iter` | `struct { cstr_value *ref; }` | cstr iterator | ## Constants and macros diff --git a/docs/csview_api.md b/docs/csview_api.md index 6125ef07..4d80692d 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -45,15 +45,15 @@ csview csview_slice(csview sv, intptr_t p1, intptr_t p2); // negative p csview csview_first_token(csview sv, csview sep); // see split example below. csview csview_next_token(csview sv, csview sep, csview token); -bool csview_equalto(csview sv, csview sv2); +bool csview_equals(csview sv, csview sv2); size_t csview_find(csview sv, csview needle); bool csview_contains(csview sv, csview needle); bool csview_starts_with(csview sv, csview sub); bool csview_ends_with(csview sv, csview sub); -csview_iter_t csview_begin(const csview* self); -csview_iter_t csview_end(const csview* self); -void csview_next(csview_iter_t* it); +csview_iter csview_begin(const csview* self); +csview_iter csview_end(const csview* self); +void csview_next(csview_iter* it); ``` #### Extended cstr methods ```c @@ -79,16 +79,16 @@ bool cstr_ends_with_v(cstr s, csview sub); #### Helper methods ```c int csview_compare(const csview* x, const csview* y); -bool csview_equals(const csview* x, const csview* y); +bool csview_equalto(const csview* x, const csview* y); uint64_t csview_hash(const csview* x, ...); ``` ## Types -| Type name | Type definition | Used to represent... | -|:------------------|:------------------------------------------|:-------------------------| -| `csview` | `struct { const char *str; size_t size }` | The string view type | -| `csview_value_t` | `char` | The string element type | -| `csview_iter_t` | `struct { csview_value_t *ref; }` | csview iterator | +| Type name | Type definition | Used to represent... | +|:----------------|:------------------------------------------|:-------------------------| +| `csview` | `struct { const char *str; size_t size }` | The string view type | +| `csview_value` | `char` | The string element type | +| `csview_iter` | `struct { csview_value *ref; }` | csview iterator | ## Constants and macros diff --git a/docs/cvec_api.md b/docs/cvec_api.md index a14f6952..9953bb4b 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -45,61 +45,60 @@ bool cvec_X_empty(cvec_X vec); size_t cvec_X_size(cvec_X vec); size_t cvec_X_capacity(cvec_X vec); -cvec_X_value_t* cvec_X_at(const cvec_X* self, size_t idx); -cvec_X_value_t* cvec_X_front(const cvec_X* self); -cvec_X_value_t* cvec_X_back(const cvec_X* self); +cvec_X_value* cvec_X_at(const cvec_X* self, size_t idx); +cvec_X_value* cvec_X_front(const cvec_X* self); +cvec_X_value* cvec_X_back(const cvec_X* self); -cvec_X_value_t* cvec_X_push_back(cvec_X* self, i_val value); -cvec_X_value_t* cvec_X_emplace_back(cvec_X* self, i_valraw raw); +cvec_X_value* cvec_X_push_back(cvec_X* self, i_val value); +cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw); void cvec_X_pop_back(cvec_X* self); -cvec_X_iter_t cvec_X_insert(cvec_X* self, size_t idx, i_val value); // move value -cvec_X_iter_t cvec_X_insert_n(cvec_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values -cvec_X_iter_t cvec_X_insert_at(cvec_X* self, cvec_X_iter_t it, i_val value); // move value +cvec_X_iter cvec_X_insert(cvec_X* self, size_t idx, i_val value); // move value +cvec_X_iter cvec_X_insert_n(cvec_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values +cvec_X_iter cvec_X_insert_at(cvec_X* self, cvec_X_iter it, i_val value); // move value -cvec_X_iter_t cvec_X_emplace(cvec_X* self, size_t idx, i_valraw raw); -cvec_X_iter_t cvec_X_emplace_n(cvec_X* self, size_t idx, const i_valraw[] arr, size_t n); -cvec_X_iter_t cvec_X_emplace_at(cvec_X* self, cvec_X_iter_t it, i_valraw raw); -cvec_X_iter_t cvec_X_emplace_range(cvec_X* self, cvec_X_iter_t it, - cvec_X_iter_t it1, cvec_X_iter_t it2); // will clone -cvec_X_iter_t cvec_X_emplace_range_p(cvec_X* self, i_val* pos, +cvec_X_iter cvec_X_emplace(cvec_X* self, size_t idx, i_valraw raw); +cvec_X_iter cvec_X_emplace_n(cvec_X* self, size_t idx, const i_valraw[] arr, size_t n); +cvec_X_iter cvec_X_emplace_at(cvec_X* self, cvec_X_iter it, i_valraw raw); +cvec_X_iter cvec_X_emplace_range(cvec_X* self, cvec_X_iter it, + cvec_X_iter it1, cvec_X_iter it2); // will clone +cvec_X_iter cvec_X_emplace_range_p(cvec_X* self, i_val* pos, const i_val* p1, const i_val* p2); -cvec_X_iter_t cvec_X_erase_n(cvec_X* self, size_t idx, size_t n); -cvec_X_iter_t cvec_X_erase_at(cvec_X* self, cvec_X_iter_t it); -cvec_X_iter_t cvec_X_erase_range(cvec_X* self, cvec_X_iter_t it1, cvec_X_iter_t it2); +cvec_X_iter cvec_X_erase_n(cvec_X* self, size_t idx, size_t n); +cvec_X_iter cvec_X_erase_at(cvec_X* self, cvec_X_iter it); +cvec_X_iter cvec_X_erase_range(cvec_X* self, cvec_X_iter it1, cvec_X_iter it2); -cvec_X_iter_t cvec_X_find(const cvec_X* self, i_valraw raw); -cvec_X_iter_t cvec_X_find_in(cvec_X_iter_t i1, cvec_X_iter_t i2, i_valraw raw); -cvec_X_value_t* cvec_X_get(const cvec_X* self, i_valraw raw); // return NULL if not found -cvec_X_iter_t cvec_X_bsearch(const cvec_X* self, i_valraw raw); -cvec_X_iter_t cvec_X_bsearch_in(cvec_X_iter_t i1, cvec_X_iter_t i2, i_valraw raw); +cvec_X_iter cvec_X_find(const cvec_X* self, i_valraw raw); +cvec_X_iter cvec_X_find_in(cvec_X_iter i1, cvec_X_iter i2, i_valraw raw); +cvec_X_value* cvec_X_get(const cvec_X* self, i_valraw raw); // return NULL if not found +cvec_X_iter cvec_X_bsearch(const cvec_X* self, i_valraw raw); +cvec_X_iter cvec_X_bsearch_in(cvec_X_iter i1, cvec_X_iter i2, i_valraw raw); void cvec_X_sort(cvec_X* self); -void cvec_X_sort_range(cvec_X_iter_t i1, cvec_X_iter_t i2, +void cvec_X_sort_range(cvec_X_iter i1, cvec_X_iter i2, int(*cmp)(const i_val*, const i_val*)); -cvec_X_iter_t cvec_X_begin(const cvec_X* self); -cvec_X_iter_t cvec_X_end(const cvec_X* self); -void cvec_X_next(cvec_X_iter_t* iter); +cvec_X_iter cvec_X_begin(const cvec_X* self); +cvec_X_iter cvec_X_end(const cvec_X* self); +void cvec_X_next(cvec_X_iter* iter); -cvec_X_rawvalue_t cvec_X_value_toraw(cvec_X_value_t* pval); -cvec_X_value_t cvec_X_value_clone(cvec_X_value_t val); +cvec_X_rawvalue cvec_X_value_toraw(cvec_X_value* pval); +cvec_X_value cvec_X_value_clone(cvec_X_value val); ``` ## Types -| Type name | Type definition | Used to represent... | -|:---------------------|:------------------------------------|:-----------------------| -| `cvec_X` | `struct { cvec_X_value_t* data; }` | The cvec type | -| `cvec_X_value_t` | `i_val` | The cvec value type | -| `cvec_X_rawvalue_t` | `i_valraw` | The raw value type | -| `cvec_X_iter_t` | `struct { cvec_X_value_t* ref; }` | The iterator type | +| Type name | Type definition | Used to represent... | +|:-------------------|:----------------------------------|:-----------------------| +| `cvec_X` | `struct { cvec_X_value* data; }` | The cvec type | +| `cvec_X_value` | `i_val` | The cvec value type | +| `cvec_X_rawvalue` | `i_valraw` | The raw value type | +| `cvec_X_iter` | `struct { cvec_X_value* ref; }` | The iterator type | ## Examples ```c #define i_val int -#define i_tag i #include <stc/cvec.h> #include <stdio.h> @@ -107,29 +106,28 @@ cvec_X_value_t cvec_X_value_clone(cvec_X_value_t val); int main() { // Create a vector containing integers - cvec_i vec = cvec_i_init(); - - // Add two integers to vector - cvec_i_push_back(&vec, 25); - cvec_i_push_back(&vec, 13); - - // Append a set of numbers - c_apply(cvec_i, push_back, &vec, {7, 5, 16, 8}); - - printf("initial:"); - c_foreach (k, cvec_i, vec) { - printf(" %d", *k.ref); + c_auto (cvec_int, vec) + { + // Add two integers to vector + cvec_int_push_back(&vec, 25); + cvec_int_push_back(&vec, 13); + + // Append a set of numbers + c_apply(cvec_int, push_back, &vec, {7, 5, 16, 8}); + + printf("initial:"); + c_foreach (k, cvec_int, vec) { + printf(" %d", *k.ref); + } + + // Sort the vector + cvec_int_sort(&vec); + + printf("\nsorted:"); + c_foreach (k, cvec_int, vec) { + printf(" %d", *k.ref); + } } - - // Sort the vector - cvec_i_sort(&vec); - - printf("\nsorted:"); - c_foreach (k, cvec_i, vec) { - printf(" %d", *k.ref); - } - - cvec_i_del(&vec); } ``` Output: diff --git a/examples/advanced.c b/examples/advanced.c index 0466e0da..60276b09 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -22,7 +22,7 @@ uint64_t vikingraw_hash(const VikingRaw* raw, size_t ignore) { uint64_t hash = c_strhash(raw->name) ^ (c_strhash(raw->country) >> 15); return hash; } -static inline int vikingraw_equals(const VikingRaw* rx, const VikingRaw* ry) { +static inline bool vikingraw_equalto(const VikingRaw* rx, const VikingRaw* ry) { return strcmp(rx->name, ry->name) == 0 && strcmp(rx->country, ry->country) == 0; } @@ -37,7 +37,7 @@ static inline VikingRaw viking_toRaw(const Viking* vk) { #define i_tag vk #define i_key Viking #define i_val int -#define i_equ vikingraw_equals +#define i_equ vikingraw_equalto #define i_hash vikingraw_hash #define i_keyraw VikingRaw #define i_keyfrom viking_fromRaw @@ -57,7 +57,7 @@ int main() cmap_vk_emplace_or_assign(&vikings, bjorn, 10); VikingRaw einar = {"Einar", "Norway"}; - cmap_vk_value_t *e = cmap_vk_find(&vikings, einar).ref; + cmap_vk_value *e = cmap_vk_find(&vikings, einar).ref; e->second += 3; // add 3 hp points to Einar cmap_vk_emplace(&vikings, einar, 0).ref->second += 5; // add 5 more to Einar diff --git a/examples/astar.c b/examples/astar.c index 651886e9..04c18113 100644 --- a/examples/astar.c +++ b/examples/astar.c @@ -107,7 +107,7 @@ astar(cstr* maze, int width) int new_cost = *csmap_pcost_at(&costs, current);
if (maze->str[point_index(&next)] != '#')
{
- csmap_pcost_value_t *cost = csmap_pcost_get(&costs, next);
+ csmap_pcost_value *cost = csmap_pcost_get(&costs, next);
if (cost == NULL || new_cost < cost->second)
{
csmap_pcost_insert(&costs, next, new_cost);
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index 993f1837..bbb69a35 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -47,8 +47,8 @@ int main() puts("Starting data of map m2 is:"); printmap(m2); - mymap_iter_t it1 = mymap_advance(mymap_begin(&m2), 1); - mymap_iter_t it2 = mymap_find(&m2, mymap_back(&m2)->first); + mymap_iter it1 = mymap_advance(mymap_begin(&m2), 1); + mymap_iter it2 = mymap_find(&m2, mymap_back(&m2)->first); // The 2nd member function removes elements // in the range [First, Last) mymap_erase_range(&m2, it1, it2); diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 39ffd975..977ae6ca 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -7,12 +7,12 @@ #define i_tag istr #include <stc/csmap.h> -#define i_val csmap_istr_rawvalue_t +#define i_val csmap_istr_rawvalue #define i_cmp c_no_compare #define i_tag istr #include <stc/cvec.h> -void print_elem(csmap_istr_rawvalue_t p) { +void print_elem(csmap_istr_rawvalue p) { printf("(%d, %s) ", p.first, p.second); } @@ -29,11 +29,10 @@ void print_elem(csmap_istr_rawvalue_t p) { using_print_collection(csmap_istr) using_print_collection(cvec_istr) - -void findit(csmap_istr c, csmap_istr_key_t val) +void findit(csmap_istr c, csmap_istr_key val) { printf("Trying find() on value %d\n", val); - csmap_istr_iter_t result = csmap_istr_find(&c, val); // prefer contains() or get() + csmap_istr_iter result = csmap_istr_find(&c, val); // prefer contains() or get() if (result.ref != csmap_istr_end(&c).ref) { printf("Element found: "); print_elem(csmap_istr_value_toraw(result.ref)); puts(""); } else { @@ -50,7 +49,7 @@ int main() puts("The starting map m1 is (key, value):"); print_collection_csmap_istr(m1); - typedef cvec_istr_value_t pair; + typedef cvec_istr_value pair; cvec_istr_emplace_back(&v, (pair){43, "Tc"}); cvec_istr_emplace_back(&v, (pair){41, "Nb"}); cvec_istr_emplace_back(&v, (pair){46, "Pd"}); diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 939f2eca..3e908164 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -14,7 +14,7 @@ #define i_tag istr // Map of int => cstr
#include <stc/csmap.h>
-#define i_val csmap_ii_rawvalue_t
+#define i_val csmap_ii_rawvalue
#define i_cmp c_no_compare
#define i_tag ii
#include <stc/cvec.h>
@@ -42,9 +42,9 @@ int main() print_ii(m1);
// intentionally attempt a duplicate, single element
- csmap_ii_result_t ret = csmap_ii_insert(&m1, 1, 111);
+ csmap_ii_result ret = csmap_ii_insert(&m1, 1, 111);
if (!ret.inserted) {
- csmap_ii_value_t pr = *ret.ref;
+ csmap_ii_value pr = *ret.ref;
puts("Insert failed, element with key value 1 already exists.");
printf(" The existing element is (%d, %d)\n", pr.first, pr.second);
}
@@ -63,7 +63,7 @@ int main() // The templatized version inserting a jumbled range
c_auto (csmap_ii, m2)
c_auto (cvec_ii, v) {
- typedef cvec_ii_value_t ipair;
+ typedef cvec_ii_value ipair;
cvec_ii_push_back(&v, (ipair){43, 294});
cvec_ii_push_back(&v, (ipair){41, 262});
cvec_ii_push_back(&v, (ipair){45, 330});
@@ -83,7 +83,7 @@ int main() // The templatized versions move-constructing elements
c_auto (csmap_istr, m3) {
- csmap_istr_value_t ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
+ csmap_istr_value ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
csmap_istr_insert(&m3, ip1.first, cstr_move(&ip1.second));
diff --git a/examples/csset_erase.c b/examples/csset_erase.c index 6104a2b2..95145ed8 100644 --- a/examples/csset_erase.c +++ b/examples/csset_erase.c @@ -13,7 +13,7 @@ int main() puts("");
int val = 64;
- csset_int_iter_t it;
+ csset_int_iter it;
printf("Show values >= %d:\n", val);
it = csset_int_lower_bound(&set, val);
diff --git a/examples/cstr_match.c b/examples/cstr_match.c index 28c1a22b..9e5cc11c 100644 --- a/examples/cstr_match.c +++ b/examples/cstr_match.c @@ -6,7 +6,7 @@ int main() c_autovar (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_del(&ss)) {
size_t pos = cstr_find_n(ss, "brown", 0, 5);
printf("%zu [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
- printf("equals: %d\n", cstr_equalto(ss, "The quick brown fox jumps over the lazy dog.JPG"));
+ printf("equals: %d\n", cstr_equals(ss, "The quick brown fox jumps over the lazy dog.JPG"));
printf("contains: %d\n", cstr_contains(ss, "umps ove"));
printf("starts_with: %d\n", cstr_starts_with(ss, "The quick brown"));
printf("ends_with: %d\n", cstr_ends_with(ss, ".jpg"));
diff --git a/examples/demos.c b/examples/demos.c index ab1a95ff..49ac8486 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -59,7 +59,7 @@ void vectordemo1() void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_autovar (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
+ c_auto (cvec_str, names) {
cvec_str_emplace_back(&names, "Mary");
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
@@ -79,8 +79,7 @@ void vectordemo2() void listdemo1()
{
printf("\nLISTDEMO1\n");
- c_autovar (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
- c_autovar (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
+ c_auto (clist_ix, nums, nums2)
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -95,7 +94,7 @@ void listdemo1() *clist_ix_find(&nums, 104).ref += 50;
clist_ix_remove(&nums, 103);
- clist_ix_iter_t it = clist_ix_begin(&nums);
+ clist_ix_iter it = clist_ix_begin(&nums);
clist_ix_erase_range(&nums, clist_ix_advance(it, 5), clist_ix_advance(it, 15));
clist_ix_pop_front(&nums);
clist_ix_push_back(&nums, -99);
@@ -145,14 +144,14 @@ void mapdemo1() void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_autovar (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
+ c_auto (cmap_si, nums)
{
cmap_si_emplace_or_assign(&nums, "Hello", 64);
cmap_si_emplace_or_assign(&nums, "Groovy", 121);
cmap_si_emplace_or_assign(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
+ for (cmap_si_iter i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
printf("long: %s: %d\n", i.ref->first.str, i.ref->second);
// or rather use the short form:
@@ -172,7 +171,7 @@ void mapdemo3() cmap_str_emplace(&table, "Map", "test");
cmap_str_emplace(&table, "Make", "my");
cmap_str_emplace(&table, "Sunny", "day");
- cmap_str_iter_t it = cmap_str_find(&table, "Make");
+ cmap_str_iter it = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
printf("size %zu: remove: Make: %s\n", cmap_str_size(table), it.ref->second.str);
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c index a57251bc..b3890ecf 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -22,7 +22,6 @@ int main() // Create and init histogram map with defered destruct
c_auto (csmap_int, mhist)
- c_auto (cstr, bar)
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -30,6 +29,7 @@ int main() }
// Print the gaussian bar chart
+ c_auto (cstr, bar)
c_foreach (i, csmap_int, mhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
diff --git a/examples/list.c b/examples/list.c index 30923e8b..d0d377f3 100644 --- a/examples/list.c +++ b/examples/list.c @@ -44,7 +44,7 @@ int main() { clist_fx_insert(&list, clist_fx_begin(&list), 5); // same as push_front()
clist_fx_push_back(&list, 500);
clist_fx_push_front(&list, 1964);
- clist_fx_iter_t it = clist_fx_begin(&list);
+ clist_fx_iter it = clist_fx_begin(&list);
printf("Full: ");
c_foreach (i, clist_fx, list)
printf(" %g", *i.ref);
diff --git a/examples/list_erase.c b/examples/list_erase.c index c1e5ab61..e2db62d5 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -11,11 +11,11 @@ int main () {
c_apply(clist_i, push_back, &L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
- clist_i_iter_t it = clist_i_begin(&L); // ^
+ clist_i_iter it = clist_i_begin(&L); // ^
clist_i_next(&it);
it = clist_i_erase_at(&L, it); // 10 30 40 50
// ^
- clist_i_iter_t end = clist_i_end(&L); //
+ clist_i_iter end = clist_i_end(&L); //
clist_i_next(&it);
it = clist_i_erase_range(&L, it, end); // 10 30
// ^
diff --git a/examples/list_splice.c b/examples/list_splice.c index 517cbcce..f1049288 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -22,7 +22,7 @@ int main () print_ilist("list1:", list1); print_ilist("list2:", list2); - clist_i_iter_t it = clist_i_advance(clist_i_begin(&list1), 2); + clist_i_iter it = clist_i_advance(clist_i_begin(&list1), 2); it = clist_i_splice(&list1, it, &list2); puts("After splice"); diff --git a/examples/mapmap.c b/examples/mapmap.c index 184a7a7d..047132d1 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -19,7 +19,7 @@ void add(csmap_conf* map, const char* section, const char* entry, const char* va bool contains(csmap_conf* map, const char* section, const char* entry)
{
- csmap_conf_value_t *val = csmap_conf_get(map, section);
+ csmap_conf_value *val = csmap_conf_get(map, section);
return val && csmap_sect_get(&val->second, entry);
}
diff --git a/examples/mmap.c b/examples/mmap.c index 8ecaa6f5..e3c876ce 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -56,7 +56,7 @@ int main() print(mmap);
// find and erase a specific entry
- clist_str_iter_t pos;
+ clist_str_iter pos;
c_foreach (e, csmap_mult, mmap)
if ((pos = clist_str_find(&e.ref->second, "bar")).ref != clist_str_end(&e.ref->second).ref) {
clist_str_erase_at(&e.ref->second, pos);
diff --git a/examples/new_deq.c b/examples/new_deq.c index 7d30343f..0b41b167 100644 --- a/examples/new_deq.c +++ b/examples/new_deq.c @@ -36,25 +36,26 @@ int point_compare(const Point* a, const Point* b) { int main()
{
- cdeq_i32 vec = cdeq_i32_init();
- cdeq_i32_push_back(&vec, 123);
- cdeq_i32_del(&vec);
-
- cdeq_float fvec = cdeq_float_init();
- cdeq_float_push_back(&fvec, 123.3);
- cdeq_float_del(&fvec);
-
- cdeq_pnt pvec = cdeq_pnt_init();
- cdeq_pnt_push_back(&pvec, (Point){42, 14});
- cdeq_pnt_push_back(&pvec, (Point){32, 94});
- cdeq_pnt_push_front(&pvec, (Point){62, 81});
- cdeq_pnt_sort(&pvec);
- c_foreach (i, cdeq_pnt, pvec)
- printf(" (%d %d)", i.ref->x, i.ref->y);
- puts("");
- cdeq_pnt_del(&pvec);
-
- cdeq_str svec = cdeq_str_init();
- cdeq_str_emplace_back(&svec, "Hello, friend");
- cdeq_str_del(&svec);
+ c_auto (cdeq_i32, vec)
+ {
+ cdeq_i32_push_back(&vec, 123);
+ }
+ c_auto (cdeq_float, fvec)
+ {
+ cdeq_float_push_back(&fvec, 123.3);
+ }
+ c_auto (cdeq_pnt, pvec)
+ {
+ cdeq_pnt_push_back(&pvec, (Point){42, 14});
+ cdeq_pnt_push_back(&pvec, (Point){32, 94});
+ cdeq_pnt_push_front(&pvec, (Point){62, 81});
+ cdeq_pnt_sort(&pvec);
+ c_foreach (i, cdeq_pnt, pvec)
+ printf(" (%d %d)", i.ref->x, i.ref->y);
+ puts("");
+ }
+ c_auto (cdeq_str, svec)
+ {
+ cdeq_str_emplace_back(&svec, "Hello, friend");
+ }
}
\ No newline at end of file diff --git a/examples/new_pque.c b/examples/new_pque.c index 8335e46e..94a12fbd 100644 --- a/examples/new_pque.c +++ b/examples/new_pque.c @@ -30,36 +30,36 @@ int Point_cmp(const Point* a, const Point* b) { int main()
{
- cstack_int istk = cstack_int_init();
- cstack_int_push(&istk, 123);
- cstack_int_push(&istk, 321);
- // print
- c_foreach (i, cstack_int, istk)
- printf(" %d", *i.ref);
- cstack_int_del(&istk);
- puts("");
-
- cpque_pnt pque = cpque_pnt_init();
- cpque_pnt_push(&pque, (Point){23, 80});
- cpque_pnt_push(&pque, (Point){12, 32});
- cpque_pnt_push(&pque, (Point){54, 74});
- cpque_pnt_push(&pque, (Point){12, 62});
- // print
- while (!cpque_pnt_empty(pque)) {
- cpque_pnt_value_t *v = cpque_pnt_top(&pque);
- printf(" (%d,%d)", v->x, v->y);
- cpque_pnt_pop(&pque);
+ c_auto (cstack_int, istk)
+ {
+ cstack_int_push(&istk, 123);
+ cstack_int_push(&istk, 321);
+ // print
+ c_foreach (i, cstack_int, istk)
+ printf(" %d", *i.ref);
+ puts("");
+ }
+ c_auto (cpque_pnt, pque)
+ {
+ cpque_pnt_push(&pque, (Point){23, 80});
+ cpque_pnt_push(&pque, (Point){12, 32});
+ cpque_pnt_push(&pque, (Point){54, 74});
+ cpque_pnt_push(&pque, (Point){12, 62});
+ // print
+ while (!cpque_pnt_empty(pque)) {
+ cpque_pnt_value *v = cpque_pnt_top(&pque);
+ printf(" (%d,%d)", v->x, v->y);
+ cpque_pnt_pop(&pque);
+ }
+ puts("");
+ }
+ c_auto (cpque_int, ique)
+ {
+ cpque_int_push(&ique, 123);
+ cpque_int_push(&ique, 321);
+ // print
+ for (int i=0; i<cpque_int_size(ique); ++i)
+ printf(" %d", ique.data[i]);
+ puts("");
}
- // free
- cpque_pnt_del(&pque);
- puts("");
-
- cpque_int ique = cpque_int_init();
- cpque_int_push(&ique, 123);
- cpque_int_push(&ique, 321);
- // print
- for (int i=0; i<cpque_int_size(ique); ++i)
- printf(" %d", ique.data[i]);
- cpque_int_del(&ique);
- puts("");
}
diff --git a/examples/sptr_ex.c b/examples/sptr_ex.c index 17ac27e1..8c803db5 100644 --- a/examples/sptr_ex.c +++ b/examples/sptr_ex.c @@ -38,7 +38,7 @@ void example3() });
c_foreach (s, cvec_song, v)
- if (!cstr_equalto(s.ref->get->artist, "Bob Dylan"))
+ if (!cstr_equals(s.ref->get->artist, "Bob Dylan"))
cvec_song_emplace_back(&v2, *s.ref); // note: calls csptr_song_clone()
c_apply(cvec_song, push_back, &v2, {
diff --git a/examples/sptr_pthread.c b/examples/sptr_pthread.c index 8957a118..444d0afe 100644 --- a/examples/sptr_pthread.c +++ b/examples/sptr_pthread.c @@ -26,7 +26,7 @@ void* thr(csptr_base* lp) c_autoscope (pthread_mutex_lock(&mtx), pthread_mutex_unlock(&mtx))
{
printf("local pointer in a thread:\n"
- " p.get() = %p, p.use_count() = %zu\n", lp->get, *lp->use_count);
+ " p.get() = %p, p.use_count() = %zu\n", (void*)lp->get, *lp->use_count);
}
/* atomically decrease ref. */
csptr_base_del(lp);
@@ -38,7 +38,7 @@ int main() csptr_base p = csptr_base_make((Base){42});
printf("Created a Base\n"
- " p.get() = %p, p.use_count() = %zu\n", p.get, *p.use_count);
+ " p.get() = %p, p.use_count() = %zu\n", (void*)p.get, *p.use_count);
enum {N = 3};
pthread_t t[N];
csptr_base c[N];
@@ -49,7 +49,7 @@ int main() printf("Shared ownership between %d threads and released\n"
"ownership from main:\n"
- " p.get() = %p, p.use_count() = %zu\n", N, p.get, *p.use_count);
+ " p.get() = %p, p.use_count() = %zu\n", N, (void*)p.get, *p.use_count);
csptr_base_reset(&p);
c_forrange (i, N) pthread_join(t[i], NULL);
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index e5dc65ec..98a090e0 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -163,15 +163,15 @@ STC_INLINE cstr_size_t cstr_capacity(cstr s) { return cstr_select_(&s, cap(&s));
}
-STC_INLINE bool cstr_equalto(cstr s1, const char* str) {
+STC_INLINE bool cstr_equals(cstr s1, const char* str) {
return strcmp(cstr_str(&s1), str) == 0;
}
-STC_INLINE bool cstr_equalto_s(cstr s1, cstr s2) {
+STC_INLINE bool cstr_equals_s(cstr s1, cstr s2) {
return strcmp(cstr_str(&s1), cstr_str(&s2)) == 0;
}
-STC_INLINE int cstr_equals(const cstr* s1, const cstr* s2) {
+STC_INLINE bool cstr_equalto(const cstr* s1, const cstr* s2) {
return strcmp(cstr_str(s1), cstr_str(s2)) == 0;
}
diff --git a/include/stc/carr2.h b/include/stc/carr2.h index d2f1e729..3f9d1540 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -58,75 +58,75 @@ int main() { #include "template.h" #ifndef i_fwd -cx_deftypes(_c_carr2_types, Self, i_val); +_cx_deftypes(_c_carr2_types, _cx_self, i_val); #endif -STC_API Self cx_memb(_with_values)(size_t xdim, size_t ydim, i_val value); -STC_API Self cx_memb(_with_storage)(size_t xdim, size_t ydim, cx_value_t* storage); -STC_API Self cx_memb(_clone)(Self src); -STC_API cx_value_t* cx_memb(_release)(Self* self); -STC_API void cx_memb(_del)(Self* self); +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* storage); +STC_API _cx_self _cx_memb(_clone)(_cx_self src); +STC_API _cx_value* _cx_memb(_release)(_cx_self* self); +STC_API void _cx_memb(_del)(_cx_self* self); -STC_INLINE 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)); +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, xdim*ydim)); } -STC_INLINE size_t cx_memb(_size)(Self arr) +STC_INLINE size_t _cx_memb(_size)(_cx_self arr) { return arr.xdim*arr.ydim; } -STC_INLINE cx_value_t *cx_memb(_data)(Self* self) +STC_INLINE _cx_value *_cx_memb(_data)(_cx_self* self) { return *self->data; } -STC_INLINE cx_value_t *cx_memb(_at)(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)(Self *self, Self other) { +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); + _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE cx_iter_t cx_memb(_begin)(const 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 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 Self cx_memb(_with_storage)(size_t xdim, size_t ydim, cx_value_t* block) { - 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; } -STC_DEF Self cx_memb(_with_values)(size_t xdim, size_t ydim, i_val value) { - Self _arr = cx_memb(_init)(xdim, ydim); - for (cx_value_t* p = _arr.data[0], *e = p + xdim*ydim; p != e; ++p) +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* p = _arr.data[0], *e = p + xdim*ydim; p != e; ++p) *p = value; return _arr; } -STC_DEF Self cx_memb(_clone)(Self src) { - 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) +STC_DEF _cx_self _cx_memb(_clone)(_cx_self src) { + _cx_self _arr = _cx_memb(_init)(src.xdim, src.ydim); + 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)(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; } -STC_DEF void cx_memb(_del)(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 45b57acc..1133dcc3 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -59,78 +59,78 @@ int main() { #include "template.h" #ifndef i_fwd -cx_deftypes(_c_carr3_types, Self, i_val); +_cx_deftypes(_c_carr3_types, _cx_self, i_val); #endif -STC_API Self cx_memb(_with_values)(size_t xdim, size_t ydim, size_t zdim, i_val value); -STC_API Self cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, cx_value_t* storage); -STC_API Self cx_memb(_clone)(Self src); -STC_API cx_value_t* cx_memb(_release)(Self* self); -STC_API void cx_memb(_del)(Self* self); +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* storage); +STC_API _cx_self _cx_memb(_clone)(_cx_self src); +STC_API _cx_value* _cx_memb(_release)(_cx_self* self); +STC_API void _cx_memb(_del)(_cx_self* self); -STC_INLINE 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)); +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, xdim*ydim*zdim)); } -STC_INLINE size_t cx_memb(_size)(Self arr) +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)(Self* self) +STC_INLINE _cx_value* _cx_memb(_data)(_cx_self* self) { return **self->data; } -STC_INLINE cx_value_t* cx_memb(_at)(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)(Self *self, Self other) { +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); + _cx_memb(_del)(self); *self = _cx_memb(_clone)(other); } -STC_INLINE cx_iter_t cx_memb(_begin)(const 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 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 Self cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, cx_value_t* block) { - 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; return _arr; } -STC_DEF Self cx_memb(_with_values)(size_t xdim, size_t ydim, size_t zdim, i_val value) { - Self _arr = cx_memb(_init)(xdim, ydim, zdim); - for (cx_value_t* p = **_arr.data, *e = p + xdim*ydim*zdim; p != e; ++p) +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* p = **_arr.data, *e = p + xdim*ydim*zdim; p != e; ++p) *p = value; return _arr; } -STC_DEF Self cx_memb(_clone)(Self src) { - 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) +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* 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)(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; } -STC_DEF void cx_memb(_del)(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/ccommon.h b/include/stc/ccommon.h index b6ab84ff..6e6aefd2 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -97,11 +97,11 @@ #define c_no_compare(x, y) (assert(!"c_no_compare() called"), (x)==(y))
#define c_less_compare(less, x, y) (less(y, x) - less(x, y))
-#define c_default_equals(x, y) (*(x) == *(y))
-#define c_memcmp_equals(x, y) (memcmp(x, y, sizeof *(x)) == 0)
+#define c_default_equalto(x, y) (*(x) == *(y))
+#define c_memcmp_equalto(x, y) (memcmp(x, y, sizeof *(x)) == 0)
#define c_rawstr_compare(x, y) strcmp(*(x), *(y))
-#define c_rawstr_equals(x, y) (strcmp(*(x), *(y)) == 0)
+#define c_rawstr_equalto(x, y) (strcmp(*(x), *(y)) == 0)
#define c_rawstr_hash(p, dummy) c_strhash(*(p))
#define c_no_clone(x) (assert(!"c_no_clone() called"), x)
@@ -126,10 +126,10 @@ STC_INLINE uint64_t c_default_hash(const void *key, size_t len); #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__)
#define c_foreach_3(it, CX, cnt) \
- for (CX##_iter_t it = CX##_begin(&cnt), it##_end_ = CX##_end(&cnt) \
+ for (CX##_iter it = CX##_begin(&cnt), it##_end_ = CX##_end(&cnt) \
; it.ref != it##_end_.ref; CX##_next(&it))
#define c_foreach_4(it, CX, start, finish) \
- for (CX##_iter_t it = start, it##_end_ = finish \
+ for (CX##_iter it = start, it##_end_ = finish \
; it.ref != it##_end_.ref; CX##_next(&it))
#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__)
@@ -163,20 +163,20 @@ STC_INLINE uint64_t c_default_hash(const void *key, size_t len); ; b; b != _c_b ? c_free(b) : (void)0, b = NULL)
#define c_apply(CX, method, cx, ...) do { \
- const CX##_rawvalue_t _c_arr[] = __VA_ARGS__; \
+ const CX##_rawvalue _c_arr[] = __VA_ARGS__; \
CX* _c_cx = cx; \
for (size_t _c_i = 0; _c_i < c_arraylen(_c_arr); ++_c_i) \
CX##_##method(_c_cx, _c_arr[_c_i]); \
} while (0)
#define c_apply_pair(CX, method, cx, ...) do { \
- const CX##_rawvalue_t _c_arr[] = __VA_ARGS__; \
+ const CX##_rawvalue _c_arr[] = __VA_ARGS__; \
CX* _c_cx = cx; \
for (size_t _c_i = 0; _c_i < c_arraylen(_c_arr); ++_c_i) \
CX##_##method(_c_cx, _c_arr[_c_i].first, _c_arr[_c_i].second); \
} while (0)
#define c_apply_n(CX, method, cx, arr, n) do { \
CX* _c_cx = cx; \
- for (const CX##_rawvalue_t *_c_i = arr, *_c_end = _c_i+(n); _c_i != _c_end; ++_c_i) \
+ for (const CX##_rawvalue *_c_i = arr, *_c_end = _c_i+(n); _c_i != _c_end; ++_c_i) \
CX##_##method(_c_cx, *_c_i); \
} while (0)
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 160c7601..ab454247 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -37,160 +37,160 @@ struct cdeq_rep { size_t size, cap; void* base[]; }; #include "template.h"
#if !defined i_fwd
-cx_deftypes(_c_cdeq_types, Self, i_val);
+_cx_deftypes(_c_cdeq_types, _cx_self, i_val);
#endif
-typedef i_valraw cx_rawvalue_t;
+typedef i_valraw _cx_rawvalue;
-STC_API Self cx_memb(_init)(void);
-STC_API Self cx_memb(_clone)(Self cx);
-STC_API void cx_memb(_clear)(Self* self);
-STC_API void cx_memb(_del)(Self* self);
-STC_API cx_value_t* cx_memb(_push_back)(Self* self, i_val value);
-STC_API void cx_memb(_expand_right_half_)(Self* self, size_t idx, size_t n);
+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* _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)(Self* self, i_val value);
-STC_API cx_iter_t cx_memb(_erase_range_p)(Self* self, cx_value_t* p1, cx_value_t* p2);
-STC_API cx_iter_t cx_memb(_insert_range_p)(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)(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)(Self cx) { return !cdeq_rep_(&cx)->size; }
-STC_INLINE size_t cx_memb(_size)(Self cx) { return cdeq_rep_(&cx)->size; }
-STC_INLINE size_t cx_memb(_capacity)(Self cx) { return cdeq_rep_(&cx)->cap; }
-STC_INLINE void cx_memb(_swap)(Self* a, Self* b) {c_swap(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_val cx_memb(_value_clone)(i_val val)
+STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return !cdeq_rep_(&cx)->size; }
+STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cdeq_rep_(&cx)->size; }
+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* 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)(Self *self, Self other) {
+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);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
-STC_INLINE cx_value_t* cx_memb(_emplace_back)(Self* self, i_valraw raw)
- { return cx_memb(_push_back)(self, i_valfrom(raw)); }
-STC_INLINE void cx_memb(_pop_front)(Self* self)
+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 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 Self* self) { return self->data; }
-STC_INLINE cx_iter_t cx_memb(_begin)(const Self* self)
- { return c_make(cx_iter_t){self->data}; }
-STC_INLINE cx_iter_t cx_memb(_end)(const 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 Self
-cx_memb(_with_capacity)(size_t n) {
- Self cx = cx_memb(_init)();
- cx_memb(_expand_right_half_)(&cx, 0, n);
+STC_INLINE _cx_self
+_cx_memb(_with_capacity)(size_t n) {
+ _cx_self cx = _cx_memb(_init)();
+ _cx_memb(_expand_right_half_)(&cx, 0, n);
return cx;
}
STC_INLINE void
-cx_memb(_shrink_to_fit)(Self *self) {
- if (cx_memb(_size)(*self) != cx_memb(_capacity)(*self)) {
- Self cx = cx_memb(_clone)(*self);
- cx_memb(_del)(self); *self = cx;
+_cx_memb(_shrink_to_fit)(_cx_self *self) {
+ if (_cx_memb(_size)(*self) != _cx_memb(_capacity)(*self)) {
+ _cx_self cx = _cx_memb(_clone)(*self);
+ _cx_memb(_del)(self); *self = cx;
}
}
#ifndef i_queue
-STC_INLINE cx_value_t* cx_memb(_emplace_front)(Self* self, i_valraw raw) {
- return cx_memb(_push_front)(self, i_valfrom(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)(Self* self) {
- cx_value_t* p = &self->data[--cdeq_rep_(self)->size];
+STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) {
+ _cx_value* p = &self->data[--cdeq_rep_(self)->size];
i_valdel(p);
}
-STC_INLINE cx_value_t* cx_memb(_at)(const 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)(Self cx, cx_iter_t it) {
+STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) {
return it.ref - cx.data;
}
STC_INLINE void
-cx_memb(_reserve)(Self* self, size_t n) {
+_cx_memb(_reserve)(_cx_self* self, size_t n) {
size_t sz = cdeq_rep_(self)->size;
- if (n > sz) cx_memb(_expand_right_half_)(self, sz, n - sz);
+ if (n > sz) _cx_memb(_expand_right_half_)(self, sz, n - sz);
}
-STC_INLINE cx_iter_t
-cx_memb(_insert)(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
+_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)(Self* self, size_t idx, const cx_value_t arr[], size_t n) {
- return cx_memb(_insert_range_p)(self, self->data + idx, arr, arr + n, false);
+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)(Self* self, cx_iter_t it, i_val value) {
- return cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1, false);
+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
-cx_memb(_emplace)(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
+_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)(Self* self, size_t idx, const cx_rawvalue_t arr[], size_t n) {
- return cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + 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)(Self* self, cx_iter_t it, i_valraw raw) {
- return cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1);
+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)(Self* self, cx_iter_t it, cx_iter_t it1, cx_iter_t it2) {
- return cx_memb(_insert_range_p)(self, it.ref, it1.ref, it2.ref, true);
+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
-cx_memb(_erase_n)(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
+_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)(Self* self, cx_iter_t it) {
- return cx_memb(_erase_range_p)(self, it.ref, it.ref + 1);
+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)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- return cx_memb(_erase_range_p)(self, it1.ref, it2.ref);
+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
-cx_memb(_find)(const Self* self, i_valraw raw) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), raw);
+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*
-cx_memb(_get)(const 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;
+STC_INLINE _cx_value*
+_cx_memb(_get)(const _cx_self* self, i_valraw raw) {
+ _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_);
}
STC_INLINE void
-cx_memb(_sort)(Self* self) {
- cx_memb(_sort_range)(cx_memb(_begin)(self), cx_memb(_end)(self), cx_memb(_value_compare));
+_cx_memb(_sort)(_cx_self* self) {
+ _cx_memb(_sort_range)(_cx_memb(_begin)(self), _cx_memb(_end)(self), _cx_memb(_value_compare));
}
#endif // i_queue
@@ -202,48 +202,48 @@ static struct cdeq_rep _cdeq_sentinel = {0, 0}; #define _cdeq_nfront(self) ((self)->data - (self)->_base)
#endif
-STC_DEF Self
-cx_memb(_init)(void) {
- cx_value_t *b = (cx_value_t *) _cdeq_sentinel.base;
- return c_make(Self){b, b};
+STC_DEF _cx_self
+_cx_memb(_init)(void) {
+ _cx_value *b = (_cx_value *) _cdeq_sentinel.base;
+ return c_make(_cx_self){b, b};
}
STC_DEF void
-cx_memb(_clear)(Self* self) {
+_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;
}
}
STC_DEF void
-cx_memb(_del)(Self* self) {
- cx_memb(_clear)(self);
+_cx_memb(_del)(_cx_self* self) {
+ _cx_memb(_clear)(self);
if (cdeq_rep_(self)->cap)
c_free(cdeq_rep_(self));
}
STC_DEF size_t
-cx_memb(_realloc_)(Self* self, size_t n) {
+_cx_memb(_realloc_)(_cx_self* self, size_t n) {
struct cdeq_rep* rep = cdeq_rep_(self);
size_t sz = rep->size, cap = (size_t) (sz*1.7) + n + 7;
size_t nfront = _cdeq_nfront(self);
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;
}
STC_DEF void
-cx_memb(_expand_right_half_)(Self* self, size_t idx, size_t n) {
+_cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n) {
struct cdeq_rep* rep = cdeq_rep_(self);
size_t sz = rep->size, cap = rep->cap;
size_t nfront = _cdeq_nfront(self), nback = cap - sz - nfront;
- if (nback >= n || sz*1.3 + n > cap && cx_memb(_realloc_)(self, n)) {
+ if (nback >= n || sz*1.3 + n > cap && _cx_memb(_realloc_)(self, n)) {
memmove(self->data + idx + n, self->data + idx, (sz - idx)*sizeof(i_val));
} else {
#ifdef i_queue
@@ -258,19 +258,19 @@ cx_memb(_expand_right_half_)(Self* self, size_t idx, size_t n) { }
}
-STC_DEF cx_value_t*
-cx_memb(_push_back)(Self* self, i_val value) {
+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_memb(_expand_right_half_)(self, rep->size, 1);
+ _cx_value *v = self->data + cdeq_rep_(self)->size++;
*v = value; return v;
}
-STC_DEF Self
-cx_memb(_clone)(Self cx) {
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self cx) {
size_t sz = cdeq_rep_(&cx)->size;
- Self out = cx_memb(_with_capacity)(sz);
+ _cx_self out = _cx_memb(_with_capacity)(sz);
cdeq_rep_(&out)->size = sz;
for (size_t i = 0; i < sz; ++i) out.data[i] = i_valfrom(i_valto(&cx.data[i]));
return out;
@@ -279,34 +279,34 @@ cx_memb(_clone)(Self cx) { #ifndef i_queue
STC_DEF void
-cx_memb(_expand_left_half_)(Self* self, size_t idx, size_t n) {
+_cx_memb(_expand_left_half_)(_cx_self* self, size_t idx, size_t n) {
struct cdeq_rep* rep = cdeq_rep_(self);
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);
+ 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_)(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);
+ if (idx*2 < cdeq_rep_(self)->size) _cx_memb(_expand_left_half_)(self, idx, n);
+ else _cx_memb(_expand_right_half_)(self, idx, n);
if (n) cdeq_rep_(self)->size += n; /* do only if size > 0 */
return self->data + idx;
}
-STC_DEF cx_value_t*
-cx_memb(_push_front)(Self* self, i_val value) {
+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);
+ _cx_memb(_expand_left_half_)(self, 0, 1);
else
--self->data;
++cdeq_rep_(self)->size;
@@ -314,39 +314,39 @@ cx_memb(_push_front)(Self* self, i_val value) { return self->data;
}
-STC_DEF cx_iter_t
-cx_memb(_insert_range_p)(Self* self, cx_value_t* pos,
- const cx_value_t* p1, const cx_value_t* p2, bool clone) {
- pos = cx_memb(_insert_space_)(self, pos, p2 - p1);
- cx_iter_t it = {pos};
+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 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)(Self* self, cx_value_t* pos, const cx_rawvalue_t* p1, const cx_rawvalue_t* p2) {
- pos = cx_memb(_insert_space_)(self, pos, p2 - p1);
- cx_iter_t it = {pos};
+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 it = {pos};
for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1);
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_range_p)(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 aa1ef3e8..0c023afa 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -59,18 +59,18 @@ #include <string.h>
#define _c_clist_complete_types(SELF, dummy) \
- struct SELF##_node_t { \
- struct SELF##_node_t *next; \
- SELF##_value_t value; \
+ struct SELF##_node { \
+ struct SELF##_node *next; \
+ SELF##_value 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, Self, node, val) \
- cx_node_t *entry = c_new (cx_node_t); \
+#define _c_clist_insert_after(self, _cx_self, node, val) \
+ _cx_node *entry = c_new (_cx_node); \
if (node) entry->next = node->next, node->next = entry; \
else entry->next = entry; \
entry->value = val
@@ -84,132 +84,132 @@ _c_clist_complete_types(clist_VOID, dummy); #include "template.h"
#if !defined i_fwd
- cx_deftypes(_c_clist_types, Self, i_val);
+ _cx_deftypes(_c_clist_types, _cx_self, i_val);
#endif
-cx_deftypes(_c_clist_complete_types, Self, dummy);
-typedef i_valraw cx_rawvalue_t;
+_cx_deftypes(_c_clist_complete_types, _cx_self, dummy);
+typedef i_valraw _cx_rawvalue;
STC_API size_t _clist_count(const clist_VOID* self);
-
-STC_API Self cx_memb(_clone)(Self cx);
-STC_API void cx_memb(_del)(Self* self);
-STC_API cx_value_t* cx_memb(_push_back)(Self* self, i_val value);
-STC_API cx_value_t* cx_memb(_push_front)(Self* self, i_val value);
-STC_API cx_iter_t cx_memb(_insert)(Self* self, cx_iter_t it, i_val value);
-STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it);
-STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2);
-STC_API size_t cx_memb(_remove)(Self* self, i_valraw val);
-STC_API cx_iter_t cx_memb(_splice)(Self* self, cx_iter_t it, Self* other);
-STC_API Self cx_memb(_split_off)(Self* self, cx_iter_t it1, cx_iter_t it2);
-STC_API void cx_memb(_sort)(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_)(Self* self, cx_node_t* node);
-
-STC_INLINE Self cx_memb(_init)(void) { return c_make(Self){NULL}; }
-STC_INLINE bool cx_memb(_empty)(Self cx) { return cx.last == NULL; }
-STC_INLINE size_t cx_memb(_count)(Self cx)
+
+STC_API _cx_self _cx_memb(_clone)(_cx_self cx);
+STC_API void _cx_memb(_del)(_cx_self* self);
+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 _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 _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; }
+STC_INLINE size_t _cx_memb(_count)(_cx_self cx)
{ return _clist_count((const clist_VOID*) &cx); }
-STC_INLINE void cx_memb(_clear)(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_val cx_memb(_value_clone)(i_val val)
+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* 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)(Self* self)
- { cx_memb(_erase_after_)(self, self->last); }
-STC_INLINE cx_value_t* cx_memb(_emplace_back)(Self* self, i_valraw raw)
- { return cx_memb(_push_back)(self, i_valfrom(raw)); }
-STC_INLINE cx_value_t* cx_memb(_emplace_front)(Self* self, i_valraw raw)
- { return cx_memb(_push_front)(self, i_valfrom(raw)); }
-STC_INLINE cx_iter_t cx_memb(_emplace)(Self* self, cx_iter_t it, i_valraw raw)
- { return cx_memb(_insert)(self, it, i_valfrom(raw)); }
-STC_INLINE cx_value_t* cx_memb(_front)(const Self* self) { return &self->last->next->value; }
-STC_INLINE cx_value_t* cx_memb(_back)(const 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 _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* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_front)(self, i_valfrom(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* _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)(Self *self, Self other) {
+_cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->last == other.last) return;
- cx_memb(_del)(self); *self = cx_memb(_clone)(other);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
-STC_INLINE cx_iter_t
-cx_memb(_iter)(const 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
-cx_memb(_begin)(const Self* self) {
- cx_value_t* head = self->last ? &self->last->next->value : NULL;
- return c_make(cx_iter_t){head, &self->last, self->last};
+STC_INLINE _cx_iter
+_cx_memb(_begin)(const _cx_self* self) {
+ _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
-cx_memb(_end)(const Self* self) {
- return c_make(cx_iter_t){NULL};
+STC_INLINE _cx_iter
+_cx_memb(_end)(const _cx_self* self) {
+ 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) {
- while (n-- && it.ref) cx_memb(_next)(&it);
+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)(Self* self, cx_iter_t it,
- Self* other, cx_iter_t it1, cx_iter_t it2) {
- Self tmp = cx_memb(_split_off)(other, it1, it2);
- return cx_memb(_splice)(self, it, &tmp);
+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
-cx_memb(_find)(const Self* self, i_valraw val) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), val);
+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*
-cx_memb(_get)(const Self* self, i_valraw val) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), val).ref;
+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;
}
// -------------------------- IMPLEMENTATION -------------------------
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp)
-STC_DEF Self
-cx_memb(_clone)(Self cx) {
- Self out = cx_memb(_init)();
- c_foreach (it, Self, cx) cx_memb(_emplace_back)(&out, i_valto(it.ref));
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self cx) {
+ _cx_self out = _cx_memb(_init)();
+ c_foreach (it, _cx_self, cx) _cx_memb(_emplace_back)(&out, i_valto(it.ref));
return out;
}
STC_DEF void
-cx_memb(_del)(Self* self) {
- while (self->last) cx_memb(_erase_after_)(self, self->last);
+_cx_memb(_del)(_cx_self* self) {
+ while (self->last) _cx_memb(_erase_after_)(self, self->last);
}
-STC_DEF cx_value_t*
-cx_memb(_push_back)(Self* self, i_val value) {
- _c_clist_insert_after(self, Self, self->last, value);
+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*
-cx_memb(_push_front)(Self* self, i_val value) {
- _c_clist_insert_after(self, Self, self->last, value);
+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)(Self* self, cx_iter_t it, i_val value) {
- cx_node_t* node = it.ref ? it.prev : self->last;
- _c_clist_insert_after(self, Self, node, value);
+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;
self->last = entry;
@@ -218,35 +218,35 @@ cx_memb(_insert)(Self* self, cx_iter_t it, i_val value) { return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_at)(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);
+ _cx_memb(_erase_after_)(self, it.prev);
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_range)(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);
+ 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) {
- c_foreach (it, Self, it1, it2) {
+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;
}
it2.ref = NULL; return it2;
}
-STC_DEF cx_node_t*
-cx_memb(_erase_after_)(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;
@@ -255,26 +255,26 @@ cx_memb(_erase_after_)(Self* self, cx_node_t* node) { }
STC_DEF size_t
-cx_memb(_remove)(Self* self, i_valraw val) {
+_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);
if (i_cmp(&r, &val) == 0)
- prev = cx_memb(_erase_after_)(self, prev), ++n;
+ prev = _cx_memb(_erase_after_)(self, prev), ++n;
else
prev = (node == self->last ? NULL : node);
}
return n;
}
-STC_DEF cx_iter_t
-cx_memb(_splice)(Self* self, cx_iter_t it, 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;
@@ -283,11 +283,11 @@ cx_memb(_splice)(Self* self, cx_iter_t it, Self* other) { other->last = NULL; return it;
}
-STC_DEF Self
-cx_memb(_split_off)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- Self cx = {NULL};
+STC_DEF _cx_self
+_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;
@@ -296,19 +296,19 @@ cx_memb(_split_off)(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);
+_cx_memb(_sort_cmp_)(const clist_VOID_node* x, const clist_VOID_node* y) {
+ 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);
}
-STC_API clist_VOID_node_t*
-_clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const clist_VOID_node_t*, const clist_VOID_node_t*));
+STC_API clist_VOID_node*
+_clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const clist_VOID_node*));
STC_DEF void
-cx_memb(_sort)(Self* self) {
+_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 *) self->last->next, _cx_memb(_sort_cmp_));
}
#endif // TEMPLATE IMPLEMENTATION
@@ -317,7 +317,7 @@ cx_memb(_sort)(Self* self) { STC_DEF size_t
_clist_count(const clist_VOID* self) {
- const clist_VOID_node_t *node = self->last;
+ const clist_VOID_node *node = self->last;
if (!node) return 0;
size_t n = 1;
while ((node = node->next) != self->last) ++n;
@@ -326,9 +326,9 @@ _clist_count(const clist_VOID* self) { // Singly linked list Mergesort implementation by Simon Tatham. O(n*log n).
// https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
-STC_DEF clist_VOID_node_t *
-_clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const clist_VOID_node_t*, const clist_VOID_node_t*)) {
- clist_VOID_node_t *p, *q, *e, *tail, *oldhead;
+STC_DEF clist_VOID_node *
+_clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const clist_VOID_node*)) {
+ clist_VOID_node *p, *q, *e, *tail, *oldhead;
int insize = 1, nmerges, psize, qsize, i;
while (1) {
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 7e4e64eb..0c5aab4e 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -37,7 +37,7 @@ int main(void) { cmap_ichar_emplace(&m, 8, 'b');
cmap_ichar_emplace(&m, 12, 'c');
- cmap_ichar_value_t* v = cmap_ichar_get(&m, 10); // NULL
+ cmap_ichar_value* v = cmap_ichar_get(&m, 10); // NULL
char val = *cmap_ichar_at(&m, 5); // 'a'
cmap_ichar_emplace_or_assign(&m, 5, 'd'); // update
cmap_ichar_erase(&m, 8);
@@ -72,80 +72,80 @@ typedef struct { MAP_SIZE_T idx; uint_fast8_t hx; } chash_bucket_t; #endif
#include "template.h"
#ifndef i_fwd
-cx_deftypes(_c_chash_types, Self, i_key, i_val, cx_MAP_ONLY, cx_SET_ONLY);
+_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_valraw cx_memb(_rawmapped_t);
+typedef i_keyraw _cx_rawkey;
+typedef i_valraw _cx_memb(_rawmapped);
typedef cx_SET_ONLY( i_keyraw )
cx_MAP_ONLY( struct { i_keyraw first;
i_valraw second; } )
-cx_rawvalue_t;
-
-STC_API Self cx_memb(_with_capacity)(size_t cap);
-STC_API Self cx_memb(_clone)(Self map);
-STC_API void cx_memb(_del)(Self* self);
-STC_API void cx_memb(_clear)(Self* self);
-STC_API void cx_memb(_reserve)(Self* self, size_t capacity);
-STC_API chash_bucket_t cx_memb(_bucket_)(const Self* self, const cx_rawkey_t* rkeyptr);
-STC_API cx_result_t cx_memb(_insert_entry_)(Self* self, i_keyraw rkey);
-STC_API void cx_memb(_erase_entry)(Self* self, cx_value_t* val);
-
-STC_INLINE Self cx_memb(_init)(void) { return c_make(Self)_cmap_inits; }
-STC_INLINE void cx_memb(_shrink_to_fit)(Self* self) { cx_memb(_reserve)(self, self->size); }
-STC_INLINE void cx_memb(_max_load_factor)(Self* self, float ml) {self->max_load_factor = ml; }
-STC_INLINE bool cx_memb(_empty)(Self m) { return m.size == 0; }
-STC_INLINE size_t cx_memb(_size)(Self m) { return m.size; }
-STC_INLINE size_t cx_memb(_bucket_count)(Self map) { return map.bucket_count; }
-STC_INLINE size_t cx_memb(_capacity)(Self map)
+_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* 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); }
+STC_INLINE void _cx_memb(_max_load_factor)(_cx_self* self, float ml) {self->max_load_factor = ml; }
+STC_INLINE bool _cx_memb(_empty)(_cx_self m) { return m.size == 0; }
+STC_INLINE size_t _cx_memb(_size)(_cx_self m) { return m.size; }
+STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self map) { return map.bucket_count; }
+STC_INLINE size_t _cx_memb(_capacity)(_cx_self map)
{ return (size_t) (map.bucket_count * map.max_load_factor); }
-STC_INLINE void cx_memb(_swap)(Self *map1, Self *map2) {c_swap(Self, *map1, *map2); }
-STC_INLINE bool cx_memb(_contains)(const Self* self, i_keyraw rkey)
- { return self->size && self->_hashx[cx_memb(_bucket_)(self, &rkey).idx]; }
+STC_INLINE void _cx_memb(_swap)(_cx_self *map1, _cx_self *map2) {c_swap(_cx_self, *map1, *map2); }
+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)(Self* self, i_key _key, i_val _mapped);
- STC_API cx_result_t cx_memb(_emplace_or_assign)(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[]: */
- cx_memb(_put)(Self* self, i_key key, i_val mapped) {
- return cx_memb(_insert_or_assign)(self, key, mapped);
+ 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*
- cx_memb(_at)(const Self* self, i_keyraw rkey) {
- chash_bucket_t b = cx_memb(_bucket_)(self, &rkey);
+ 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]);
return &self->table[b.idx].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_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
-cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
- cx_result_t _res = cx_memb(_insert_entry_)(self, rkey);
+STC_INLINE _cx_result
+_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
+ _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,62 +153,62 @@ cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { return _res;
}
-STC_INLINE cx_result_t
-cx_memb(_insert)(Self* self, i_key _key cx_MAP_ONLY(, i_val _mapped)) {
- cx_result_t _res = cx_memb(_insert_entry_)(self, i_keyto(&_key));
+STC_INLINE _cx_result
+_cx_memb(_insert)(_cx_self* self, i_key _key cx_MAP_ONLY(, i_val _mapped)) {
+ _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
-cx_memb(_find)(const Self* self, i_keyraw rkey) {
- cx_size_t idx;
- if (!(self->size && self->_hashx[idx = cx_memb(_bucket_)(self, &rkey).idx]))
+STC_INLINE _cx_iter
+_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
+ _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*
-cx_memb(_get)(const Self* self, i_keyraw rkey) {
- cx_size_t idx;
- return self->size && self->_hashx[idx = cx_memb(_bucket_)(self, &rkey).idx] ?
+STC_INLINE _cx_value*
+_cx_memb(_get)(const _cx_self* self, i_keyraw rkey) {
+ _cx_size idx;
+ return self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx] ?
self->table + idx : NULL;
}
-STC_INLINE cx_iter_t
-cx_memb(_begin)(const Self* self) {
- cx_iter_t it = {self->table, self->_hashx};
+STC_INLINE _cx_iter
+_cx_memb(_begin)(const _cx_self* self) {
+ _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
-cx_memb(_end)(const Self* self)
- { return c_make(cx_iter_t){self->table + self->bucket_count}; }
+STC_INLINE _cx_iter
+_cx_memb(_end)(const _cx_self* self)
+ { 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);
+ while (n--) _cx_memb(_next)(&it);
return it;
}
STC_INLINE size_t
-cx_memb(_erase)(Self* self, i_keyraw rkey) {
+_cx_memb(_erase)(_cx_self* self, i_keyraw rkey) {
if (self->size == 0) return 0;
- chash_bucket_t b = cx_memb(_bucket_)(self, &rkey);
- return self->_hashx[b.idx] ? cx_memb(_erase_entry)(self, self->table + b.idx), 1 : 0;
+ chash_bucket_t b = _cx_memb(_bucket_)(self, &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)(Self* self, cx_iter_t it) {
- cx_memb(_erase_entry)(self, it.ref);
- if (*it._hx == 0) cx_memb(_next)(&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;
}
@@ -230,49 +230,49 @@ STC_INLINE uint64_t c_default_hash(const void *key, size_t len) { #define chash_index_(h, entryPtr) ((entryPtr) - (h).table)
#endif // CMAP_H_INCLUDED
-STC_DEF Self
-cx_memb(_with_capacity)(size_t cap) {
- Self h = _cmap_inits;
- cx_memb(_reserve)(&h, cap);
+STC_DEF _cx_self
+_cx_memb(_with_capacity)(size_t cap) {
+ _cx_self h = _cmap_inits;
+ _cx_memb(_reserve)(&h, cap);
return h;
}
-STC_INLINE void cx_memb(_wipe_)(Self* self) {
+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);
+ for (; e != end; ++e) if (*hx++) _cx_memb(_value_del)(e);
}
-STC_DEF void cx_memb(_del)(Self* self) {
- cx_memb(_wipe_)(self);
+STC_DEF void _cx_memb(_del)(_cx_self* self) {
+ _cx_memb(_wipe_)(self);
c_free(self->_hashx);
c_free((void *) self->table);
}
-STC_DEF void cx_memb(_clear)(Self* self) {
- cx_memb(_wipe_)(self);
+STC_DEF void _cx_memb(_clear)(_cx_self* self) {
+ _cx_memb(_wipe_)(self);
self->size = 0;
memset(self->_hashx, 0, self->bucket_count);
}
-STC_INLINE void cx_memb(_copy)(Self *self, Self other) {
+STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->table == other.table) return;
- cx_memb(_del)(self); *self = cx_memb(_clone)(other);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
cx_MAP_ONLY(
- STC_DEF cx_result_t
- cx_memb(_insert_or_assign)(Self* self, i_key _key, i_val _mapped) {
- cx_result_t _res = cx_memb(_insert_entry_)(self, i_keyto(&_key));
+ STC_DEF _cx_result
+ _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped) {
+ _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
- cx_memb(_emplace_or_assign)(Self* self, i_keyraw rkey, i_valraw rmapped) {
- cx_result_t _res = cx_memb(_insert_entry_)(self, rkey);
+ STC_DEF _cx_result
+ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
+ _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 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 Self* self, const cx_rawkey_t* rkeyptr) { return b;
}
-STC_DEF cx_result_t
-cx_memb(_insert_entry_)(Self* self, i_keyraw rkey) {
- if (self->size + 1 >= (cx_size_t) (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]};
+STC_DEF _cx_result
+_cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) {
+ 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 res = {&self->table[b.idx], !self->_hashx[b.idx]};
if (res.inserted) {
self->_hashx[b.idx] = b.hx;
++self->size;
@@ -308,39 +308,39 @@ cx_memb(_insert_entry_)(Self* self, i_keyraw rkey) { return res;
}
-STC_DEF Self
-cx_memb(_clone)(Self m) {
- Self clone = {
- c_new_n(cx_value_t, m.bucket_count),
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self m) {
+ _cx_self clone = {
+ 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);
+ if (*hx) _cx_memb(_value_clone)(dst, e);
return clone;
}
STC_DEF void
-cx_memb(_reserve)(Self* self, size_t _newcap) {
+_cx_memb(_reserve)(_cx_self* self, size_t _newcap) {
if (_newcap < self->size) return;
size_t _oldcap = self->bucket_count;
_newcap = (size_t) (2 + _newcap / self->max_load_factor) | 1;
- Self _tmp = {
- c_new_n(cx_value_t, _newcap),
+ _cx_self _tmp = {
+ 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(Self, *self, _tmp);
- cx_value_t* e = _tmp.table, *_slot = self->table;
+ _tmp._hashx[_newcap] = 0xff; c_swap(_cx_self, *self, _tmp);
+ _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));
- chash_bucket_t b = cx_memb(_bucket_)(self, &_raw);
+ _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)(Self* self, size_t _newcap) { }
STC_DEF void
-cx_memb(_erase_entry)(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]);
+ _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 3fc8ebea..964a7058 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -34,111 +34,111 @@ #include "template.h"
#if !defined i_fwd
- cx_deftypes(_c_cpque_types, Self, i_val);
+ _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)(Self* self);
-STC_API void cx_memb(_erase_at)(Self* self, size_t idx);
-STC_API void cx_memb(_push)(Self* self, cx_value_t value);
-STC_API Self cx_memb(_clone)(Self q);
+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 value);
+STC_API _cx_self _cx_memb(_clone)(_cx_self q);
-STC_INLINE Self cx_memb(_init)(void)
- { return c_make(Self){0, 0, 0}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){0, 0, 0}; }
-STC_INLINE Self cx_memb(_with_capacity)(size_t cap) {
- Self out = {(cx_value_t *) c_malloc(cap*sizeof(cx_value_t)), 0, cap};
+STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) {
+ _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(_cx_value)), 0, cap};
return out;
}
-STC_INLINE void cx_memb(_reserve)(Self* self, size_t n) {
+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)(Self* self) {
+STC_INLINE void _cx_memb(_clear)(_cx_self* self) {
size_t i = self->size; self->size = 0;
while (i--) i_valdel(&self->data[i]);
}
-STC_INLINE void cx_memb(_del)(Self* self)
- { cx_memb(_clear)(self); c_free(self->data); }
+STC_INLINE void _cx_memb(_del)(_cx_self* self)
+ { _cx_memb(_clear)(self); c_free(self->data); }
-STC_INLINE void cx_memb(_copy)(Self *self, Self other) {
+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);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
-STC_INLINE size_t cx_memb(_size)(Self q)
+STC_INLINE size_t _cx_memb(_size)(_cx_self q)
{ return q.size; }
-STC_INLINE bool cx_memb(_empty)(Self q)
+STC_INLINE bool _cx_memb(_empty)(_cx_self q)
{ return !q.size; }
-STC_INLINE size_t cx_memb(_capacity)(Self q)
+STC_INLINE size_t _cx_memb(_capacity)(_cx_self q)
{ return q.capacity; }
-STC_INLINE cx_value_t* cx_memb(_top)(const Self* self)
+STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self)
{ return &self->data[0]; }
-STC_INLINE void cx_memb(_pop)(Self* self)
- { cx_memb(_erase_at)(self, 0); }
+STC_INLINE void _cx_memb(_pop)(_cx_self* self)
+ { _cx_memb(_erase_at)(self, 0); }
-STC_INLINE void cx_memb(_emplace)(Self* self, cx_rawvalue_t raw)
- { cx_memb(_push)(self, i_valfrom(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)(Self* self, cx_value_t value) {
- if (self->size == self->capacity) cx_memb(_reserve)(self, self->size*3/2 + 4);
+_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)(Self* self)
- { cx_value_t* p = &self->data[--self->size]; i_valdel(p); }
+_cx_memb(_pop_back)(_cx_self* self)
+ { _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)(Self* self) {
- size_t n = cx_memb(_size)(*self);
- cx_value_t *arr = self->data - 1;
+_cx_memb(_make_heap)(_cx_self* self) {
+ size_t n = _cx_memb(_size)(*self);
+ _cx_value *arr = self->data - 1;
for (size_t k = n >> 1; k != 0; --k)
- cx_memb(_sift_down_)(arr, k, n);
+ _cx_memb(_sift_down_)(arr, k, n);
}
-STC_DEF Self cx_memb(_clone)(Self q) {
- Self out = {(cx_value_t *) c_malloc(q.size*sizeof(cx_value_t)), q.size, q.size};
+STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) {
+ _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;
}
STC_DEF void
-cx_memb(_erase_at)(Self* self, size_t idx) {
- size_t n = cx_memb(_size)(*self) - 1;
+_cx_memb(_erase_at)(_cx_self* self, size_t idx) {
+ size_t n = _cx_memb(_size)(*self) - 1;
self->data[idx] = self->data[n];
- cx_memb(_pop_back)(self);
- cx_memb(_sift_down_)(self->data - 1, idx + 1, n);
+ _cx_memb(_pop_back)(self);
+ _cx_memb(_sift_down_)(self->data - 1, idx + 1, n);
}
STC_DEF void
-cx_memb(_push)(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_memb(_reserve)(self, self->size*3/2 + 4);
+ _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 3d9a935a..3319d435 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -38,7 +38,7 @@ int main(void) { csmap_sx_emplace(&m, "Testing two", 12.34);
csmap_sx_emplace(&m, "Testing three", 123.4);
- csmap_sx_value_t *v = csmap_sx_get(&m, "Testing five"); // NULL
+ csmap_sx_value *v = csmap_sx_get(&m, "Testing five"); // NULL
double num = *csmap_sx_at(&m, "Testing one");
csmap_sx_emplace_or_assign(&m, "Testing three", 1000.0); // update
csmap_sx_erase(&m, "Testing two");
@@ -74,103 +74,103 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; #include "template.h"
#ifndef i_fwd
-cx_deftypes(_c_aatree_types, Self, i_key, i_val, cx_MAP_ONLY, cx_SET_ONLY);
+_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_valraw cx_memb(_rawmapped_t);
+typedef i_keyraw _cx_rawkey;
+typedef i_valraw _cx_memb(_rawmapped);
typedef cx_SET_ONLY( i_keyraw )
cx_MAP_ONLY( struct { i_keyraw first; i_valraw second; } )
- cx_rawvalue_t;
-
-STC_API Self cx_memb(_init)(void);
-STC_API Self cx_memb(_clone)(Self tree);
-STC_API void cx_memb(_del)(Self* self);
-STC_API void cx_memb(_reserve)(Self* self, size_t cap);
-STC_API cx_value_t* cx_memb(_find_it)(const Self* self, i_keyraw rkey, cx_iter_t* out);
-STC_API cx_iter_t cx_memb(_lower_bound)(const Self* self, i_keyraw rkey);
-STC_API cx_value_t* cx_memb(_front)(const Self* self);
-STC_API cx_value_t* cx_memb(_back)(const Self* self);
-STC_API int cx_memb(_erase)(Self* self, i_keyraw rkey);
-STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it);
-STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2);
-STC_API cx_result_t cx_memb(_insert_entry_)(Self* self, i_keyraw rkey);
-STC_API void cx_memb(_next)(cx_iter_t* it);
-
-STC_INLINE bool cx_memb(_empty)(Self tree) { return _csmap_rep(&tree)->size == 0; }
-STC_INLINE size_t cx_memb(_size)(Self tree) { return _csmap_rep(&tree)->size; }
-STC_INLINE size_t cx_memb(_capacity)(Self tree) { return _csmap_rep(&tree)->cap; }
-STC_INLINE void cx_memb(_clear)(Self* self) { cx_memb(_del)(self); *self = cx_memb(_init)(); }
-STC_INLINE void cx_memb(_swap)(Self* a, Self* b) { c_swap(Self, *a, *b); }
-STC_INLINE bool cx_memb(_contains)(const Self* self, i_keyraw rkey)
- { cx_iter_t it; return cx_memb(_find_it)(self, rkey, &it) != NULL; }
-STC_INLINE cx_value_t* cx_memb(_get)(const Self* self, i_keyraw rkey)
- { cx_iter_t it; return cx_memb(_find_it)(self, rkey, &it); }
-
-STC_INLINE Self
-cx_memb(_with_capacity)(size_t size) {
- Self tree = cx_memb(_init)();
- cx_memb(_reserve)(&tree, size);
+ _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* _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 _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; }
+STC_INLINE size_t _cx_memb(_capacity)(_cx_self tree) { return _csmap_rep(&tree)->cap; }
+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 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) {
+ _cx_self tree = _cx_memb(_init)();
+ _cx_memb(_reserve)(&tree, size);
return tree;
}
STC_INLINE void
-cx_memb(_copy)(Self *self, Self other) {
+_cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->nodes == other.nodes) return;
- cx_memb(_del)(self); *self = cx_memb(_clone)(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)(Self* self, i_key key, i_val mapped);
- STC_API cx_result_t cx_memb(_emplace_or_assign)(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
- cx_memb(_put)(Self* self, i_key key, i_val mapped)
- { return cx_memb(_insert_or_assign)(self, key, mapped); }
+ 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*
- cx_memb(_at)(const Self* self, i_keyraw rkey)
- { cx_iter_t it; return &cx_memb(_find_it)(self, rkey, &it)->second; }
+ STC_INLINE _cx_mapped*
+ _cx_memb(_at)(const _cx_self* self, i_keyraw rkey)
+ { _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; }
)
-STC_INLINE cx_iter_t
-cx_memb(_find)(const Self* self, i_keyraw rkey) {
- cx_iter_t it;
- cx_memb(_find_it)(self, rkey, &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 cx_result_t
-cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
- cx_result_t res = cx_memb(_insert_entry_)(self, rkey);
+STC_INLINE _cx_result
+_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
+ _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,31 +178,31 @@ cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) { return res;
}
-STC_INLINE cx_result_t
-cx_memb(_insert)(Self* self, i_key key cx_MAP_ONLY(, i_val mapped)) {
- cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key));
+STC_INLINE _cx_result
+_cx_memb(_insert)(_cx_self* self, i_key key cx_MAP_ONLY(, i_val mapped)) {
+ _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
-cx_memb(_begin)(const Self* self) {
- cx_iter_t it; it._d = self->nodes, it._top = 0;
- it._tn = (cx_size_t) _csmap_rep(self)->root;
- if (it._tn) cx_memb(_next)(&it);
+STC_INLINE _cx_iter
+_cx_memb(_begin)(const _cx_self* self) {
+ _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
-cx_memb(_end)(const Self* self) {
+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) {
- while (n-- && it.ref) cx_memb(_next)(&it);
+STC_INLINE _cx_iter
+_cx_memb(_advance)(_cx_iter it, size_t n) {
+ while (n-- && it.ref) _cx_memb(_next)(&it);
return it;
}
@@ -213,82 +213,82 @@ cx_memb(_advance)(cx_iter_t it, size_t n) { static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0};
#endif // CSMAP_H_INCLUDED
-STC_DEF Self
-cx_memb(_init)(void) {
- Self tree = {(cx_node_t *) _csmap_sentinel.nodes};
+STC_DEF _cx_self
+_cx_memb(_init)(void) {
+ _cx_self tree = {(_cx_node *) _csmap_sentinel.nodes};
return tree;
}
-STC_DEF cx_value_t*
-cx_memb(_front)(const Self* self) {
- cx_node_t *d = self->nodes;
- cx_size_t tn = (cx_size_t) _csmap_rep(self)->root;
+STC_DEF _cx_value*
+_cx_memb(_front)(const _cx_self* self) {
+ _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*
-cx_memb(_back)(const Self* self) {
- cx_node_t *d = self->nodes;
- cx_size_t tn = (cx_size_t) _csmap_rep(self)->root;
+STC_DEF _cx_value*
+_cx_memb(_back)(const _cx_self* self) {
+ _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;
}
STC_DEF void
-cx_memb(_reserve)(Self* self, size_t cap) {
+_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
-cx_memb(_node_new_)(Self* self, int level) {
+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) {
tn = rep->disp;
rep->disp = self->nodes[tn].link[1];
} else {
- if ((tn = rep->head + 1) > rep->cap) cx_memb(_reserve)(self, 4 + (tn*13 >> 3));
+ 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
- cx_memb(_insert_or_assign)(Self* self, i_key key, i_val mapped) {
- cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key));
+ STC_DEF _cx_result
+ _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) {
+ _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
- cx_memb(_emplace_or_assign)(Self* self, i_keyraw rkey, i_valraw rmapped) {
- cx_result_t res = cx_memb(_insert_entry_)(self, rkey);
+ STC_DEF _cx_result
+ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
+ _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 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 Self* self, i_keyraw rkey, cx_iter_t* out) { return (out->ref = NULL);
}
-STC_DEF cx_iter_t
-cx_memb(_lower_bound)(const Self* self, i_keyraw rkey) {
- cx_iter_t it;
- cx_memb(_find_it)(self, rkey, &it);
+STC_DEF _cx_iter
+_cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) {
+ _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 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_)(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;
@@ -361,52 +361,52 @@ cx_memb(_insert_entry_i_)(Self* self, cx_size_t tn, const cx_rawkey_t* rkey, cx_ dir = (c < 0);
tx = d[tx].link[dir];
}
- tx = cx_memb(_node_new_)(self, 1); d = self->nodes;
+ tx = _cx_memb(_node_new_)(self, 1); d = self->nodes;
res->ref = &d[tx].value, res->inserted = true;
if (top == 0) return tx;
d[up[top - 1]].link[dir] = tx;
while (top--) {
if (top) dir = (d[up[top - 1]].link[1] == up[top]);
- up[top] = cx_memb(_skew_)(d, up[top]);
- up[top] = cx_memb(_split_)(d, up[top]);
+ up[top] = _cx_memb(_skew_)(d, up[top]);
+ up[top] = _cx_memb(_split_)(d, up[top]);
if (top) d[up[top - 1]].link[dir] = up[top];
}
return up[0];
}
-STC_DEF cx_result_t
-cx_memb(_insert_entry_)(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);
+STC_DEF _cx_result
+_cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) {
+ _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);
+ d[tn].link[c < 0] = _cx_memb(_erase_r_)(d, d[tn].link[c < 0], rkey, erased);
else {
if (!(*erased)++)
- cx_memb(_value_del)(&d[tn].value);
+ _cx_memb(_value_del)(&d[tn].value);
if (d[tn].link[0] && d[tn].link[1]) {
tx = d[tn].link[0];
while (d[tx].link[1])
tx = d[tx].link[1];
d[tn].value = d[tx].value; /* move */
raw = i_keyto(cx_keyref(&d[tn].value));
- d[tn].link[0] = cx_memb(_erase_r_)(d, d[tn].link[0], &raw, erased);
+ d[tn].link[0] = _cx_memb(_erase_r_)(d, d[tn].link[0], &raw, erased);
} else { /* unlink node */
tx = tn;
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;
}
}
@@ -414,78 +414,78 @@ cx_memb(_erase_r_)(cx_node_t *d, cx_size_t tn, const cx_rawkey_t* rkey, int *era if (d[d[tn].link[0]].level < d[tn].level - 1 || d[tx].level < d[tn].level - 1) {
if (d[tx].level > --d[tn].level)
d[tx].level = d[tn].level;
- tn = cx_memb(_skew_)(d, tn);
- tx = d[tn].link[1] = cx_memb(_skew_)(d, d[tn].link[1]);
- d[tx].link[1] = cx_memb(_skew_)(d, d[tx].link[1]);
- tn = cx_memb(_split_)(d, tn);
- d[tn].link[1] = cx_memb(_split_)(d, d[tn].link[1]);
+ tn = _cx_memb(_skew_)(d, tn);
+ tx = d[tn].link[1] = _cx_memb(_skew_)(d, d[tn].link[1]);
+ d[tx].link[1] = _cx_memb(_skew_)(d, d[tx].link[1]);
+ tn = _cx_memb(_split_)(d, tn);
+ d[tn].link[1] = _cx_memb(_split_)(d, d[tn].link[1]);
}
return tn;
}
STC_DEF int
-cx_memb(_erase)(Self* self, i_keyraw rkey) {
+_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)(Self* self, cx_iter_t it) {
- cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt;
- cx_memb(_next)(&it);
+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);
- if (it.ref) cx_memb(_find_it)(self, nxt, &it);
+ _cx_memb(_erase)(self, raw);
+ if (it.ref) _cx_memb(_find_it)(self, nxt, &it);
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- if (!it2.ref) { while (it1.ref) it1 = cx_memb(_erase_at)(self, it1);
+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);
- cx_memb(_erase)(self, r1);
- cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1);
+ _cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref);
+ _cx_memb(_erase)(self, r1);
+ _cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1);
}
}
-STC_DEF cx_size_t
-cx_memb(_clone_r_)(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_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;
+ _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;
return tn;
}
-STC_DEF Self
-cx_memb(_clone)(Self tree) {
- 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);
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self tree) {
+ _cx_self clone = _cx_memb(_with_capacity)(_csmap_rep(&tree)->size);
+ _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]);
- cx_memb(_value_del)(&d[tn].value);
+ _cx_memb(_del_r_)(d, d[tn].link[0]);
+ _cx_memb(_del_r_)(d, d[tn].link[1]);
+ _cx_memb(_value_del)(&d[tn].value);
}
}
STC_DEF void
-cx_memb(_del)(Self* self) {
+_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 f8b02c0b..5db626a4 100644 --- a/include/stc/csptr.h +++ b/include/stc/csptr.h @@ -88,47 +88,47 @@ typedef long atomic_count_t; #define cx_decrement(v) c_atomic_decrement(v)
#endif
#ifndef i_fwd
-cx_deftypes(_c_csptr_types, Self, i_val);
+_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; };
+#define cx_csptr_rep struct _cx_memb(_rep_)
+cx_csptr_rep { atomic_count_t counter; _cx_value value; };
-STC_INLINE Self
-cx_memb(_init)(void) { return c_make(Self){NULL, NULL}; }
+STC_INLINE _cx_self
+_cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; }
STC_INLINE atomic_count_t
-cx_memb(_use_count)(Self ptr) { return ptr.use_count ? *ptr.use_count : 0; }
+_cx_memb(_use_count)(_cx_self ptr) { return ptr.use_count ? *ptr.use_count : 0; }
-STC_INLINE Self
-cx_memb(_from)(cx_value_t* p) {
- Self ptr = {p};
+STC_INLINE _cx_self
+_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 Self
-cx_memb(_make)(cx_value_t val) {
- Self ptr; cx_csptr_rep *rep = c_new(cx_csptr_rep);
+STC_INLINE _cx_self
+_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;
return ptr;
}
-STC_INLINE Self
-cx_memb(_clone)(Self ptr) {
+STC_INLINE _cx_self
+_cx_memb(_clone)(_cx_self ptr) {
if (ptr.use_count) cx_increment(ptr.use_count);
return ptr;
}
-STC_INLINE Self
-cx_memb(_move)(Self* self) {
- Self ptr = *self;
+STC_INLINE _cx_self
+_cx_memb(_move)(_cx_self* self) {
+ _cx_self ptr = *self;
self->get = NULL, self->use_count = NULL;
return ptr;
}
STC_INLINE void
-cx_memb(_del)(Self* self) {
+_cx_memb(_del)(_cx_self* self) {
if (self->use_count && cx_decrement(self->use_count) == 0) {
i_valdel(self->get);
if (self->get != &((cx_csptr_rep *)self->use_count)->value)
@@ -138,37 +138,37 @@ cx_memb(_del)(Self* self) { }
STC_INLINE void
-cx_memb(_reset)(Self* self) {
- cx_memb(_del)(self);
+_cx_memb(_reset)(_cx_self* self) {
+ _cx_memb(_del)(self);
self->use_count = NULL, self->get = NULL;
}
STC_INLINE void
-cx_memb(_reset_from)(Self* self, cx_value_t* p) {
- cx_memb(_del)(self);
- *self = cx_memb(_from)(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)(Self* self, cx_value_t val) {
- cx_memb(_del)(self);
- *self = cx_memb(_make)(val);
+_cx_memb(_reset_with)(_cx_self* self, _cx_value val) {
+ _cx_memb(_del)(self);
+ *self = _cx_memb(_make)(val);
}
STC_INLINE void
-cx_memb(_copy)(Self* self, Self ptr) {
+_cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
if (ptr.use_count) cx_increment(ptr.use_count);
- cx_memb(_del)(self); *self = ptr;
+ _cx_memb(_del)(self); *self = ptr;
}
STC_INLINE void
-cx_memb(_take)(Self* self, Self ptr) {
- if (self->get != ptr.get) cx_memb(_del)(self);
+_cx_memb(_take)(_cx_self* self, _cx_self ptr) {
+ if (self->get != ptr.get) _cx_memb(_del)(self);
*self = ptr;
}
STC_INLINE int
-cx_memb(_compare)(const Self* x, const Self* y) {
+_cx_memb(_compare)(const _cx_self* x, const _cx_self* y) {
return i_cmp(x->get, y->get);
}
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index e461ca4b..a57dfcb8 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -34,90 +34,90 @@ #include "template.h"
#if !defined i_fwd
-cx_deftypes(_c_cstack_types, Self, i_val);
+_cx_deftypes(_c_cstack_types, _cx_self, i_val);
#endif
-typedef i_valraw cx_rawvalue_t;
+typedef i_valraw _cx_rawvalue;
-STC_INLINE Self cx_memb(_init)(void)
- { return c_make(Self){0, 0, 0}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){0, 0, 0}; }
-STC_INLINE Self cx_memb(_with_capacity)(size_t cap) {
- Self out = {(cx_value_t *) c_malloc(cap*sizeof(i_val)), 0, cap};
+STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) {
+ _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(i_val)), 0, cap};
return out;
}
-STC_INLINE Self cx_memb(_with_size)(size_t size, i_val fill) {
- Self out = {(cx_value_t *) c_malloc(size*sizeof fill), size, size};
+STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_val fill) {
+ _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)(Self* self) {
- cx_value_t *p = self->data + self->size;
+STC_INLINE void _cx_memb(_clear)(_cx_self* self) {
+ _cx_value *p = self->data + self->size;
while (p-- != self->data) i_valdel(p);
self->size = 0;
}
-STC_INLINE void cx_memb(_del)(Self* self)
- { cx_memb(_clear)(self); c_free(self->data); }
+STC_INLINE void _cx_memb(_del)(_cx_self* self)
+ { _cx_memb(_clear)(self); c_free(self->data); }
-STC_INLINE size_t cx_memb(_size)(Self v)
+STC_INLINE size_t _cx_memb(_size)(_cx_self v)
{ return v.size; }
-STC_INLINE bool cx_memb(_empty)(Self v)
+STC_INLINE bool _cx_memb(_empty)(_cx_self v)
{ return !v.size; }
-STC_INLINE size_t cx_memb(_capacity)(Self v)
+STC_INLINE size_t _cx_memb(_capacity)(_cx_self v)
{ return v.capacity; }
-STC_INLINE cx_value_t* cx_memb(_top)(const 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)(Self* self)
- { cx_value_t* p = &self->data[--self->size]; i_valdel(p); }
+STC_INLINE void _cx_memb(_pop)(_cx_self* self)
+ { _cx_value* p = &self->data[--self->size]; i_valdel(p); }
-STC_INLINE void cx_memb(_reserve)(Self* self, size_t n) {
+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)(Self* self)
- { cx_memb(_reserve)(self, self->size); }
+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)(Self* self, cx_value_t val) {
- if (self->size == self->capacity) cx_memb(_reserve)(self, self->size*3/2 + 4);
- cx_value_t* vp = self->data + self->size++;
+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* vp = self->data + self->size++;
*vp = val; return vp;
}
-STC_INLINE cx_value_t* cx_memb(_emplace)(Self* self, cx_rawvalue_t raw)
- { return cx_memb(_push)(self, i_valfrom(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 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 Self cx_memb(_clone)(Self v) {
- Self out = {(cx_value_t *) c_malloc(v.size*sizeof(cx_value_t)), v.size, v.size};
+STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) {
+ _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;
}
-STC_INLINE void cx_memb(_copy)(Self *self, Self other) {
+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);
+ _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 Self* self)
- { return c_make(cx_iter_t){self->data}; }
-STC_INLINE cx_iter_t cx_memb(_end)(const 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/cstr.h b/include/stc/cstr.h index 41af7925..c0a6650b 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -31,8 +31,8 @@ #include <ctype.h>
typedef struct cstr { char* str; } cstr;
-typedef struct cstr_iter { char *ref; } cstr_iter_t;
-typedef char cstr_value_t;
+typedef struct cstr_iter { char *ref; } cstr_iter;
+typedef char cstr_value;
#define cstr_npos (SIZE_MAX >> 1)
STC_LIBRARY_ONLY( extern const cstr cstr_null; )
@@ -111,14 +111,14 @@ STC_INLINE void cstr_erase(cstr* self, size_t pos) STC_INLINE char* cstr_front(cstr* self) { return self->str; }
STC_INLINE char* cstr_back(cstr* self)
{ return self->str + _cstr_rep(self)->size - 1; }
-STC_INLINE cstr_iter_t cstr_begin(cstr* self)
- { return c_make(cstr_iter_t){self->str}; }
-STC_INLINE cstr_iter_t cstr_end(cstr* self)
- { return c_make(cstr_iter_t){self->str + _cstr_rep(self)->size}; }
-STC_INLINE void cstr_next(cstr_iter_t* it) {++it->ref; }
-STC_INLINE bool cstr_equalto(cstr s, const char* str)
+STC_INLINE cstr_iter cstr_begin(cstr* self)
+ { return c_make(cstr_iter){self->str}; }
+STC_INLINE cstr_iter cstr_end(cstr* self)
+ { return c_make(cstr_iter){self->str + _cstr_rep(self)->size}; }
+STC_INLINE void cstr_next(cstr_iter* it) {++it->ref; }
+STC_INLINE bool cstr_equals(cstr s, const char* str)
{ return strcmp(s.str, str) == 0; }
-STC_INLINE bool cstr_equalto_s(cstr s1, cstr s2)
+STC_INLINE bool cstr_equals_s(cstr s1, cstr s2)
{ return strcmp(s1.str, s2.str) == 0; }
STC_INLINE bool cstr_contains(cstr s, const char* needle)
{ return strstr(s.str, needle) != NULL; }
@@ -168,7 +168,7 @@ cstr_ends_with(cstr s, const char* sub) { /* container adaptor functions: */
#define cstr_compare(xp, yp) strcmp((xp)->str, (yp)->str)
-#define cstr_equals(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
+#define cstr_equalto(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
#define cstr_hash(xp, dummy) c_strhash((xp)->str)
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/csview.h b/include/stc/csview.h index d4ef0bd1..87707d84 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -26,8 +26,8 @@ #include "cstr.h"
typedef struct csview { const char* str; size_t size; } csview;
-typedef struct csview_iter { const char *ref; } csview_iter_t;
-typedef char csview_value_t;
+typedef struct csview_iter { const char *ref; } csview_iter;
+typedef char csview_value;
#define csview_null c_make(csview){"", 0}
#define csview_npos cstr_npos
@@ -57,7 +57,7 @@ STC_INLINE char csview_back(csview sv) { return sv.str[sv.size - 1]; } STC_INLINE void csview_clear(csview* self) { *self = csview_null; }
-STC_INLINE bool csview_equalto(csview sv, csview sv2)
+STC_INLINE bool csview_equals(csview sv, csview sv2)
{ return sv.size == sv2.size && !memcmp(sv.str, sv2.str, sv.size); }
STC_INLINE size_t csview_find(csview sv, csview needle)
{ char* res = c_strnstrn(sv.str, needle.str, sv.size, needle.size);
@@ -70,11 +70,11 @@ STC_INLINE bool csview_starts_with(csview sv, csview sub) STC_INLINE bool csview_ends_with(csview sv, csview sub)
{ if (sub.size > sv.size) return false;
return !memcmp(sv.str + sv.size - sub.size, sub.str, sub.size); }
-STC_INLINE csview_iter_t csview_begin(const csview* self)
- { return c_make(csview_iter_t){self->str}; }
-STC_INLINE csview_iter_t csview_end(const csview* self)
- { return c_make(csview_iter_t){self->str + self->size}; }
-STC_INLINE void csview_next(csview_iter_t* it) { ++it->ref; }
+STC_INLINE csview_iter csview_begin(const csview* self)
+ { return c_make(csview_iter){self->str}; }
+STC_INLINE csview_iter csview_end(const csview* self)
+ { return c_make(csview_iter){self->str + self->size}; }
+STC_INLINE void csview_next(csview_iter* it) { ++it->ref; }
/* cstr interaction with csview: */
@@ -116,7 +116,7 @@ STC_INLINE bool cstr_ends_with_v(cstr s, csview sub) #define csview_compare(xp, yp) strcmp((xp)->str, (yp)->str)
#define csview_hash(xp, dummy) c_strhash((xp)->str)
-#define csview_equals(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
+#define csview_equalto(xp, yp) (strcmp((xp)->str, (yp)->str) == 0)
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 3810e678..92c8f5bd 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -74,148 +74,148 @@ struct cvec_rep { size_t size, cap; void* data[]; }; #include "template.h"
#if !defined i_fwd
- cx_deftypes(_c_cvec_types, Self, i_val);
+ _cx_deftypes(_c_cvec_types, _cx_self, i_val);
#endif
-typedef i_valraw cx_rawvalue_t;
-
-STC_API Self cx_memb(_init)(void);
-STC_API Self cx_memb(_clone)(Self cx);
-STC_API void cx_memb(_del)(Self* self);
-STC_API void cx_memb(_clear)(Self* self);
-STC_API void cx_memb(_reserve)(Self* self, size_t cap);
-STC_API void cx_memb(_resize)(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)(Self* self, i_val value);
-STC_API cx_iter_t cx_memb(_erase_range_p)(Self* self, cx_value_t* p1, cx_value_t* p2);
-STC_API cx_iter_t cx_memb(_insert_range_p)(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)(Self* self, cx_value_t* pos,
- const cx_rawvalue_t* p1, const cx_rawvalue_t* p2);
-
-STC_INLINE size_t cx_memb(_size)(Self cx) { return cvec_rep_(&cx)->size; }
-STC_INLINE size_t cx_memb(_capacity)(Self cx) { return cvec_rep_(&cx)->cap; }
-STC_INLINE bool cx_memb(_empty)(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)
+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(_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* 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* 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)(Self* a, Self* b) { c_swap(Self, *a, *b); }
-STC_INLINE cx_value_t* cx_memb(_front)(const Self* self) { return self->data; }
-STC_INLINE cx_value_t* cx_memb(_back)(const Self* self)
+STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); }
+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)(Self* self, i_valraw raw)
- { return cx_memb(_push_back)(self, i_valfrom(raw)); }
-STC_INLINE void cx_memb(_pop_back)(Self* self)
- { cx_value_t* p = &self->data[--cvec_rep_(self)->size]; i_valdel(p); }
-STC_INLINE cx_iter_t cx_memb(_begin)(const Self* self)
- { return c_make(cx_iter_t){self->data}; }
-STC_INLINE cx_iter_t cx_memb(_end)(const 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)
+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* 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)(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 Self
-cx_memb(_with_size)(size_t size, i_val null_val) {
- Self cx = cx_memb(_init)();
- cx_memb(_resize)(&cx, size, null_val);
+STC_INLINE _cx_self
+_cx_memb(_with_size)(size_t size, i_val null_val) {
+ _cx_self cx = _cx_memb(_init)();
+ _cx_memb(_resize)(&cx, size, null_val);
return cx;
}
-STC_INLINE Self
-cx_memb(_with_capacity)(size_t size) {
- Self cx = cx_memb(_init)();
- cx_memb(_reserve)(&cx, size);
+STC_INLINE _cx_self
+_cx_memb(_with_capacity)(size_t size) {
+ _cx_self cx = _cx_memb(_init)();
+ _cx_memb(_reserve)(&cx, size);
return cx;
}
STC_INLINE void
-cx_memb(_shrink_to_fit)(Self *self) {
- cx_memb(_reserve)(self, cx_memb(_size)(*self));
+_cx_memb(_shrink_to_fit)(_cx_self *self) {
+ _cx_memb(_reserve)(self, _cx_memb(_size)(*self));
}
STC_INLINE void
-cx_memb(_copy)(Self *self, Self other) {
+_cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->data == other.data) return;
- cx_memb(_del)(self); *self = cx_memb(_clone)(other);
+ _cx_memb(_del)(self); *self = _cx_memb(_clone)(other);
}
-STC_INLINE cx_iter_t
-cx_memb(_insert)(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
+_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)(Self* self, size_t idx, const cx_value_t arr[], size_t n) {
- return cx_memb(_insert_range_p)(self, self->data + idx, arr, arr + n, false);
+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)(Self* self, cx_iter_t it, i_val value) {
- return cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1, false);
+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
-cx_memb(_emplace)(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
+_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)(Self* self, size_t idx, const cx_rawvalue_t arr[], size_t n) {
- return cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + 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)(Self* self, cx_iter_t it, i_valraw raw) {
- return cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1);
+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)(Self* self, cx_iter_t it, cx_iter_t it1, cx_iter_t it2) {
- return cx_memb(_insert_range_p)(self, it.ref, it1.ref, it2.ref, true);
+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
-cx_memb(_erase_n)(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
+_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)(Self* self, cx_iter_t it) {
- return cx_memb(_erase_range_p)(self, it.ref, it.ref + 1);
+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)(Self* self, cx_iter_t it1, cx_iter_t it2) {
- return cx_memb(_erase_range_p)(self, it1.ref, it2.ref);
+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*
-cx_memb(_at)(const Self* self, size_t idx) {
+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
-cx_memb(_find)(const Self* self, i_valraw raw) {
- return cx_memb(_find_in)(cx_memb(_begin)(self), cx_memb(_end)(self), raw);
+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*
-cx_memb(_get)(const 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;
+STC_INLINE _cx_value*
+_cx_memb(_get)(const _cx_self* self, i_valraw raw) {
+ _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
-cx_memb(_bsearch)(const Self* self, i_valraw raw) {
- return cx_memb(_bsearch_in)(cx_memb(_begin)(self), cx_memb(_end)(self), raw);
+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)(Self* self) {
- cx_memb(_sort_range)(cx_memb(_begin)(self), cx_memb(_end)(self), cx_memb(_value_compare));
+_cx_memb(_sort)(_cx_self* self) {
+ _cx_memb(_sort_range)(_cx_memb(_begin)(self), _cx_memb(_end)(self), _cx_memb(_value_compare));
}
/* -------------------------- IMPLEMENTATION ------------------------- */
@@ -225,46 +225,46 @@ cx_memb(_sort)(Self* self) { static struct cvec_rep _cvec_sentinel = {0, 0};
#endif
-STC_DEF Self
-cx_memb(_init)(void) {
- Self cx = {(cx_value_t *) _cvec_sentinel.data};
+STC_DEF _cx_self
+_cx_memb(_init)(void) {
+ _cx_self cx = {(_cx_value *) _cvec_sentinel.data};
return cx;
}
STC_DEF void
-cx_memb(_clear)(Self* self) {
+_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;
}
}
STC_DEF void
-cx_memb(_del)(Self* self) {
- cx_memb(_clear)(self);
+_cx_memb(_del)(_cx_self* self) {
+ _cx_memb(_clear)(self);
if (cvec_rep_(self)->cap)
c_free(cvec_rep_(self));
}
STC_DEF void
-cx_memb(_reserve)(Self* self, size_t cap) {
+_cx_memb(_reserve)(_cx_self* self, size_t cap) {
struct cvec_rep* rep = cvec_rep_(self);
size_t len = rep->size;
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;
}
}
STC_DEF void
-cx_memb(_resize)(Self* self, size_t len, i_val fill) {
- if (len > cx_memb(_capacity)(*self))
- cx_memb(_reserve)(self, len);
+_cx_memb(_resize)(_cx_self* self, size_t len, i_val fill) {
+ if (len > _cx_memb(_capacity)(*self))
+ _cx_memb(_reserve)(self, len);
struct cvec_rep* rep = cvec_rep_(self);
size_t i, n = rep->size;
for (i = len; i < n; ++i) i_valdel(&self->data[i]);
@@ -272,68 +272,68 @@ cx_memb(_resize)(Self* self, size_t len, i_val fill) { if (rep->cap) rep->size = len;
}
-STC_DEF cx_value_t*
-cx_memb(_push_back)(Self* self, i_val value) {
+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++;
+ if (len == _cx_memb(_capacity)(*self))
+ _cx_memb(_reserve)(self, (len*13 >> 3) + 4);
+ _cx_value *v = self->data + cvec_rep_(self)->size++;
*v = value; return v;
}
-STC_DEF Self
-cx_memb(_clone)(Self cx) {
+STC_DEF _cx_self
+_cx_memb(_clone)(_cx_self cx) {
size_t len = cvec_rep_(&cx)->size;
- Self out = cx_memb(_with_capacity)(len);
- cx_memb(_insert_range_p)(&out, out.data, cx.data, cx.data + len, true);
+ _cx_self out = _cx_memb(_with_capacity)(len);
+ _cx_memb(_insert_range_p)(&out, out.data, cx.data, cx.data + len, true);
return out;
}
-STC_DEF cx_value_t*
-cx_memb(_insert_space_)(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))
- cx_memb(_reserve)(self, (size*13 >> 3) + len),
+ if (size + len > _cx_memb(_capacity)(*self))
+ _cx_memb(_reserve)(self, (size*13 >> 3) + len),
pos = self->data + idx;
cvec_rep_(self)->size += len;
memmove(pos + len, pos, (size - idx) * sizeof(i_val));
return pos;
}
-STC_DEF cx_iter_t
-cx_memb(_insert_range_p)(Self* self, cx_value_t* pos,
- const cx_value_t* p1, const cx_value_t* p2, bool clone) {
- pos = cx_memb(_insert_space_)(self, pos, p2 - p1);
- cx_iter_t it = {pos};
+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 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)(Self* self, cx_value_t* pos, const cx_rawvalue_t* p1,
- const cx_rawvalue_t* p2) {
- pos = cx_memb(_insert_space_)(self, pos, p2 - p1);
- cx_iter_t it = {pos};
+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 it = {pos};
for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1);
return it;
}
-STC_DEF cx_iter_t
-cx_memb(_erase_range_p)(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/forward.h b/include/stc/forward.h index ec5f77b9..11a32550 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -46,111 +46,111 @@ #define c_false(...)
#define _c_carr2_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
- typedef struct { SELF##_value_t **data; size_t xdim, ydim; } SELF
+ typedef VAL SELF##_value; \
+ typedef struct { SELF##_value *ref; } SELF##_iter; \
+ typedef struct { SELF##_value **data; size_t xdim, ydim; } SELF
#define _c_carr3_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
- typedef struct { SELF##_value_t ***data; size_t xdim, ydim, zdim; } SELF
+ typedef VAL SELF##_value; \
+ typedef struct { SELF##_value *ref; } SELF##_iter; \
+ typedef struct { SELF##_value ***data; size_t xdim, ydim, zdim; } SELF
#define _c_cdeq_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct {SELF##_value_t *ref; } SELF##_iter_t; \
- typedef struct {SELF##_value_t *_base, *data;} SELF
+ typedef VAL SELF##_value, SELF##_value_t; \
+ typedef struct {SELF##_value *ref; } SELF##_iter, SELF##_iter_t; \
+ typedef struct {SELF##_value *_base, *data;} SELF
#define _c_clist_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct SELF##_node_t SELF##_node_t; \
+ typedef VAL SELF##_value, SELF##_value_t; \
+ typedef struct SELF##_node SELF##_node; \
\
typedef struct { \
- SELF##_value_t *ref; \
- SELF##_node_t *const *_last, *prev; \
- } SELF##_iter_t; \
+ SELF##_value *ref; \
+ SELF##_node *const *_last, *prev; \
+ } SELF##_iter, SELF##_iter_t; \
\
typedef struct { \
- SELF##_node_t *last; \
+ SELF##_node *last; \
} SELF
#define _c_chash_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \
- typedef KEY SELF##_key_t; \
- typedef VAL SELF##_mapped_t; \
+ typedef KEY SELF##_key; \
+ typedef VAL SELF##_mapped; \
typedef MAP_SIZE_T SELF##_size_t; \
\
- typedef SET_ONLY( SELF##_key_t ) \
- MAP_ONLY( struct SELF##_value_t ) \
- SELF##_value_t; \
+ typedef SET_ONLY( SELF##_key ) \
+ MAP_ONLY( struct SELF##_value ) \
+ SELF##_value, SELF##_value_t; \
\
typedef struct { \
- SELF##_value_t *ref; \
+ SELF##_value *ref; \
bool inserted; \
- } SELF##_result_t; \
+ } SELF##_result, SELF##_result_t; \
\
typedef struct { \
- SELF##_value_t *ref; \
+ SELF##_value *ref; \
uint8_t* _hx; \
- } SELF##_iter_t; \
+ } SELF##_iter, SELF##_iter_t; \
\
typedef struct { \
- SELF##_value_t* table; \
+ SELF##_value* table; \
uint8_t* _hashx; \
SELF##_size_t size, bucket_count; \
float max_load_factor; \
} SELF
#define _c_aatree_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \
- typedef KEY SELF##_key_t; \
- typedef VAL SELF##_mapped_t; \
+ typedef KEY SELF##_key; \
+ typedef VAL SELF##_mapped; \
typedef MAP_SIZE_T SELF##_size_t; \
- typedef struct SELF##_node_t SELF##_node_t; \
+ typedef struct SELF##_node SELF##_node; \
\
- typedef SET_ONLY( SELF##_key_t ) \
- MAP_ONLY( struct SELF##_value_t ) \
- SELF##_value_t; \
+ typedef SET_ONLY( SELF##_key ) \
+ MAP_ONLY( struct SELF##_value ) \
+ SELF##_value, SELF##_value_t; \
\
typedef struct { \
- SELF##_value_t *ref; \
+ SELF##_value *ref; \
bool inserted; \
- } SELF##_result_t; \
+ } SELF##_result, SELF##_result_t; \
\
typedef struct { \
- SELF##_value_t *ref; \
- SELF##_node_t *_d; \
+ SELF##_value *ref; \
+ SELF##_node *_d; \
int _top; \
SELF##_size_t _tn, _st[36]; \
- } SELF##_iter_t; \
+ } SELF##_iter, SELF##_iter_t; \
\
typedef struct { \
- SELF##_node_t *nodes; \
+ SELF##_node *nodes; \
} SELF
#define _c_csptr_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
+ typedef VAL SELF##_value; \
\
typedef struct { \
- SELF##_value_t* get; \
+ SELF##_value* get; \
long* use_count; \
} SELF
#define _c_cstack_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
+ typedef VAL SELF##_value; \
+ typedef struct { SELF##_value *ref; } SELF##_iter; \
typedef struct SELF { \
- SELF##_value_t* data; \
+ SELF##_value* data; \
size_t size, capacity; \
} SELF
#define _c_cpque_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
+ typedef VAL SELF##_value; \
typedef struct SELF { \
- SELF##_value_t* data; \
+ SELF##_value* data; \
size_t size, capacity; \
} SELF
#define _c_cvec_types(SELF, VAL) \
- typedef VAL SELF##_value_t; \
- typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
- typedef struct { SELF##_value_t *data; } SELF
+ typedef VAL SELF##_value, SELF##_value_t; \
+ typedef struct { SELF##_value *ref; } SELF##_iter, SELF##_iter_t; \
+ typedef struct { SELF##_value *data; } SELF
#endif // STC_FORWARD_H_INCLUDED
diff --git a/include/stc/template.h b/include/stc/template.h index d72228aa..28c6879a 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -25,21 +25,21 @@ #ifndef STC_TEMPLATE_H_INCLUDED
#define STC_TEMPLATE_H_INCLUDED
- #define cx_memb(name) c_PASTE(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_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 _cx_memb(_value)
+ #define _cx_key _cx_memb(_key)
+ #define _cx_mapped _cx_memb(_mapped)
+ #define _cx_rawvalue _cx_memb(_rawvalue)
+ #define _cx_rawkey _cx_memb(_rawkey)
+ #define _cx_rawmapped _cx_memb(_rawmapped)
+ #define _cx_iter _cx_memb(_iter)
+ #define _cx_result _cx_memb(_result)
+ #define _cx_node _cx_memb(_node)
+ #define _cx_size _cx_memb(_size_t)
#endif
-#define Self c_PASTE(i_prefix, i_tag)
#if defined i_valraw && !(defined i_valto && defined i_valfrom)
#error if i_valraw or i_valto defined, i_valfrom must be defined
#endif
@@ -127,7 +127,7 @@ #if !defined i_equ && defined i_cmp
#define i_equ !i_cmp
#elif !defined i_equ
- #define i_equ c_default_equals
+ #define i_equ c_default_equalto
#endif
#ifndef i_hash
#define i_hash c_default_hash
@@ -183,7 +183,6 @@ #undef i_key_csptr
#undef i_val_csptr
#undef i_cnt
-#undef Self
#undef i_template
#endif
|
