diff options
| author | Tyge Løvset <[email protected]> | 2023-02-24 17:15:24 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-24 17:15:24 +0100 |
| commit | 1a2143fbbda0805fdc9d3862e9c45cb0fc6a336f (patch) | |
| tree | 7c6a139207c7efaec414ad85dd4ea58a6f3b19b5 /include | |
| parent | dde5e3465c4198841fdba32dfaf2220c87bc6a94 (diff) | |
| download | STC-modified-1a2143fbbda0805fdc9d3862e9c45cb0fc6a336f.tar.gz STC-modified-1a2143fbbda0805fdc9d3862e9c45cb0fc6a336f.zip | |
Added eq function to cspan.
Final cleanup normalized var naming.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cdeq.h | 12 | ||||
| -rw-r--r-- | include/stc/clist.h | 12 | ||||
| -rw-r--r-- | include/stc/csmap.h | 6 | ||||
| -rw-r--r-- | include/stc/cspan.h | 15 | ||||
| -rw-r--r-- | include/stc/cvec.h | 12 |
5 files changed, 35 insertions, 22 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index d435d1e3..c4f84a1b 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -196,12 +196,12 @@ _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; +_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); + if (!(i_eq((&_rx), (&_ry)))) return false; } return true; } diff --git a/include/stc/clist.h b/include/stc/clist.h index 1650714b..f8a21f40 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -207,13 +207,13 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw val) { } 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; +_cx_memb(_eq)(const _cx_self* x, const _cx_self* y) { + _cx_iter i = _cx_memb(_begin)(x), j = _cx_memb(_begin)(y); + for (; i.ref && j.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j)) { + const _cx_raw _rx = i_keyto(i.ref), _ry = i_keyto(j.ref); + if (!(i_eq((&_rx), (&_ry)))) return false; } - return !(i1.ref || i2.ref); + return !(i.ref || j.ref); } #endif #ifndef i_no_cmp diff --git a/include/stc/csmap.h b/include/stc/csmap.h index e908f157..0f72ca2d 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -224,9 +224,9 @@ _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 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)); + _cx_iter i = _cx_memb(_begin)(m1), j = _cx_memb(_begin)(m2); + 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; } return true; diff --git a/include/stc/cspan.h b/include/stc/cspan.h index bbaaf6c0..506702b3 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -61,14 +61,20 @@ int demo2() { #include "ccommon.h" #define using_cspan(...) c_MACRO_OVERLOAD(using_cspan, __VA_ARGS__) -#define using_cspan_2(Self, T) using_cspan_3(Self, T, 1) +#define using_cspan_2(Self, T) \ + using_cspan_3(Self, T, 1) + #define using_cspan_3(Self, T, RANK) \ + using_cspan_4(Self, T, RANK, c_default_eq) + +#define using_cspan_4(Self, T, RANK, i_eq) \ typedef T Self##_value; typedef T Self##_raw; \ typedef struct { \ Self##_value *data; \ int32_t shape[RANK]; \ cspan_idx##RANK stride; \ } Self; \ + \ typedef struct { Self##_value *ref; int32_t pos[RANK]; const Self *_s; } Self##_iter; \ \ STC_INLINE Self Self##_from_n(Self##_raw* raw, const intptr_t n) { \ @@ -93,6 +99,13 @@ int demo2() { it->ref += _cspan_next##RANK(RANK, it->pos, it->_s->shape, it->_s->stride.d); \ if (it->pos[0] == it->_s->shape[0]) it->ref = NULL; \ } \ + STC_INLINE bool Self##_eq(const Self* x, const Self* y) { \ + if (memcmp(x->shape, y->shape, sizeof x->shape)) return false; \ + Self##_iter i = Self##_begin(x), j = Self##_begin(y); \ + for (; i.ref; Self##_next(&i), Self##_next(&j)) \ + if (!(i_eq(i.ref, j.ref))) return false; \ + return true; \ + } \ struct stc_nostruct #define using_cspan2(Self, T) using_cspan_3(Self, T, 1); using_cspan_3(Self##2, T, 2) diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 96ad1ecb..91cdb25c 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -234,12 +234,12 @@ _cx_memb(_get_mut)(const _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; +_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); + if (!(i_eq((&_rx), (&_ry)))) return false; } return true; } |
