diff options
| author | Tyge Lovset <[email protected]> | 2023-03-29 08:45:28 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-03-29 08:45:28 +0200 |
| commit | 97d205f7ba096a9872afbce5e696a8806d7b72d1 (patch) | |
| tree | 27d1b31ed756a8a74157e48a27bcb506d66e097a /include/stc | |
| parent | 4f0ca428e332761666916477b22c3301044a85c6 (diff) | |
| download | STC-modified-97d205f7ba096a9872afbce5e696a8806d7b72d1.tar.gz STC-modified-97d205f7ba096a9872afbce5e696a8806d7b72d1.zip | |
Removed i_less_functor, i_cmp_functor, i_eq_functor and i_hash_functor: not needed.
Simplified cvec_X_eq() and cdeq_X_eq()
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/cdeq.h | 5 | ||||
| -rw-r--r-- | include/stc/cmap.h | 14 | ||||
| -rw-r--r-- | include/stc/cpque.h | 10 | ||||
| -rw-r--r-- | include/stc/csmap.h | 18 | ||||
| -rw-r--r-- | include/stc/cvec.h | 5 |
5 files changed, 17 insertions, 35 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index c4f84a1b..09c0a7f8 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -198,9 +198,8 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw) STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) { if (x->_len != y->_len) return false; - _cx_iter i = _cx_memb(_begin)(x), j = _cx_memb(_begin)(y); - for (; i.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j)) { - const _cx_raw _rx = i_keyto(i.ref), _ry = i_keyto(j.ref); + for (intptr_t i = 0; i < x->_len; ++i) { + const _cx_raw _rx = i_keyto(x->data+i), _ry = i_keyto(y->data+i); if (!(i_eq((&_rx), (&_ry)))) return false; } return true; diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 402038cb..c840523f 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -82,12 +82,6 @@ typedef struct { int64_t idx; uint8_t hx; } chash_bucket_t; #define _i_size i_ssize #endif #include "priv/template.h" -#ifndef i_hash_functor - #define i_hash_functor(self, x) i_hash(x) -#endif -#ifndef i_eq_functor - #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_ssize, _i_MAP_ONLY, _i_SET_ONLY); #endif @@ -371,14 +365,14 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { STC_DEF chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) { - const uint64_t _hash = i_hash_functor(self, rkeyptr); + const uint64_t _hash = i_hash(rkeyptr); int64_t _cap = self->bucket_count; chash_bucket_t b = {c_PASTE(fastrange_,_i_expandby)(_hash, (uint64_t)_cap), (uint8_t)(_hash | 0x80)}; const uint8_t* _hx = self->_hashx; while (_hx[b.idx]) { if (_hx[b.idx] == b.hx) { const _cx_rawkey _raw = i_keyto(_i_keyref(self->table + b.idx)); - if (i_eq_functor(self, (&_raw), rkeyptr)) + if (i_eq((&_raw), rkeyptr)) break; } if (++b.idx == _cap) @@ -469,7 +463,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_ssize)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), (uint64_t)_cap); + k = (i_ssize)c_PASTE(fastrange_,_i_expandby)(i_hash((&_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; } @@ -479,8 +473,6 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { #endif // i_implement #undef i_max_load_factor -#undef i_hash_functor -#undef i_eq_functor #undef _i_size #undef _i_isset #undef _i_ismap diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 4955f2e0..00eaa49e 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -32,9 +32,6 @@ #endif #include "priv/template.h" -#ifndef i_less_functor - #define i_less_functor(self, x, y) i_less(x, y) -#endif #if !c_option(c_is_forward) _cx_deftypes(_c_cpque_types, _cx_self, i_key); #endif @@ -120,8 +117,8 @@ STC_DEF void _cx_memb(_sift_down_)(_cx_self* self, const intptr_t idx, const intptr_t n) { _cx_value t, *arr = self->data - 1; for (intptr_t r = idx, c = idx*2; c <= n; c *= 2) { - c += i_less_functor(self, (&arr[c]), (&arr[c + (c < n)])); - if (!(i_less_functor(self, (&arr[r]), (&arr[c])))) return; + c += i_less((&arr[c]), (&arr[c + (c < n)])); + if (!(i_less((&arr[r]), (&arr[c])))) return; t = arr[r], arr[r] = arr[c], arr[r = c] = t; } } @@ -156,12 +153,11 @@ _cx_memb(_push)(_cx_self* self, _cx_value value) { _cx_memb(_reserve)(self, self->_len*3/2 + 4); _cx_value *arr = self->data - 1; /* base 1 */ intptr_t c = ++self->_len; - for (; c > 1 && (i_less_functor(self, (&arr[c/2]), (&value))); c /= 2) + for (; c > 1 && (i_less((&arr[c/2]), (&value))); c /= 2) arr[c] = arr[c/2]; arr[c] = value; } #endif #define CPQUE_H_INCLUDED -#undef i_less_functor #include "priv/template.h" diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 2b1910e9..50593ba3 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -80,9 +80,6 @@ int main(void) { #define _i_size i_ssize #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_ssize, _i_MAP_ONLY, _i_SET_ONLY); #endif @@ -222,12 +219,12 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { } STC_INLINE bool -_cx_memb(_eq)(const _cx_self* m1, const _cx_self* m2) { - if (_cx_memb(_size)(m1) != _cx_memb(_size)(m2)) return false; - _cx_iter i = _cx_memb(_begin)(m1), j = _cx_memb(_begin)(m2); +_cx_memb(_eq)(const _cx_self* self, const _cx_self* other) { + if (_cx_memb(_size)(self) != _cx_memb(_size)(other)) return false; + _cx_iter i = _cx_memb(_begin)(self), j = _cx_memb(_begin)(other); for (; i.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j)) { const _cx_rawkey _rx = i_keyto(_i_keyref(i.ref)), _ry = i_keyto(_i_keyref(j.ref)); - if ((i_cmp_functor(m1, (&_rx), (&_ry))) != 0) return false; + if (!(i_eq((&_rx), (&_ry)))) return false; } return true; } @@ -357,7 +354,7 @@ _cx_memb(_find_it)(const _cx_self* self, _cx_rawkey rkey, _cx_iter* out) { out->_top = 0; while (tn) { int c; const _cx_rawkey _raw = i_keyto(_i_keyref(&d[tn].value)); - if ((c = i_cmp_functor(self, (&_raw), (&rkey))) < 0) + if ((c = i_cmp((&_raw), (&rkey))) < 0) tn = d[tn].link[1]; else if (c > 0) { out->_st[out->_top++] = tn; tn = d[tn].link[0]; } @@ -425,7 +422,7 @@ _cx_memb(_insert_entry_i_)(_cx_self* self, i_ssize tn, const _cx_rawkey* rkey, _ while (tx) { up[top++] = tx; const _cx_rawkey _raw = i_keyto(_i_keyref(&d[tx].value)); - if (!(c = i_cmp_functor(self, (&_raw), rkey))) + if (!(c = i_cmp((&_raw), rkey))) { _res->ref = &d[tx].value; return tn; } dir = (c < 0); tx = d[tx].link[dir]; @@ -464,7 +461,7 @@ _cx_memb(_erase_r_)(_cx_self *self, i_ssize tn, const _cx_rawkey* rkey, int *era if (tn == 0) return 0; _cx_rawkey raw = i_keyto(_i_keyref(&d[tn].value)); - i_ssize tx; int c = i_cmp_functor(self, (&raw), rkey); + i_ssize tx; int c = i_cmp((&raw), rkey); if (c != 0) d[tn].link[c < 0] = _cx_memb(_erase_r_)(self, d[tn].link[c < 0], rkey, erased); else { @@ -594,7 +591,6 @@ _cx_memb(_drop)(_cx_self* self) { } #endif // i_implement -#undef i_cmp_functor #undef _i_size #undef _i_isset #undef _i_ismap diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 91cdb25c..8f35e5fc 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -236,9 +236,8 @@ _cx_memb(_get_mut)(const _cx_self* self, _cx_raw raw) STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) { if (x->_len != y->_len) return false; - _cx_iter i = _cx_memb(_begin)(x), j = _cx_memb(_begin)(y); - for (; i.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j)) { - const _cx_raw _rx = i_keyto(i.ref), _ry = i_keyto(j.ref); + for (intptr_t i = 0; i < x->_len; ++i) { + const _cx_raw _rx = i_keyto(x->data+i), _ry = i_keyto(y->data+i); if (!(i_eq((&_rx), (&_ry)))) return false; } return true; |
