diff options
| author | Tyge Løvset <[email protected]> | 2023-02-11 23:55:24 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-11 23:55:24 +0100 |
| commit | e730c593429bdd5a73da5b02e7559b1f0fd21e19 (patch) | |
| tree | 3613172419e4c4821e45f41c15e8d16423b5e6da /include | |
| parent | 921c06f1b46d449668881ebd1c35a83dc32ad38a (diff) | |
| download | STC-modified-e730c593429bdd5a73da5b02e7559b1f0fd21e19.tar.gz STC-modified-e730c593429bdd5a73da5b02e7559b1f0fd21e19.zip | |
Some more docs. Renamed (half-)internal template parameter i_size => i_ssize. Updated external cpp maps for benchmarks.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cmap.h | 22 | ||||
| -rw-r--r-- | include/stc/csmap.h | 64 | ||||
| -rw-r--r-- | include/stc/forward.h | 10 | ||||
| -rw-r--r-- | include/stc/priv/template.h | 6 |
4 files changed, 51 insertions, 51 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 0553823b..799df1ec 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -73,8 +73,8 @@ typedef struct { int64_t idx; uint8_t hx; } chash_bucket_t; #ifndef i_max_load_factor #define i_max_load_factor 0.85f #endif -#ifndef i_size - #define i_size int32_t +#ifndef i_ssize + #define i_ssize int32_t #define _i_expandby 1 #else #define _i_expandby 2 @@ -87,7 +87,7 @@ typedef struct { int64_t idx; uint8_t hx; } chash_bucket_t; #define i_eq_functor(self, x, y) i_eq(x, y) #endif #if !c_option(c_is_forward) - _cx_deftypes(_c_chash_types, _cx_self, i_key, i_val, i_size, _i_MAP_ONLY, _i_SET_ONLY); + _cx_deftypes(_c_chash_types, _cx_self, i_key, i_val, i_ssize, _i_MAP_ONLY, _i_SET_ONLY); #endif _i_MAP_ONLY( struct _cx_value { @@ -378,7 +378,7 @@ _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) { STC_DEF _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey) { _cx_result res = {NULL}; - if (self->size + 2 > (i_size)((float)self->bucket_count * (i_max_load_factor))) + if (self->size + 2 > (i_ssize)((float)self->bucket_count * (i_max_load_factor))) if (!_cx_memb(_reserve)(self, self->size*3/2)) return res; @@ -412,12 +412,12 @@ _cx_memb(_clone)(_cx_self m) { STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const int64_t newcap) { - const i_size _oldbuckets = self->bucket_count, _newcap = (i_size)newcap; + const i_ssize _oldbuckets = self->bucket_count, _newcap = (i_ssize)newcap; if (_newcap != self->size && _newcap <= _oldbuckets) return true; - i_size _nbuckets = (i_size)((float)_newcap / (i_max_load_factor)) + 4; + i_ssize _nbuckets = (i_ssize)((float)_newcap / (i_max_load_factor)) + 4; #if _i_expandby == 2 - _nbuckets = (i_size)next_power_of_2(_nbuckets); + _nbuckets = (i_ssize)next_power_of_2(_nbuckets); #else _nbuckets |= 1; #endif @@ -431,7 +431,7 @@ _cx_memb(_reserve)(_cx_self* self, const int64_t newcap) { m._hashx[_nbuckets] = 0xff; const _cx_value* e = self->table; const uint8_t* h = self->_hashx; - for (i_size i = 0; i < _oldbuckets; ++i, ++e) if (*h++) { + for (i_ssize i = 0; i < _oldbuckets; ++i, ++e) if (*h++) { _cx_rawkey r = i_keyto(_i_keyref(e)); chash_bucket_t b = _cx_memb(_bucket_)(&m, &r); m.table[b.idx] = *e; @@ -446,8 +446,8 @@ _cx_memb(_reserve)(_cx_self* self, const int64_t newcap) { STC_DEF void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { - i_size i = (i_size)(_val - self->table), j = i, k; - const i_size _cap = self->bucket_count; + i_ssize i = (i_ssize)(_val - self->table), j = i, k; + const i_ssize _cap = self->bucket_count; _cx_value* _slot = self->table; uint8_t* _hashx = self->_hashx; _cx_memb(_value_drop)(_val); @@ -457,7 +457,7 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { if (! _hashx[j]) break; const _cx_rawkey _raw = i_keyto(_i_keyref(_slot + j)); - k = (i_size)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), (uint64_t)_cap); + k = (i_ssize)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), (uint64_t)_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/csmap.h b/include/stc/csmap.h index 6a359fbb..4344ceb9 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -73,15 +73,15 @@ int main(void) { #define _i_SET_ONLY c_false #define _i_keyref(vp) (&(vp)->first) #endif -#ifndef i_size - #define i_size int32_t +#ifndef i_ssize + #define i_ssize int32_t #endif #include "priv/template.h" #ifndef i_cmp_functor #define i_cmp_functor(self, x, y) i_cmp(x, y) #endif #if !c_option(c_is_forward) - _cx_deftypes(_c_aatree_types, _cx_self, i_key, i_val, i_size, _i_MAP_ONLY, _i_SET_ONLY); + _cx_deftypes(_c_aatree_types, _cx_self, i_key, i_val, i_ssize, _i_MAP_ONLY, _i_SET_ONLY); #endif _i_MAP_ONLY( struct _cx_value { @@ -89,7 +89,7 @@ _i_MAP_ONLY( struct _cx_value { _cx_mapped second; }; ) struct _cx_node { - i_size link[2]; + i_ssize link[2]; int8_t level; _cx_value value; }; @@ -229,21 +229,21 @@ _cx_memb(_init)(void) { STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const int64_t cap) { - if ((i_size)cap <= self->cap) + if ((i_ssize)cap <= self->cap) return false; _cx_node* nodes = (_cx_node*)i_realloc(self->nodes, (cap + 1)*c_sizeof(_cx_node)); if (!nodes) return false; nodes[0] = c_LITERAL(_cx_node){{0, 0}, 0}; self->nodes = nodes; - self->cap = (i_size)cap; + self->cap = (i_ssize)cap; return true; } STC_DEF _cx_value* _cx_memb(_front)(const _cx_self* self) { _cx_node *d = self->nodes; - i_size tn = self->root; + i_ssize tn = self->root; while (d[tn].link[0]) tn = d[tn].link[0]; return &d[tn].value; @@ -252,15 +252,15 @@ _cx_memb(_front)(const _cx_self* self) { STC_DEF _cx_value* _cx_memb(_back)(const _cx_self* self) { _cx_node *d = self->nodes; - i_size tn = self->root; + i_ssize tn = self->root; while (d[tn].link[1]) tn = d[tn].link[1]; return &d[tn].value; } -static i_size +static i_ssize _cx_memb(_new_node_)(_cx_self* self, int level) { - i_size tn; + i_ssize tn; if (self->disp) { tn = self->disp; self->disp = self->nodes[tn].link[1]; @@ -344,7 +344,7 @@ STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, int64_t n) STC_DEF _cx_value* _cx_memb(_find_it)(const _cx_self* self, _cx_rawkey rkey, _cx_iter* out) { - i_size tn = self->root; + i_ssize tn = self->root; _cx_node *d = out->_d = self->nodes; out->_top = 0; while (tn) { @@ -364,7 +364,7 @@ _cx_memb(_lower_bound)(const _cx_self* self, _cx_rawkey rkey) { _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); if (!it.ref && it._top) { - i_size tn = it._st[--it._top]; + i_ssize tn = it._st[--it._top]; it._tn = it._d[tn].link[1]; it.ref = &it._d[tn].value; } @@ -373,7 +373,7 @@ _cx_memb(_lower_bound)(const _cx_self* self, _cx_rawkey rkey) { STC_DEF void _cx_memb(_next)(_cx_iter *it) { - i_size tn = it->_tn; + i_ssize tn = it->_tn; if (it->_top || tn) { while (tn) { it->_st[it->_top++] = tn; @@ -386,10 +386,10 @@ _cx_memb(_next)(_cx_iter *it) { it->ref = NULL; } -STC_DEF i_size -_cx_memb(_skew_)(_cx_node *d, i_size tn) { +STC_DEF i_ssize +_cx_memb(_skew_)(_cx_node *d, i_ssize tn) { if (tn && d[d[tn].link[0]].level == d[tn].level) { - i_size tmp = d[tn].link[0]; + i_ssize tmp = d[tn].link[0]; d[tn].link[0] = d[tmp].link[1]; d[tmp].link[1] = tn; tn = tmp; @@ -397,10 +397,10 @@ _cx_memb(_skew_)(_cx_node *d, i_size tn) { return tn; } -STC_DEF i_size -_cx_memb(_split_)(_cx_node *d, i_size tn) { +STC_DEF i_ssize +_cx_memb(_split_)(_cx_node *d, i_ssize tn) { if (d[d[d[tn].link[1]].link[1]].level == d[tn].level) { - i_size tmp = d[tn].link[1]; + i_ssize tmp = d[tn].link[1]; d[tn].link[1] = d[tmp].link[0]; d[tmp].link[0] = tn; tn = tmp; @@ -409,9 +409,9 @@ _cx_memb(_split_)(_cx_node *d, i_size tn) { return tn; } -static i_size -_cx_memb(_insert_entry_i_)(_cx_self* self, i_size tn, const _cx_rawkey* rkey, _cx_result* _res) { - i_size up[64], tx = tn; +static i_ssize +_cx_memb(_insert_entry_i_)(_cx_self* self, i_ssize tn, const _cx_rawkey* rkey, _cx_result* _res) { + i_ssize up[64], tx = tn; _cx_node* d = self->nodes; int c, top = 0, dir = 0; while (tx) { @@ -444,19 +444,19 @@ _cx_memb(_insert_entry_i_)(_cx_self* self, i_size tn, const _cx_rawkey* rkey, _c static _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey) { _cx_result res = {NULL}; - i_size tn = _cx_memb(_insert_entry_i_)(self, self->root, &rkey, &res); + i_ssize tn = _cx_memb(_insert_entry_i_)(self, self->root, &rkey, &res); self->root = tn; self->size += res.inserted; return res; } -static i_size -_cx_memb(_erase_r_)(_cx_self *self, i_size tn, const _cx_rawkey* rkey, int *erased) { +static i_ssize +_cx_memb(_erase_r_)(_cx_self *self, i_ssize tn, const _cx_rawkey* rkey, int *erased) { _cx_node *d = self->nodes; if (tn == 0) return 0; _cx_rawkey raw = i_keyto(_i_keyref(&d[tn].value)); - i_size tx; int c = i_cmp_functor(self, (&raw), rkey); + i_ssize tx; int c = i_cmp_functor(self, (&raw), rkey); if (c != 0) d[tn].link[c < 0] = _cx_memb(_erase_r_)(self, d[tn].link[c < 0], rkey, erased); else { @@ -493,7 +493,7 @@ _cx_memb(_erase_r_)(_cx_self *self, i_size tn, const _cx_rawkey* rkey, int *eras STC_DEF int _cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) { int erased = 0; - i_size root = _cx_memb(_erase_r_)(self, self->root, &rkey, &erased); + i_ssize root = _cx_memb(_erase_r_)(self, self->root, &rkey, &erased); if (!erased) return 0; self->root = root; @@ -535,11 +535,11 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { } #if !defined i_no_clone -static i_size -_cx_memb(_clone_r_)(_cx_self* self, _cx_node* src, i_size sn) { +static i_ssize +_cx_memb(_clone_r_)(_cx_self* self, _cx_node* src, i_ssize sn) { if (sn == 0) return 0; - i_size tx, tn = _cx_memb(_new_node_)(self, src[sn].level); + i_ssize tx, tn = _cx_memb(_new_node_)(self, src[sn].level); self->nodes[tn].value = _cx_memb(_value_clone)(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; @@ -549,7 +549,7 @@ _cx_memb(_clone_r_)(_cx_self* self, _cx_node* src, i_size sn) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self tree) { _cx_self clone = _cx_memb(_with_capacity)(tree.size); - i_size root = _cx_memb(_clone_r_)(&clone, tree.nodes, tree.root); + i_ssize root = _cx_memb(_clone_r_)(&clone, tree.nodes, tree.root); clone.root = root; clone.size = tree.size; return clone; @@ -569,7 +569,7 @@ _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MAP_ONLY(, i_valraw rmappe #endif // i_no_emplace static void -_cx_memb(_drop_r_)(_cx_node* d, i_size tn) { +_cx_memb(_drop_r_)(_cx_node* d, i_ssize tn) { if (tn) { _cx_memb(_drop_r_)(d, d[tn].link[0]); _cx_memb(_drop_r_)(d, d[tn].link[1]); diff --git a/include/stc/forward.h b/include/stc/forward.h index 64d4370a..00c531fe 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -106,7 +106,7 @@ typedef union { #define _c_chash_types(SELF, KEY, VAL, SZ, MAP_ONLY, SET_ONLY) \ typedef KEY SELF##_key; \ typedef VAL SELF##_mapped; \ - typedef SZ SELF##_sizet; \ + typedef SZ SELF##_ssize; \ \ typedef SET_ONLY( SELF##_key ) \ MAP_ONLY( struct SELF##_value ) \ @@ -125,13 +125,13 @@ typedef union { typedef struct SELF { \ SELF##_value* table; \ uint8_t* _hashx; \ - SELF##_sizet size, bucket_count; \ + SELF##_ssize size, bucket_count; \ } SELF #define _c_aatree_types(SELF, KEY, VAL, SZ, MAP_ONLY, SET_ONLY) \ typedef KEY SELF##_key; \ typedef VAL SELF##_mapped; \ - typedef SZ SELF##_sizet; \ + typedef SZ SELF##_ssize; \ typedef struct SELF##_node SELF##_node; \ \ typedef SET_ONLY( SELF##_key ) \ @@ -147,12 +147,12 @@ typedef union { SELF##_value *ref; \ SELF##_node *_d; \ int _top; \ - SELF##_sizet _tn, _st[36]; \ + SELF##_ssize _tn, _st[36]; \ } SELF##_iter; \ \ typedef struct SELF { \ SELF##_node *nodes; \ - SELF##_sizet root, disp, head, size, cap; \ + SELF##_ssize root, disp, head, size, cap; \ } SELF #define _c_cstack_fixed(SELF, VAL, CAP) \ diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h index dd770839..3bef2c9a 100644 --- a/include/stc/priv/template.h +++ b/include/stc/priv/template.h @@ -44,8 +44,8 @@ #define _i_prefix #endif -#ifndef i_size - #define i_size intptr_t +#ifndef i_ssize + #define i_ssize intptr_t #endif #ifndef i_allocator @@ -298,7 +298,7 @@ #undef i_hash #undef i_rawclass #undef i_capacity -#undef i_size +#undef i_ssize #undef i_val #undef i_val_str |
