diff options
| author | Tyge Løvset <[email protected]> | 2023-02-24 13:17:12 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-24 13:17:12 +0100 |
| commit | 560b1f4e4bf61ca01c27f1895b5138f6004eb717 (patch) | |
| tree | b8f0c4dba891b49c089a9a1916b75a002818f697 /include | |
| parent | 5c66bfeb3bf39774ebd14444bd23eaa2c17447d0 (diff) | |
| download | STC-modified-560b1f4e4bf61ca01c27f1895b5138f6004eb717.tar.gz STC-modified-560b1f4e4bf61ca01c27f1895b5138f6004eb717.zip | |
Added eq function to cdeq, clist, cmap, csmap, and fixed cmap eq.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cdeq.h | 10 | ||||
| -rw-r--r-- | include/stc/clist.h | 10 | ||||
| -rw-r--r-- | include/stc/cmap.h | 12 | ||||
| -rw-r--r-- | include/stc/csmap.h | 51 | ||||
| -rw-r--r-- | include/stc/cvec.h | 9 |
5 files changed, 65 insertions, 27 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 3a21097d..d435d1e3 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -195,6 +195,16 @@ STC_INLINE _cx_value* _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw) { return (_cx_value *) _cx_memb(_get)(self, raw); } +STC_INLINE bool +_cx_memb(_eq)(const _cx_self* v1, const _cx_self* v2) { + if (v1->_len != v2->_len) return false; + _cx_iter i1 = _cx_memb(_begin)(v1), i2 = _cx_memb(_begin)(v2); + for (; i1.ref && i2.ref; _cx_memb(_next)(&i1), _cx_memb(_next)(&i2)) { + const _cx_raw rx = i_keyto(i1.ref), ry = i_keyto(i2.ref); + if (!(i_eq((&rx), (&ry)))) return false; + } + return true; +} #endif #ifndef i_no_cmp diff --git a/include/stc/clist.h b/include/stc/clist.h index 6fd7252d..1650714b 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -205,6 +205,16 @@ STC_INLINE _cx_value* _cx_memb(_get_mut)(_cx_self* self, _cx_raw val) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val).ref; } + +STC_INLINE bool +_cx_memb(_eq)(const _cx_self* v1, const _cx_self* v2) { + _cx_iter i1 = _cx_memb(_begin)(v1), i2 = _cx_memb(_begin)(v2); + for (; i1.ref && i2.ref; _cx_memb(_next)(&i1), _cx_memb(_next)(&i2)) { + const _cx_raw rx = i_keyto(i1.ref), ry = i_keyto(i2.ref); + if (!(i_eq((&rx), (&ry)))) return false; + } + return !(i1.ref || i2.ref); +} #endif #ifndef i_no_cmp diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 83beb92c..bc3b5546 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -115,7 +115,7 @@ STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawke STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey); STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); -STC_INLINE _cx_self _cx_memb(_init)(void) { return c_LITERAL(_cx_self){0}; } +STC_INLINE _cx_self _cx_memb(_init)(void) { _cx_self map = {0}; return map; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); } STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; } @@ -282,6 +282,16 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { return it; } +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; + for (_cx_iter i = _cx_memb(_begin)(m1); i.ref; _cx_memb(_next)(&i)) { + const _cx_rawkey _raw = i_keyto(_i_keyref(i.ref)); + if (!_cx_memb(_contains)(m2, _raw)) return false; + } + return true; +} + /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/csmap.h b/include/stc/csmap.h index bca0343c..e908f157 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -109,7 +109,6 @@ STC_API _cx_result _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MA #if !defined i_no_clone STC_API _cx_self _cx_memb(_clone)(_cx_self tree); #endif // !i_no_clone -STC_API _cx_self _cx_memb(_init)(void); STC_API _cx_result _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)); STC_API _cx_result _cx_memb(_push)(_cx_self* self, _cx_value _val); STC_API void _cx_memb(_drop)(_cx_self* self); @@ -123,6 +122,7 @@ STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); STC_API void _cx_memb(_next)(_cx_iter* it); +STC_INLINE _cx_self _cx_memb(_init)(void) { _cx_self tree = {0}; return tree; } STC_INLINE bool _cx_memb(_empty)(const _cx_self* cx) { return cx->size == 0; } STC_INLINE _i_size _cx_memb(_size)(const _cx_self* cx) { return cx->size; } STC_INLINE _i_size _cx_memb(_capacity)(const _cx_self* cx) { return cx->cap; } @@ -221,15 +221,36 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { return it; } -/* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) +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 i1 = _cx_memb(_begin)(m1), i2 = _cx_memb(_begin)(m2); + for (; i1.ref && i2.ref; _cx_memb(_next)(&i1), _cx_memb(_next)(&i2)) { + const _cx_rawkey _rx = i_keyto(_i_keyref(i1.ref)), _ry = i_keyto(_i_keyref(i2.ref)); + if ((i_cmp_functor(m1, (&_rx), (&_ry))) != 0) return false; + } + return true; +} -STC_DEF _cx_self -_cx_memb(_init)(void) { - _cx_self tree = {0}; - return tree; +STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, _i_size n) { + while (n--) +#if defined _i_isset && defined i_no_emplace + _cx_memb(_insert)(self, *raw++); +#elif defined _i_isset + _cx_memb(_emplace)(self, *raw++); +#elif defined i_no_emplace + _cx_memb(_insert_or_assign)(self, raw->first, raw->second), ++raw; +#else + _cx_memb(_emplace_or_assign)(self, raw->first, raw->second), ++raw; +#endif } +STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, _i_size n) + { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } + +/* -------------------------- IMPLEMENTATION ------------------------- */ +#if defined(i_implement) + STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const _i_size cap) { if (cap <= self->cap) @@ -300,22 +321,6 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } -STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, _i_size n) { - while (n--) -#if defined _i_isset && defined i_no_emplace - _cx_memb(_insert)(self, *raw++); -#elif defined _i_isset - _cx_memb(_emplace)(self, *raw++); -#elif defined i_no_emplace - _cx_memb(_insert_or_assign)(self, raw->first, raw->second), ++raw; -#else - _cx_memb(_emplace_or_assign)(self, raw->first, raw->second), ++raw; -#endif -} - -STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, _i_size n) - { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } - #ifndef _i_isset STC_DEF _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped) { diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 130644cf..96ad1ecb 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -235,10 +235,13 @@ _cx_memb(_get_mut)(const _cx_self* self, _cx_raw raw) STC_INLINE bool _cx_memb(_eq)(const _cx_self* v1, const _cx_self* v2) { + if (v1->_len != v2->_len) return false; _cx_iter i1 = _cx_memb(_begin)(v1), i2 = _cx_memb(_begin)(v2); - for (; i1.ref && i2.ref; _cx_memb(_next)(&i1), _cx_memb(_next)(&i2)) - if (!i_eq(i1.ref, i2.ref)) return false; - return !(i1.ref || i2.ref); + for (; i1.ref && i2.ref; _cx_memb(_next)(&i1), _cx_memb(_next)(&i2)) { + const _cx_raw rx = i_keyto(i1.ref), ry = i_keyto(i2.ref); + if (!(i_eq((&rx), (&ry)))) return false; + } + return true; } #endif #ifndef i_no_cmp |
