diff options
| author | Tyge Løvset <[email protected]> | 2022-11-15 18:50:49 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-11-15 18:50:49 +0100 |
| commit | 178f4f9048cc4b4db30d5ee694c3eb3158c34749 (patch) | |
| tree | 9d3a67ce3f5b6d8029cc0b7484e89c4874298da4 /include/stc | |
| parent | 688aa900792cf6629c2aa8c814dd590306ae05e0 (diff) | |
| download | STC-modified-178f4f9048cc4b4db30d5ee694c3eb3158c34749.tar.gz STC-modified-178f4f9048cc4b4db30d5ee694c3eb3158c34749.zip | |
More internal cleanup and fixes for cbox and carc.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/carc.h | 54 | ||||
| -rw-r--r-- | include/stc/cbox.h | 54 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 8 | ||||
| -rw-r--r-- | include/stc/template.h | 6 |
4 files changed, 50 insertions, 72 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h index 31cfa387..78887073 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -78,12 +78,6 @@ int main() { #ifndef _i_prefix #define _i_prefix carc_ #endif -#if !(defined i_cmp || defined i_less || defined i_keyclass || defined i_valclass) - #define i_no_cmp -#endif -#if !(defined i_eq || defined i_hash || defined i_keyclass || defined i_valclass) - #define i_no_hash -#endif #include "template.h" typedef i_keyraw _cx_raw; @@ -177,42 +171,34 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self ptr) { *self = ptr; } -STC_INLINE int _cx_memb(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry) { - #if defined i_no_cmp - return memcmp(rx, ry, sizeof *rx); - #else - return i_cmp(rx, ry); - #endif -} - -STC_INLINE uint64_t _cx_memb(_raw_hash)(const _cx_raw* rx) { - #if defined i_no_hash - return c_default_hash(rx); - #else - return i_hash(rx); - #endif -} - -STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry) { - #if defined i_no_hash - return memcmp(rx, ry, sizeof *rx) == 0; - #else - return i_eq(rx, ry); - #endif -} - -STC_INLINE uint64_t _cx_memb(_hash)(const _cx_self* x) - { _cx_raw rx = i_keyto(x->get); return _cx_memb(_raw_hash)(&rx); } +#ifndef i_no_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* x, const _cx_self* y) { _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); - return _cx_memb(_raw_cmp)(&rx, &ry); + return i_cmp(&rx, &ry); } +#endif + +#ifndef i_no_eq +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* x, const _cx_self* y) { _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); - return _cx_memb(_raw_eq)(&rx, &ry); + return i_eq(&rx, &ry); } +#endif + +#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* x) + { _cx_raw rx = i_keyto(x->get); return i_hash(&rx); } +#endif + #undef _i_atomic_inc #undef _i_atomic_dec_and_test #include "template.h" diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 4c63d322..a5e01519 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -70,12 +70,6 @@ int main() { #ifndef _i_prefix #define _i_prefix cbox_ #endif -#if !(defined i_cmp || defined i_less || defined i_keyclass || defined i_valclass) - #define i_no_cmp -#endif -#if !(defined i_eq || defined i_hash || defined i_keyclass || defined i_valclass) - #define i_no_hash -#endif #include "template.h" typedef i_keyraw _cx_raw; @@ -152,40 +146,32 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) { *self = other; } -STC_INLINE int _cx_memb(_raw_cmp)(const _cx_raw* rx, const _cx_raw* ry) { - #if defined i_no_cmp - return memcmp(rx, ry, sizeof *rx); - #else - return i_cmp(rx, ry); - #endif -} - -STC_INLINE uint64_t _cx_memb(_raw_hash)(const _cx_raw* rx) { - #if defined i_no_hash - return c_default_hash(rx); - #else - return i_hash(rx); - #endif -} - -STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry) { - #if defined i_no_hash - return memcmp(rx, ry, sizeof *rx) == 0; - #else - return i_eq(rx, ry); - #endif -} - -STC_INLINE uint64_t _cx_memb(_hash)(const _cx_self* x) - { _cx_raw rx = i_keyto(x->get); return _cx_memb(_raw_hash)(&rx); } +#ifndef i_no_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* x, const _cx_self* y) { _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); - return _cx_memb(_raw_cmp)(&rx, &ry); + return i_cmp(&rx, &ry); } +#endif + +#ifndef i_no_eq +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* x, const _cx_self* y) { _cx_raw rx = i_keyto(x->get), ry = i_keyto(y->get); - return _cx_memb(_raw_eq)(&rx, &ry); + return i_eq(&rx, &ry); } +#endif + +#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* x) + { _cx_raw rx = i_keyto(x->get); return i_hash(&rx); } +#endif + #include "template.h" diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index a6851eb8..8d6fa0ea 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -104,9 +104,11 @@ #define c_is_forward (1<<0) #define c_no_atomic (1<<1) #define c_no_clone (1<<2) -#define c_no_cmp (1<<3) -#define c_no_hash (1<<4) -#define c_no_emplace (1<<5) +#define c_no_emplace (1<<3) +#define c_no_cmp (1<<4) +#define c_no_eq (1<<5) +#define c_no_hash (1<<6) +#define c_no_lookup (c_no_cmp|c_no_eq|c_no_hash) /* Generic algorithms */ diff --git a/include/stc/template.h b/include/stc/template.h index 95a0871f..cd47a989 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -92,6 +92,9 @@ #if c_option(c_no_cmp) #define i_no_cmp #endif +#if c_option(c_no_eq) + #define i_no_eq +#endif #if c_option(c_no_hash) #define i_no_hash #endif @@ -119,7 +122,7 @@ #define i_keyclass i_keyboxed #define i_rawclass c_paste(i_keyboxed, _raw) #define i_keyfrom c_paste(i_keyboxed, _from) - #if !defined i_no_hash + #ifndef i_no_eq #define i_eq c_paste(i_keyboxed, _raw_eq) #endif #endif @@ -316,6 +319,7 @@ #undef i_extern #undef i_no_cmp +#undef i_no_eq #undef i_no_hash #undef i_no_clone #undef i_no_emplace |
