summaryrefslogtreecommitdiffhomepage
path: root/include/stc/carc.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-10-24 05:42:10 +0200
committerTyge Løvset <[email protected]>2022-10-24 05:42:10 +0200
commit60611de13ad64442287c5a57c7aa874ad45273ab (patch)
tree5b41b188ec79a924fe8f5154baa09854735c9e2d /include/stc/carc.h
parent3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a (diff)
downloadSTC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.tar.gz
STC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.zip
Generalized i_key_class and i_key_arcbox scheme.
Diffstat (limited to 'include/stc/carc.h')
-rw-r--r--include/stc/carc.h42
1 files changed, 20 insertions, 22 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 7209eb28..882acb6b 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -149,10 +149,8 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
*self = _cx_memb(_from_ptr)(p);
}
-#if !defined _i_no_emplace
- STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw)
- { return _cx_memb(_from)(i_keyfrom(raw)); }
-#endif // !_i_no_emplace
+STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw)
+ { return _cx_memb(_from)(i_keyfrom(raw)); }
// does not use i_keyclone, so OK to always define.
STC_INLINE _cx_self _cx_memb(_clone)(_cx_self ptr) {
@@ -174,42 +172,42 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self ptr) {
*self = ptr;
}
-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); }
+ { _cx_raw rx = i_keyto(x->get); return _cx_memb(_raw_hash)(&rx); }
-STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y)
- { return _cx_memb(_value_cmp)(x->get, y->get); }
-
-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_atomic_inc
#undef _i_atomic_dec_and_test
#undef _i_no_hash