summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-11-15 18:50:49 +0100
committerTyge Løvset <[email protected]>2022-11-15 18:50:49 +0100
commit178f4f9048cc4b4db30d5ee694c3eb3158c34749 (patch)
tree9d3a67ce3f5b6d8029cc0b7484e89c4874298da4
parent688aa900792cf6629c2aa8c814dd590306ae05e0 (diff)
downloadSTC-modified-178f4f9048cc4b4db30d5ee694c3eb3158c34749.tar.gz
STC-modified-178f4f9048cc4b4db30d5ee694c3eb3158c34749.zip
More internal cleanup and fixes for cbox and carc.
-rw-r--r--examples/arc_containers.c6
-rw-r--r--examples/box2.c3
-rw-r--r--include/stc/carc.h54
-rw-r--r--include/stc/cbox.h54
-rw-r--r--include/stc/ccommon.h8
-rw-r--r--include/stc/template.h6
6 files changed, 57 insertions, 74 deletions
diff --git a/examples/arc_containers.c b/examples/arc_containers.c
index 5a8b3653..b577f2c8 100644
--- a/examples/arc_containers.c
+++ b/examples/arc_containers.c
@@ -12,15 +12,17 @@
#define i_val Map
#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p))
// no need for atomic ref. count in single thread:
-#define i_opt c_no_atomic
+#define i_opt c_no_atomic|c_no_lookup
#include <stc/carc.h>
#define i_type Stack
#define i_valboxed Arc // define i_valboxed for carc/cbox value (not i_val)
-#include <stc/cstack.h>
+#define i_opt c_no_cmp
+#include <stc/cvec.h>
#define i_type List
#define i_valboxed Arc // as above
+#define i_opt c_no_cmp
#include <stc/clist.h>
int main()
diff --git a/examples/box2.c b/examples/box2.c
index 03f7d8bd..b9628eeb 100644
--- a/examples/box2.c
+++ b/examples/box2.c
@@ -18,15 +18,18 @@ struct {
} typedef Rectangle;
#define i_val Point
+#define i_opt c_no_lookup
#include <stc/cbox.h> // cbox_Point
#define i_val Rectangle
+#define i_opt c_no_lookup
#include <stc/cbox.h> // cbox_Rectangle
// Box in box:
#define i_valboxed cbox_Point // NB: use i_valboxed when value is a cbox or carc!
// it will auto define i_valdrop, i_valfrom, and i_cmp.
#define i_tag BoxPoint
+#define i_opt c_no_lookup
#include <stc/cbox.h> // cbox_BoxPoint
Point origin(void) {
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