summaryrefslogtreecommitdiffhomepage
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
parent3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a (diff)
downloadSTC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.tar.gz
STC-modified-60611de13ad64442287c5a57c7aa874ad45273ab.zip
Generalized i_key_class and i_key_arcbox scheme.
-rw-r--r--include/stc/carc.h42
-rw-r--r--include/stc/cbox.h43
-rw-r--r--include/stc/template.h36
3 files changed, 58 insertions, 63 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
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"
diff --git a/include/stc/template.h b/include/stc/template.h
index 55201526..e7b6dfdc 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -33,7 +33,6 @@
#define _cx_mapped _cx_memb(_mapped)
#define _cx_raw _cx_memb(_raw)
#define _cx_rawkey _cx_memb(_rawkey)
- #define _cx_rawmapped _cx_memb(_rawmapped)
#define _cx_iter _cx_memb(_iter)
#define _cx_result _cx_memb(_result)
#define _cx_node _cx_memb(_node)
@@ -52,7 +51,7 @@
#define _i_expandby 1
#endif
-#if (defined i_valraw) ^ (defined i_valto)
+#if defined i_valraw ^ defined i_valto
#error "both i_valto and i_valraw must be defined, if any"
#elif defined i_valfrom && !defined i_valraw
#error "i_valfrom defined without i_valraw"
@@ -67,7 +66,6 @@
#if !(defined i_key || defined i_key_str || defined i_key_ssv || \
defined i_key_class || defined i_key_arcbox)
- #define _i_key_from_val
#if defined _i_ismap
#error "i_key* must be defined for maps."
#endif
@@ -104,6 +102,13 @@
#endif
#endif
+#if c_option(c_no_cmp)
+ #define _i_no_cmp
+#endif
+#if c_option(c_no_hash)
+ #define _i_no_hash
+#endif
+
#if defined i_key_str
#define i_key_class cstr
#define i_keyraw crawstr
@@ -122,10 +127,11 @@
#endif
#elif defined i_key_arcbox
#define i_key_class i_key_arcbox
- #define i_keyraw c_paste(i_key_arcbox, _value)
- #define i_keyfrom c_paste(i_key_arcbox, _from)
- #define i_keyto(x) *(x)->get
- #define i_eq c_paste(i_key_arcbox, _value_eq)
+ #define i_keyraw c_paste(i_key_arcbox, _raw)
+ #define i_keyfrom c_paste(i_key_arcbox, _new)
+ #if !defined _i_no_hash
+ #define i_eq c_paste(i_key_arcbox, _raw_eq)
+ #endif
#endif
#ifdef i_key_class
@@ -139,10 +145,10 @@
#ifndef i_keydrop
#define i_keydrop c_paste(i_key, _drop)
#endif
- #ifndef i_cmp
+ #if !defined i_cmp && !defined _i_no_cmp
#define i_cmp c_paste(i_keyraw, _cmp)
#endif
- #ifndef i_hash
+ #if !defined i_hash && !defined _i_no_hash
#define i_hash c_paste(i_keyraw, _hash)
#endif
#endif
@@ -160,12 +166,6 @@
#ifndef i_tag
#define i_tag i_key
#endif
-#if c_option(c_no_cmp)
- #define _i_no_cmp
-#endif
-#if c_option(c_no_hash)
- #define _i_no_hash
-#endif
#if c_option(c_no_clone) || (!defined i_keyclone && (defined i_keydrop || defined i_keyraw))
#define _i_no_clone
#endif
@@ -221,9 +221,8 @@
#define i_valto cstr_sv
#elif defined i_val_arcbox
#define i_val_class i_val_arcbox
- #define i_valraw c_paste(i_val_arcbox, _value)
- #define i_valfrom c_paste(i_val_arcbox, _from)
- #define i_valto(x) *(x)->get
+ #define i_valraw c_paste(i_val_arcbox, _raw)
+ #define i_valfrom c_paste(i_val_arcbox, _new)
#endif
#ifdef i_val_class
@@ -321,7 +320,6 @@
#undef _i_expandby
#undef _i_prefix
#undef _i_has_from
-#undef _i_key_from_val
#undef _i_no_cmp
#undef _i_no_clone
#undef _i_no_emplace