summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-16 07:32:16 +0100
committerTyge Løvset <[email protected]>2021-12-16 07:32:16 +0100
commit183a89859ba9914ee0546e4482b40be199e52292 (patch)
treec199c6f1f5dead5e349f2b00f70bb33989ee520e /include/stc
parent7f264be520123c71211967a56d2826d272694edf (diff)
downloadSTC-modified-183a89859ba9914ee0546e4482b40be199e52292.tar.gz
STC-modified-183a89859ba9914ee0546e4482b40be199e52292.zip
Changed default comparison of csbox and csptr objects to comparing addresses to containing objects. If i_cmp is defined, it is used instead.
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/cbox.h6
-rw-r--r--include/stc/csptr.h6
-rw-r--r--include/stc/template.h37
3 files changed, 26 insertions, 23 deletions
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 445057dd..89bd272e 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -151,9 +151,9 @@ _cx_memb(_take)(_cx_self* self, _cx_self other) {
STC_INLINE uint64_t
_cx_memb(_hash)(const _cx_self* self, size_t n) {
- #if c_option(c_no_compare) && SIZE_MAX >> 32
+ #if (c_option(c_no_compare) || defined _i_default_compare) && SIZE_MAX >> 32
return c_hash64(&self->get, 8);
- #elif c_option(c_no_compare)
+ #elif (c_option(c_no_compare) || defined _i_default_compare)
return c_hash32(&self->get, 4);
#else
i_valraw raw = i_valto(self->get);
@@ -163,7 +163,7 @@ _cx_memb(_hash)(const _cx_self* self, size_t n) {
STC_INLINE int
_cx_memb(_compare)(const _cx_self* x, const _cx_self* y) {
- #if c_option(c_no_compare)
+ #if (c_option(c_no_compare) || defined _i_default_compare)
return (int)(x->get - y->get);
#else
i_valraw rx = i_valto(x->get);
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index 06790e01..4753ef12 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -185,9 +185,9 @@ _cx_memb(_take)(_cx_self* self, _cx_self ptr) {
STC_INLINE uint64_t
_cx_memb(_hash)(const _cx_self* self, size_t n) {
- #if c_option(c_no_compare) && SIZE_MAX >> 32
+ #if (c_option(c_no_compare) || defined _i_default_compare) && SIZE_MAX >> 32
return c_hash64(&self->get, 8);
- #elif c_option(c_no_compare)
+ #elif (c_option(c_no_compare) || defined _i_default_compare)
return c_hash32(&self->get, 4);
#else
i_valraw raw = i_valto(self->get);
@@ -197,7 +197,7 @@ _cx_memb(_hash)(const _cx_self* self, size_t n) {
STC_INLINE int
_cx_memb(_compare)(const _cx_self* x, const _cx_self* y) {
- #if c_option(c_no_compare)
+ #if (c_option(c_no_compare) || defined _i_default_compare)
return (int)(x->get - y->get);
#else
i_valraw rx = i_valto(x->get);
diff --git a/include/stc/template.h b/include/stc/template.h
index e788d4eb..85c4a940 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -102,13 +102,29 @@
#endif
#endif
+/* Resolve i_del and i_from here */
+#if defined i_del && defined i_isset
+ #define i_keydel i_del
+#elif defined i_del && !defined i_key
+ #define i_valdel i_del
+#elif defined i_del
+ #error "i_del not supported for maps, define i_keydel / i_valdel instead."
+#endif
+#if defined i_from && defined i_isset
+ #define i_keyfrom i_from
+#elif defined i_from && !defined i_key
+ #define i_valfrom i_from
+#elif defined i_from
+ #error "i_from not supported for maps, define i_keyfrom / i_valfrom instead."
+#endif
+
#if defined i_val_ref
#define i_val i_val_ref
#define i_valfrom c_PASTE(i_val, _clone)
#if !defined i_cmp && !defined i_key
#define i_cmp c_PASTE(i_val, _compare)
#endif
- #if !defined i_valdel && !defined i_del
+ #if !defined i_valdel
#define i_valdel c_PASTE(i_val, _del)
#endif
@@ -124,26 +140,11 @@
#if !defined i_cmp && !defined i_key
#define i_cmp c_rawstr_compare
#endif
- #if !defined i_valdel && !defined i_del
+ #if !defined i_valdel
#define i_valdel cstr_del
#endif
#endif
-#if defined i_del && defined i_isset
- #define i_keydel i_del
-#elif defined i_del && !defined i_key
- #define i_valdel i_del
-#elif defined i_del
- #error "i_del not supported for maps, define i_keydel / i_valdel instead."
-#endif
-#if defined i_from && defined i_isset
- #define i_keyfrom i_from
-#elif defined i_from && !defined i_key
- #define i_valfrom i_from
-#elif defined i_from
- #error "i_from not supported for maps, define i_keyfrom / i_valfrom instead."
-#endif
-
#ifdef i_key
#ifdef _i_isset
#define i_val i_key
@@ -190,6 +191,7 @@
#define i_valdel c_default_del
#endif
#ifndef i_cmp
+ #define _i_default_compare
#define i_cmp c_default_compare
#endif
#ifndef i_hash
@@ -225,6 +227,7 @@
#undef i_keyto
#undef _i_prefix
+#undef _i_default_compare
#undef _i_has_internal_clone
#undef _i_template
#endif