summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-08-10 21:17:48 +0200
committerTyge Løvset <[email protected]>2023-08-10 21:17:48 +0200
commitbe5651c9fc3d3ecd2d9d24e6e4763260ef86de41 (patch)
treec9e9f5bc6814716b4faac75833cc1ecc1371c8c5 /include
parentc27c266b6c4ae0e5e535b18c3790ee97416412b9 (diff)
downloadSTC-modified-be5651c9fc3d3ecd2d9d24e6e4763260ef86de41.tar.gz
STC-modified-be5651c9fc3d3ecd2d9d24e6e4763260ef86de41.zip
Update template.h - also renamed i_cmp_native => i_use_cmp
Diffstat (limited to 'include')
-rw-r--r--include/stc/carc.h64
-rw-r--r--include/stc/cbox.h65
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/priv/template.h29
-rw-r--r--include/stc/priv/template2.h2
5 files changed, 71 insertions, 91 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 9ba2ddd1..e1dfe14e 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -176,50 +176,40 @@ STC_INLINE void _cx_MEMB(_assign)(_cx_Self* self, _cx_Self ptr) {
*self = ptr;
}
-#if defined _i_has_cmp
+#if defined i_use_cmp
STC_INLINE int _cx_MEMB(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_cmp(rx, ry); }
- STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
- _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
- return i_cmp((&rx), (&ry));
- }
-#else
- STC_INLINE int _cx_MEMB(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry)
- { return c_default_cmp(&rx, &ry); }
-
- STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
- return c_default_cmp(&self->get, &other->get);
- }
-#endif
-#if defined _i_has_eq || defined _i_has_cmp
STC_INLINE bool _cx_MEMB(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_eq(rx, ry); }
-
- STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
- _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
- return i_eq((&rx), (&ry));
- }
-#else
- STC_INLINE bool _cx_MEMB(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
- { return rx == ry; }
-
- STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
- return self->get == other->get;
- }
-#endif
-#if defined i_hash
+ #ifndef i_no_hash
STC_INLINE uint64_t _cx_MEMB(_raw_hash)(const _cx_raw* rx)
{ return i_hash(rx); }
-
- STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
- { _cx_raw rx = i_keyto(self->get); return i_hash(&rx); }
-#else
- STC_INLINE uint64_t _cx_MEMB(_raw_hash)(const _cx_raw* rx)
- { return c_default_hash(&rx); }
-
- STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
- { return c_default_hash(&self->get); }
+ #endif // i_no_hash
+
+ #if defined i_ptr_cmp
+ STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
+ return c_default_cmp(&self->get, &other->get);
+ }
+ STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
+ return self->get == other->get;
+ }
+ STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
+ { return c_default_hash(&self->get); }
+ #else
+ STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
+ _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
+ return i_cmp((&rx), (&ry));
+ }
+ STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
+ _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
+ return i_eq((&rx), (&ry));
+ }
+ #ifndef i_no_hash
+ STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
+ { _cx_raw rx = i_keyto(self->get); return i_hash(&rx); }
+ #endif // i_no_hash
+ #endif // i_ptr_cmp
#endif
#undef _i_atomic_inc
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 25d41b92..b799c24c 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -159,50 +159,41 @@ STC_INLINE void _cx_MEMB(_assign)(_cx_Self* self, _cx_Self* moved) {
moved->get = NULL;
}
-#if defined _i_has_cmp
+#if defined i_use_cmp
STC_INLINE int _cx_MEMB(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_cmp(rx, ry); }
- STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
- _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
- return i_cmp((&rx), (&ry));
- }
-#else
- STC_INLINE int _cx_MEMB(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry)
- { return c_default_cmp(&rx, &ry); }
-
- STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
- return c_default_cmp(&self->get, &other->get);
- }
-#endif
-#if defined _i_has_eq || defined _i_has_cmp
STC_INLINE bool _cx_MEMB(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_eq(rx, ry); }
-
- STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
- _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
- return i_eq((&rx), (&ry));
- }
-#else
- STC_INLINE bool _cx_MEMB(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
- { return rx == ry; }
-
- STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
- return self->get == other->get;
- }
-#endif
-#if defined i_hash
+ #ifndef i_no_hash
STC_INLINE uint64_t _cx_MEMB(_raw_hash)(const _cx_raw* rx)
{ return i_hash(rx); }
-
- STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
- { _cx_raw rx = i_keyto(self->get); return i_hash(&rx); }
-#else
- STC_INLINE uint64_t _cx_MEMB(_raw_hash)(const _cx_raw* rx)
- { return c_default_hash(&rx); }
-
- STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
- { return c_default_hash(&self->get); }
+ #endif // i_no_hash
+
+ #if defined i_ptr_cmp
+ STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
+ return c_default_cmp(&self->get, &other->get);
+ }
+ STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
+ return self->get == other->get;
+ }
+ STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
+ { return c_default_hash(&self->get); }
+ #else
+ STC_INLINE int _cx_MEMB(_cmp)(const _cx_Self* self, const _cx_Self* other) {
+ _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
+ return i_cmp((&rx), (&ry));
+ }
+ STC_INLINE bool _cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) {
+ _cx_raw rx = i_keyto(self->get), ry = i_keyto(other->get);
+ return i_eq((&rx), (&ry));
+ }
+ #ifndef i_no_hash
+ STC_INLINE uint64_t _cx_MEMB(_hash)(const _cx_Self* self)
+ { _cx_raw rx = i_keyto(self->get); return i_hash(&rx); }
+ #endif // i_no_hash
+ #endif // i_ptr_cmp
#endif
+
#include "priv/template2.h"
#undef _i_cbox
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 2528b94f..b37ad1da 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -117,7 +117,7 @@ typedef long long _llong;
#define c_no_clone (1<<2)
#define c_no_emplace (1<<3)
#define c_no_cmp (1<<4)
-#define c_native_cmp (1<<5)
+#define c_use_cmp (1<<5)
#define c_no_hash (1<<6)
/* Function macros and others */
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 49b4d8da..fae9093e 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -102,8 +102,8 @@
#if c_option(c_no_emplace)
#define i_no_emplace
#endif
-#if c_option(c_native_cmp)
- #define i_cmp_native
+#if c_option(c_use_cmp) || defined _i_ismap || defined _i_isset || defined _i_ispque
+ #define i_use_cmp
#endif
#if c_option(c_no_clone) || defined _i_carc
#define i_no_clone
@@ -127,7 +127,7 @@
#elif defined i_keyboxed
#define i_keyclass i_keyboxed
#define i_rawclass c_PASTE(i_keyboxed, _raw)
- #ifndef i_no_cmp
+ #if !defined i_no_cmp && defined i_use_cmp
#define i_eq c_PASTE(i_keyboxed, _raw_eq)
#endif
#endif
@@ -138,7 +138,7 @@
#define i_rawclass i_key
#endif
-#ifdef i_keyclass
+#if defined i_keyclass
#define i_key i_keyclass
#ifndef i_keyclone
#define i_keyclone c_PASTE(i_key, _clone)
@@ -154,8 +154,8 @@
#endif
#endif
-#ifdef i_rawclass
- #if !(defined i_cmp || defined i_no_cmp)
+#if defined i_rawclass && defined i_use_cmp
+ #if !(defined i_cmp || defined i_less || defined i_no_cmp)
#define i_cmp c_PASTE(i_keyraw, _cmp)
#endif
#if !(defined i_hash || defined i_no_hash || defined i_no_cmp)
@@ -171,26 +171,29 @@
#endif
#endif
-#ifndef i_no_cmp
- #if defined i_cmp || defined i_less || defined i_cmp_native
+#if !defined i_no_cmp
+ #if defined i_cmp || defined i_less || defined i_use_cmp
#define _i_has_cmp
#endif
- #if defined i_eq || defined i_cmp_native
+ #if defined i_eq || defined i_use_cmp
#define _i_has_eq
#endif
#endif
+#if !(defined i_hash || defined i_no_hash || defined i_no_cmp)
+ #define i_hash c_default_hash
+#endif
#if !defined i_key
#error "No i_key or i_val defined"
#elif defined i_keyraw ^ defined i_keyto
#error "Both i_keyraw/i_valraw and i_keyto/i_valto must be defined, if any"
#elif !defined i_no_clone && (defined i_keyclone ^ defined i_keydrop)
- #error "Both i_keyclone/i_valclone and i_keydrop/i_valdrop must be defined, if any"
+ #error "Both i_keyclone/i_valclone and i_keydrop/i_valdrop must be defined, if any (unless i_no_clone defined)."
#elif defined i_from || defined i_drop
#error "i_from / i_drop not supported. Define i_keyfrom/i_valfrom and/or i_keydrop/i_valdrop instead"
#elif defined i_keyraw && defined _i_ishash && !(defined i_hash && (defined _i_has_cmp || defined i_eq))
#error "For cmap/cset, both i_hash and i_eq (or i_less or i_cmp) must be defined when i_keyraw is defined."
-#elif defined i_keyraw && (defined _i_ismap || defined _i_isset || defined _i_ispque) && !defined _i_has_cmp
+#elif defined i_keyraw && defined i_use_cmp && !defined _i_has_cmp
#error "For csmap/csset/cpque, i_cmp or i_less must be defined when i_keyraw is defined."
#endif
@@ -234,10 +237,6 @@
#endif
#endif
-#if !defined i_hash && (!(defined _i_cbox || defined _i_carc) || defined i_cmp_native)
- #define i_hash c_default_hash
-#endif
-
#if defined _i_ismap // ---- process cmap/csmap value i_val, ... ----
#ifdef i_val_str
diff --git a/include/stc/priv/template2.h b/include/stc/priv/template2.h
index 351defde..1e0d4a2e 100644
--- a/include/stc/priv/template2.h
+++ b/include/stc/priv/template2.h
@@ -67,7 +67,7 @@
#undef i_realloc
#undef i_free
-#undef i_cmp_native
+#undef i_use_cmp
#undef i_no_cmp
#undef i_no_hash
#undef i_no_clone