diff options
| author | Tyge Løvset <[email protected]> | 2021-10-29 14:39:12 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-10-29 14:39:12 +0200 |
| commit | a0899da505475f4f98e67027d13ffc8da155c201 (patch) | |
| tree | d27788c588543163190807c063ce7b6ccc37e22a /include | |
| parent | 583a0ac357dba6b8c35db7450e8286469516a3b9 (diff) | |
| download | STC-modified-a0899da505475f4f98e67027d13ffc8da155c201.tar.gz STC-modified-a0899da505475f4f98e67027d13ffc8da155c201.zip | |
renamed cx_..._t to _cx_..._t, and Self to _cx_self
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/carr2.h | 60 | ||||
| -rw-r--r-- | include/stc/carr3.h | 62 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 278 | ||||
| -rw-r--r-- | include/stc/clist.h | 222 | ||||
| -rw-r--r-- | include/stc/cmap.h | 236 | ||||
| -rw-r--r-- | include/stc/cpque.h | 90 | ||||
| -rw-r--r-- | include/stc/csmap.h | 350 | ||||
| -rw-r--r-- | include/stc/csptr.h | 62 | ||||
| -rw-r--r-- | include/stc/cstack.h | 80 | ||||
| -rw-r--r-- | include/stc/cvec.h | 286 | ||||
| -rw-r--r-- | include/stc/template.h | 27 |
11 files changed, 876 insertions, 877 deletions
diff --git a/include/stc/carr2.h b/include/stc/carr2.h index d2f1e729..80a47a34 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_t* storage); +STC_API _cx_self _cx_memb(_clone)(_cx_self src); +STC_API _cx_value_t* _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_t, 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_t *_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_t *_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_t _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter_t){*self->data}; } -STC_INLINE cx_iter_t cx_memb(_end)(const Self* self) - { return c_make(cx_iter_t){*self->data + self->xdim*self->ydim}; } +STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter_t){*self->data + self->xdim*self->ydim}; } -STC_INLINE void cx_memb(_next)(cx_iter_t* it) +STC_INLINE void _cx_memb(_next)(_cx_iter_t* 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_t* block) { + _cx_self _arr = {c_new_n(_cx_value_t*, 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_t* 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_t* 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_t *_cx_memb(_release)(_cx_self* self) { + _cx_value_t *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_t* 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..135acda0 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_t* storage); +STC_API _cx_self _cx_memb(_clone)(_cx_self src); +STC_API _cx_value_t* _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_t, 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_t* _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_t* _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_t _cx_memb(_begin)(const _cx_self* self) + { return c_make(_cx_iter_t){**self->data}; } -STC_INLINE cx_iter_t cx_memb(_end)(const Self* self) - { return c_make(cx_iter_t){**self->data + cx_memb(_size)(*self)}; } +STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter_t){**self->data + _cx_memb(_size)(*self)}; } -STC_INLINE void cx_memb(_next)(cx_iter_t* it) +STC_INLINE void _cx_memb(_next)(_cx_iter_t* 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_t* block) { + _cx_self _arr = {c_new_n(_cx_value_t**, xdim*(ydim + 1)), xdim, ydim, zdim}; + _cx_value_t** p = (_cx_value_t**) &_arr.data[xdim]; 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_t* 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_t* 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_t* _cx_memb(_release)(_cx_self* self) { + _cx_value_t *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_t* p = **self->data, *e = p + _cx_memb(_size)(*self); p != e; ++p) i_valdel(p); c_free(self->data[0][0]); /* data */ c_free(self->data); /* pointers */ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 160c7601..0f09238c 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_t;
-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_t* _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_t _cx_memb(_find_in)(_cx_iter_t p1, _cx_iter_t p2, i_valraw raw);
+STC_API int _cx_memb(_value_compare)(const _cx_value_t* x, const _cx_value_t* y);
+STC_API _cx_value_t* _cx_memb(_push_front)(_cx_self* self, i_val value);
+STC_API _cx_iter_t _cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2);
+STC_API _cx_iter_t _cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_value_t* p1, const _cx_value_t* p2, bool clone);
+STC_API _cx_iter_t _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_rawvalue_t* p1, const _cx_rawvalue_t* p2);
#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_t* 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_t* _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_t* _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_t* _cx_memb(_front)(const _cx_self* self) { return self->data; }
+STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data}; }
+STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data + cdeq_rep_(self)->size}; }
+STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; }
+STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs)
{ 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_t* _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_t* 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_t* _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_t 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_t
+_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_t
+_cx_memb(_insert_n)(_cx_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_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_t
+_cx_memb(_insert_at)(_cx_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_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_t
+_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_t
+_cx_memb(_emplace_n)(_cx_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_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_t
+_cx_memb(_emplace_at)(_cx_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_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_t
+_cx_memb(_emplace_range)(_cx_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_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_t
+_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_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t 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_t
+_cx_memb(_erase_range)(_cx_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_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_t
+_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_t*
+_cx_memb(_get)(const _cx_self* self, i_valraw raw) {
+ _cx_iter_t end = _cx_memb(_end)(self);
+ _cx_value_t* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref;
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_t i1, _cx_iter_t i2,
+ int(*_cmp_)(const _cx_value_t*, const _cx_value_t*)) {
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_t *b = (_cx_value_t *) _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_t *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_t *) 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_t*
+_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_t *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_t *) 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_t *) 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_t*
+_cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* 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_t*
+_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_t
+_cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_value_t* p1, const _cx_value_t* p2, bool clone) {
+ pos = _cx_memb(_insert_space_)(self, pos, p2 - p1);
+ _cx_iter_t 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_t
+_cx_memb(_emplace_range_p)(_cx_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};
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_t
+_cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2) {
size_t n = p2 - p1;
if (n > 0) {
- cx_value_t* p = p1, *end = self->data + cdeq_rep_(self)->size;
+ _cx_value_t* 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_t){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_t
+_cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t 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_t* x, const _cx_value_t* 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..85f14378 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -64,13 +64,13 @@ SELF##_value_t value; \
}
-#define clist_node_(vp) c_container_of(vp, cx_node_t, value)
+#define clist_node_(vp) c_container_of(vp, _cx_node_t, 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_t *entry = c_new (_cx_node_t); \
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_t;
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_t* _cx_memb(_push_back)(_cx_self* self, i_val value);
+STC_API _cx_value_t* _cx_memb(_push_front)(_cx_self* self, i_val value);
+STC_API _cx_iter_t _cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value);
+STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it);
+STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2);
+STC_API size_t _cx_memb(_remove)(_cx_self* self, i_valraw val);
+STC_API _cx_iter_t _cx_memb(_splice)(_cx_self* self, _cx_iter_t it, _cx_self* other);
+STC_API _cx_self _cx_memb(_split_off)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2);
+STC_API void _cx_memb(_sort)(_cx_self* self);
+STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw val);
+STC_API _cx_node_t* _cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node);
+
+STC_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_t* 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_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_back)(self, i_valfrom(raw)); }
+STC_INLINE _cx_value_t* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_front)(self, i_valfrom(raw)); }
+STC_INLINE _cx_iter_t _cx_memb(_emplace)(_cx_self* self, _cx_iter_t it, i_valraw raw)
+ { return _cx_memb(_insert)(self, it, i_valfrom(raw)); }
+STC_INLINE _cx_value_t* _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; }
+STC_INLINE _cx_value_t* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; }
STC_INLINE 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_t
+_cx_memb(_iterator)(const _cx_self* self, _cx_node_t* prev) {
+ return c_make(_cx_iter_t){&prev->next->value, &self->last, prev};
}
-STC_INLINE cx_iter_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_t
+_cx_memb(_begin)(const _cx_self* self) {
+ _cx_value_t* head = self->last ? &self->last->next->value : NULL;
+ return c_make(_cx_iter_t){head, &self->last, self->last};
}
-STC_INLINE cx_iter_t
-cx_memb(_end)(const Self* self) {
- return c_make(cx_iter_t){NULL};
+STC_INLINE _cx_iter_t
+_cx_memb(_end)(const _cx_self* self) {
+ return c_make(_cx_iter_t){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_t* it) {
+ _cx_node_t* 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_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_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_t
+_cx_memb(_splice_range)(_cx_self* self, _cx_iter_t it,
+ _cx_self* other, _cx_iter_t it1, _cx_iter_t 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_t
+_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_t*
+_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_t*
+_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_t*
+_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_t
+_cx_memb(_insert)(_cx_self* self, _cx_iter_t it, i_val value) {
+ _cx_node_t* 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_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) {
+ _cx_node_t *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_t
+_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2) {
+ _cx_node_t *node = it1.ref ? it1.prev : NULL,
*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_t
+_cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t 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_t*
+_cx_memb(_erase_after_)(_cx_self* self, _cx_node_t* node) {
+ _cx_node_t* 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_t* 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_t
+_cx_memb(_splice)(_cx_self* self, _cx_iter_t 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_t *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_t it1, _cx_iter_t it2) {
+ _cx_self cx = {NULL};
if (it1.ref == it2.ref) return cx;
- cx_node_t *p1 = it1.prev,
+ _cx_node_t *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,9 +296,9 @@ 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_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);
return i_cmp(&a, &b);
}
@@ -306,9 +306,9 @@ 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_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_t *) _clist_mergesort((clist_VOID_node_t *) self->last->next, _cx_memb(_sort_cmp_));
}
#endif // TEMPLATE IMPLEMENTATION
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 7e4e64eb..61147345 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -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_t {
+ _cx_key_t first;
+ _cx_mapped_t second;
}; )
-typedef i_keyraw cx_rawkey_t;
-typedef i_valraw cx_memb(_rawmapped_t);
+typedef i_keyraw _cx_rawkey_t;
+typedef i_valraw _cx_memb(_rawmapped_t);
typedef cx_SET_ONLY( i_keyraw )
cx_MAP_ONLY( struct { i_keyraw first;
i_valraw second; } )
-cx_rawvalue_t;
-
-STC_API Self cx_memb(_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_t;
+
+STC_API _cx_self _cx_memb(_with_capacity)(size_t cap);
+STC_API _cx_self _cx_memb(_clone)(_cx_self map);
+STC_API void _cx_memb(_del)(_cx_self* self);
+STC_API void _cx_memb(_clear)(_cx_self* self);
+STC_API void _cx_memb(_reserve)(_cx_self* self, size_t capacity);
+STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey_t* rkeyptr);
+STC_API _cx_result_t _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey);
+STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value_t* val);
+
+STC_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_t _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped);
+ STC_API _cx_result_t _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped);
- STC_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_t /* 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_t*
+ _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_t* _dst, _cx_value_t* _val) {
*cx_keyref(_dst) = i_keyfrom(i_keyto(cx_keyref(_val)));
cx_MAP_ONLY( _dst->second = i_valfrom(i_valto(&_val->second)); )
}
-STC_INLINE cx_rawvalue_t
-cx_memb(_value_toraw)(cx_value_t* val) {
+STC_INLINE _cx_rawvalue_t
+_cx_memb(_value_toraw)(_cx_value_t* val) {
return cx_SET_ONLY( i_keyto(val) )
- cx_MAP_ONLY( c_make(cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} );
+ cx_MAP_ONLY( c_make(_cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} );
}
STC_INLINE void
-cx_memb(_value_del)(cx_value_t* _val) {
+_cx_memb(_value_del)(_cx_value_t* _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_t
+_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
+ _cx_result_t _res = _cx_memb(_insert_entry_)(self, rkey);
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_t
+_cx_memb(_insert)(_cx_self* self, i_key _key cx_MAP_ONLY(, i_val _mapped)) {
+ _cx_result_t _res = _cx_memb(_insert_entry_)(self, i_keyto(&_key));
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_t
+_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
+ _cx_size_t 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_t){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_t*
+_cx_memb(_get)(const _cx_self* self, i_keyraw rkey) {
+ _cx_size_t 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_t
+_cx_memb(_begin)(const _cx_self* self) {
+ _cx_iter_t 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_t
+_cx_memb(_end)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->table + self->bucket_count}; }
STC_INLINE void
-cx_memb(_next)(cx_iter_t* it)
+_cx_memb(_next)(_cx_iter_t* 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_t
+_cx_memb(_advance)(_cx_iter_t 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_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t 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_t* 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_t
+ _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped) {
+ _cx_result_t _res = _cx_memb(_insert_entry_)(self, i_keyto(&_key));
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_t
+ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
+ _cx_result_t _res = _cx_memb(_insert_entry_)(self, rkey);
if (_res.inserted) _res.ref->first = i_keyfrom(rkey);
else i_valdel(&_res.ref->second);
_res.ref->second = i_valfrom(rmapped); return _res;
@@ -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_t* 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_t _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_t _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_t
+_cx_memb(_insert_entry_)(_cx_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]};
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_t, 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_t *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_t, _newcap),
(uint8_t *) c_calloc(_newcap + 1, sizeof(uint8_t)),
- self->size, (cx_size_t) _newcap,
+ self->size, (_cx_size_t) _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_t* 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_t _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_t* _val) {
size_t i = chash_index_(*self, _val), j = i, k, _cap = self->bucket_count;
- cx_value_t* _slot = self->table;
+ _cx_value_t* _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_t _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..f4404af1 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_t;
-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_t 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_t *) c_malloc(cap*sizeof(_cx_value_t)), 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_t *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value_t));
}
-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_t* _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_t 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_t 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_t 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_t* 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_t* 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 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_t *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_t *) c_malloc(q.size*sizeof(_cx_value_t)), 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_t 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_t *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..db7a0a8c 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -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_t {
+ _cx_key_t first;
+ _cx_mapped_t second;
}; )
-struct cx_node_t {
- cx_size_t link[2];
+struct _cx_node_t {
+ _cx_size_t link[2];
int8_t level;
- cx_value_t value;
+ _cx_value_t value;
};
-typedef i_keyraw cx_rawkey_t;
-typedef i_valraw cx_memb(_rawmapped_t);
+typedef i_keyraw _cx_rawkey_t;
+typedef i_valraw _cx_memb(_rawmapped_t);
typedef cx_SET_ONLY( i_keyraw )
cx_MAP_ONLY( struct { i_keyraw first; i_valraw second; } )
- cx_rawvalue_t;
-
-STC_API Self cx_memb(_init)(void);
-STC_API Self cx_memb(_clone)(Self tree);
-STC_API void cx_memb(_del)(Self* self);
-STC_API void cx_memb(_reserve)(Self* self, size_t cap);
-STC_API cx_value_t* cx_memb(_find_it)(const Self* self, i_keyraw rkey, cx_iter_t* out);
-STC_API cx_iter_t cx_memb(_lower_bound)(const Self* self, i_keyraw rkey);
-STC_API cx_value_t* cx_memb(_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_t;
+
+STC_API _cx_self _cx_memb(_init)(void);
+STC_API _cx_self _cx_memb(_clone)(_cx_self tree);
+STC_API void _cx_memb(_del)(_cx_self* self);
+STC_API void _cx_memb(_reserve)(_cx_self* self, size_t cap);
+STC_API _cx_value_t* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out);
+STC_API _cx_iter_t _cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey);
+STC_API _cx_value_t* _cx_memb(_front)(const _cx_self* self);
+STC_API _cx_value_t* _cx_memb(_back)(const _cx_self* self);
+STC_API int _cx_memb(_erase)(_cx_self* self, i_keyraw rkey);
+STC_API _cx_iter_t _cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it);
+STC_API _cx_iter_t _cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t it2);
+STC_API _cx_result_t _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey);
+STC_API void _cx_memb(_next)(_cx_iter_t* it);
+
+STC_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_t it; return _cx_memb(_find_it)(self, rkey, &it) != NULL; }
+STC_INLINE _cx_value_t* _cx_memb(_get)(const _cx_self* self, i_keyraw rkey)
+ { _cx_iter_t it; return _cx_memb(_find_it)(self, rkey, &it); }
+
+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_t
+_cx_memb(_value_toraw)(_cx_value_t* val) {
return cx_SET_ONLY( i_keyto(val) )
- cx_MAP_ONLY( c_make(cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} );
+ cx_MAP_ONLY( c_make(_cx_rawvalue_t){i_keyto(&val->first), i_valto(&val->second)} );
}
STC_INLINE void
-cx_memb(_value_del)(cx_value_t* val) {
+_cx_memb(_value_del)(_cx_value_t* 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_t* dst, _cx_value_t* val) {
*cx_keyref(dst) = i_keyfrom(i_keyto(cx_keyref(val)));
cx_MAP_ONLY( dst->second = i_valfrom(i_valto(&val->second)); )
}
cx_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_t _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped);
+ STC_API _cx_result_t _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped);
- STC_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_t
+ _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_t*
+ _cx_memb(_at)(const _cx_self* self, i_keyraw rkey)
+ { _cx_iter_t 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_t
+_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
+ _cx_iter_t it;
+ _cx_memb(_find_it)(self, rkey, &it);
return it;
}
-STC_INLINE cx_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_t
+_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
+ _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey);
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_t
+_cx_memb(_insert)(_cx_self* self, i_key key cx_MAP_ONLY(, i_val mapped)) {
+ _cx_result_t res = _cx_memb(_insert_entry_)(self, i_keyto(&key));
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_t
+_cx_memb(_begin)(const _cx_self* self) {
+ _cx_iter_t it; it._d = self->nodes, it._top = 0;
+ it._tn = (_cx_size_t) _csmap_rep(self)->root;
+ if (it._tn) _cx_memb(_next)(&it);
return it;
}
-STC_INLINE cx_iter_t
-cx_memb(_end)(const Self* self) {
+STC_INLINE _cx_iter_t
+_cx_memb(_end)(const _cx_self* self) {
(void)self;
- return c_make(cx_iter_t){.ref = NULL};
+ return c_make(_cx_iter_t){.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_t
+_cx_memb(_advance)(_cx_iter_t 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_t *) _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_t*
+_cx_memb(_front)(const _cx_self* self) {
+ _cx_node_t *d = self->nodes;
+ _cx_size_t tn = (_cx_size_t) _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_t*
+_cx_memb(_back)(const _cx_self* self) {
+ _cx_node_t *d = self->nodes;
+ _cx_size_t tn = (_cx_size_t) _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_t 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_t));
if (oldcap == 0)
- memset(rep, 0, sizeof(struct csmap_rep) + sizeof(cx_node_t));
+ memset(rep, 0, sizeof(struct csmap_rep) + sizeof(_cx_node_t));
rep->cap = cap;
- self->nodes = (cx_node_t *) rep->nodes;
+ self->nodes = (_cx_node_t *) rep->nodes;
}
}
-STC_DEF cx_size_t
-cx_memb(_node_new_)(Self* self, int level) {
+STC_DEF _cx_size_t
+_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_t* dn = &self->nodes[tn];
dn->link[0] = dn->link[1] = 0; dn->level = level;
- return (cx_size_t) tn;
+ return (_cx_size_t) 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_t
+ _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) {
+ _cx_result_t res = _cx_memb(_insert_entry_)(self, i_keyto(&key));
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_t
+ _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
+ _cx_result_t res = _cx_memb(_insert_entry_)(self, rkey);
if (res.inserted) res.ref->first = i_keyfrom(rkey);
else i_valdel(&res.ref->second);
res.ref->second = i_valfrom(rmapped); return res;
}
)
-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_t*
+_cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter_t* out) {
+ _cx_size_t tn = _csmap_rep(self)->root;
+ _cx_node_t *d = out->_d = self->nodes;
out->_top = 0;
while (tn) {
- int c; cx_rawkey_t raw = i_keyto(cx_keyref(&d[tn].value));
+ int c; _cx_rawkey_t raw = i_keyto(cx_keyref(&d[tn].value));
if ((c = i_cmp(&raw, &rkey)) < 0)
tn = d[tn].link[1];
else if (c > 0)
@@ -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_t
+_cx_memb(_lower_bound)(const _cx_self* self, i_keyraw rkey) {
+ _cx_iter_t it;
+ _cx_memb(_find_it)(self, rkey, &it);
if (!it.ref && it._top) {
- cx_size_t tn = it._st[--it._top];
+ _cx_size_t 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_t *it) {
+ _cx_size_t 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_t
+_cx_memb(_skew_)(_cx_node_t *d, _cx_size_t tn) {
if (tn && d[d[tn].link[0]].level == d[tn].level) {
- cx_size_t tmp = d[tn].link[0];
+ _cx_size_t 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_t
+_cx_memb(_split_)(_cx_node_t *d, _cx_size_t tn) {
if (d[d[d[tn].link[1]].link[1]].level == d[tn].level) {
- cx_size_t tmp = d[tn].link[1];
+ _cx_size_t 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_t
+_cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size_t tn, const _cx_rawkey_t* rkey, _cx_result_t* res) {
+ _cx_size_t up[64], tx = tn;
+ _cx_node_t* d = self->nodes;
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_t
+_cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) {
+ _cx_result_t res = {NULL, false};
+ _cx_size_t tn = _cx_memb(_insert_entry_i_)(self, (_cx_size_t) _csmap_rep(self)->root, &rkey, &res);
_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_t
+_cx_memb(_erase_r_)(_cx_node_t *d, _cx_size_t tn, const _cx_rawkey_t* rkey, int *erased) {
if (tn == 0)
return 0;
i_keyraw raw = i_keyto(cx_keyref(&d[tn].value));
- cx_size_t tx; int c = i_cmp(&raw, rkey);
+ _cx_size_t tx; int c = i_cmp(&raw, rkey);
if (c != 0)
- d[tn].link[c < 0] = cx_memb(_erase_r_)(d, d[tn].link[c < 0], rkey, erased);
+ 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_t) 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_t root = _cx_memb(_erase_r_)(self->nodes, (_cx_size_t) _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_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t it) {
+ _cx_rawkey_t raw = i_keyto(cx_keyref(it.ref)), nxt;
+ _cx_memb(_next)(&it);
if (it.ref) nxt = i_keyto(cx_keyref(it.ref));
- 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_t
+_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t 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_t k1 = *cx_keyref(it1.ref), k2 = *cx_keyref(it2.ref);
+ _cx_rawkey_t r1 = i_keyto(&k1);
for (;;) {
if (memcmp(&k1, &k2, sizeof k1) == 0) return it1;
- cx_memb(_next)(&it1); k1 = *cx_keyref(it1.ref);
- cx_memb(_erase)(self, r1);
- cx_memb(_find_it)(self, (r1 = i_keyto(&k1)), &it1);
+ _cx_memb(_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_t
+_cx_memb(_clone_r_)(_cx_self* self, _cx_node_t* src, _cx_size_t 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_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;
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_t root = _cx_memb(_clone_r_)(&clone, tree.nodes, (_cx_size_t) _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_t* d, _cx_size_t 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_t) _csmap_rep(self)->root);
c_free(_csmap_rep(self));
}
}
diff --git a/include/stc/csptr.h b/include/stc/csptr.h index f8b02c0b..9c946e03 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_t 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_t* 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_t 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_t* 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_t 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..03a9f1d2 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_t;
-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_t *) 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_t *) 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_t *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_t* _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_t* 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_t *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value_t));
}
-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_t* _cx_memb(_push)(_cx_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++;
*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_t* _cx_memb(_emplace)(_cx_self* self, _cx_rawvalue_t 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_t* _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_t *) c_malloc(v.size*sizeof(_cx_value_t)), 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_t 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_t* 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_t _cx_memb(_begin)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data}; }
+STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data + self->size}; }
+STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; }
+STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs)
{ it.ref += offs; return it; }
#include "template.h"
diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 3810e678..0b0313d9 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_t;
+
+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_t* x, const _cx_value_t* y);
+STC_API _cx_iter_t _cx_memb(_find_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw raw);
+STC_API _cx_iter_t _cx_memb(_bsearch_in)(_cx_iter_t it1, _cx_iter_t it2, i_valraw raw);
+STC_API _cx_value_t* _cx_memb(_push_back)(_cx_self* self, i_val value);
+STC_API _cx_iter_t _cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2);
+STC_API _cx_iter_t _cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_value_t* p1, const _cx_value_t* p2, bool clone);
+STC_API _cx_iter_t _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_rawvalue_t* p1, const _cx_rawvalue_t* p2);
+
+STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cvec_rep_(&cx)->size; }
+STC_INLINE size_t _cx_memb(_capacity)(_cx_self cx) { return cvec_rep_(&cx)->cap; }
+STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return !cvec_rep_(&cx)->size; }
+STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); }
+STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value_t* val) { return i_valto(val); }
+STC_INLINE i_val _cx_memb(_value_clone)(_cx_value_t val)
{ 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_t* _cx_memb(_front)(const _cx_self* self) { return self->data; }
+STC_INLINE _cx_value_t* _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_t* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push_back)(self, i_valfrom(raw)); }
+STC_INLINE void _cx_memb(_pop_back)(_cx_self* self)
+ { _cx_value_t* p = &self->data[--cvec_rep_(self)->size]; i_valdel(p); }
+STC_INLINE _cx_iter_t _cx_memb(_begin)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data}; }
+STC_INLINE _cx_iter_t _cx_memb(_end)(const _cx_self* self)
+ { return c_make(_cx_iter_t){self->data + cvec_rep_(self)->size}; }
+STC_INLINE void _cx_memb(_next)(_cx_iter_t* it) { ++it->ref; }
+STC_INLINE _cx_iter_t _cx_memb(_advance)(_cx_iter_t it, intptr_t offs)
{ 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_t 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_t
+_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_t
+_cx_memb(_insert_n)(_cx_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_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_t
+_cx_memb(_insert_at)(_cx_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_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_t
+_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_t
+_cx_memb(_emplace_n)(_cx_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_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_t
+_cx_memb(_emplace_at)(_cx_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_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_t
+_cx_memb(_emplace_range)(_cx_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_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_t
+_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_t
+_cx_memb(_erase_at)(_cx_self* self, _cx_iter_t 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_t
+_cx_memb(_erase_range)(_cx_self* self, _cx_iter_t it1, _cx_iter_t 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_t*
+_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_t
+_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_t*
+_cx_memb(_get)(const _cx_self* self, i_valraw raw) {
+ _cx_iter_t end = _cx_memb(_end)(self);
+ _cx_value_t* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref;
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_t
+_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_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_);
}
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_t *) _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_t *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_t*) 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_t*
+_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_t *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_t*
+_cx_memb(_insert_space_)(_cx_self* self, _cx_value_t* 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_t
+_cx_memb(_insert_range_p)(_cx_self* self, _cx_value_t* pos,
+ const _cx_value_t* p1, const _cx_value_t* p2, bool clone) {
+ pos = _cx_memb(_insert_space_)(self, pos, p2 - p1);
+ _cx_iter_t 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_t
+_cx_memb(_emplace_range_p)(_cx_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};
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_t
+_cx_memb(_erase_range_p)(_cx_self* self, _cx_value_t* p1, _cx_value_t* p2) {
intptr_t len = p2 - p1;
if (len > 0) {
- cx_value_t* p = p1, *end = self->data + cvec_rep_(self)->size;
+ _cx_value_t* 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_t){.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_t
+_cx_memb(_find_in)(_cx_iter_t i1, _cx_iter_t 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_t
+_cx_memb(_bsearch_in)(_cx_iter_t i1, _cx_iter_t i2, i_valraw raw) {
+ _cx_iter_t 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_t* x, const _cx_value_t* y) {
i_valraw rx = i_valto(x);
i_valraw ry = i_valto(y);
return i_cmp(&rx, &ry);
diff --git a/include/stc/template.h b/include/stc/template.h index d72228aa..592b5bad 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_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)
#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
@@ -183,7 +183,6 @@ #undef i_key_csptr
#undef i_val_csptr
#undef i_cnt
-#undef Self
#undef i_template
#endif
|
