diff options
| author | Tyge Løvset <[email protected]> | 2022-10-24 05:42:10 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-10-24 05:42:10 +0200 |
| commit | 60611de13ad64442287c5a57c7aa874ad45273ab (patch) | |
| tree | 5b41b188ec79a924fe8f5154baa09854735c9e2d /include/stc/cbox.h | |
| parent | 3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a (diff) | |
| download | STC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.tar.gz STC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.zip | |
Generalized i_key_class and i_key_arcbox scheme.
Diffstat (limited to 'include/stc/cbox.h')
| -rw-r--r-- | include/stc/cbox.h | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 17ec026f..dde0ed08 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -128,10 +128,9 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) { self->get = p; } -#if !defined _i_no_emplace - STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw) - { return _cx_memb(_from)(i_keyfrom(raw)); } -#endif +STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw) + { return _cx_memb(_from)(i_keyfrom(raw)); } + #if !defined _i_no_clone STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) { if (!other.get) @@ -148,41 +147,41 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) { *self = other; } -STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { +STC_INLINE int _cx_memb(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry) { #if defined _i_no_cmp - return c_default_cmp(&x, &y); + return memcmp(rx, ry, sizeof *rx); #else - _cx_raw rx = i_keyto(x), ry = i_keyto(y); - return i_cmp((&rx), (&ry)); + return i_cmp(rx, ry); #endif } -STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { +STC_INLINE uint64_t _cx_memb(_raw_hash)(const _cx_raw* rx) { #if defined _i_no_hash - return (uintptr_t)x; + return c_default_hash(rx); #else - _cx_raw rx = i_keyto(x); - return i_hash((&rx)); + return i_hash(rx); #endif } -STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { +STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry) { #if defined _i_no_hash - return x == y; + return memcmp(rx, ry, sizeof *rx) == 0; #else - _cx_raw rx = i_keyto(x), ry = i_keyto(y); - return i_eq((&rx), (&ry)); + return i_eq(rx, ry); #endif } STC_INLINE uint64_t _cx_memb(_hash)(const _cx_self* x) - { return _cx_memb(_value_hash)(x->get); } - -STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) - { return _cx_memb(_value_cmp)(x->get, y->get); } + { _cx_raw rx = i_keyto(x->get); return _cx_memb(_raw_hash)(&rx); } -STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) - { return _cx_memb(_value_eq)(x->get, y->get); } +STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) { + _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); + return _cx_memb(_raw_cmp)(&rx, &ry); +} +STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) { + _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); + return _cx_memb(_raw_eq)(&rx, &ry); +} #undef _i_no_hash #include "template.h" |
