summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-18 07:51:44 +0100
committerTyge Løvset <[email protected]>2023-02-18 07:51:44 +0100
commit0e3d07dbd991c1f1a691b24655c37ddab660a9d9 (patch)
treedc9801e2fc9f62cbe3eb32cc8897c65e3f25f78b
parentc4ae61de5be08e719e3183f4e2d1115c11856796 (diff)
downloadSTC-modified-0e3d07dbd991c1f1a691b24655c37ddab660a9d9.tar.gz
STC-modified-0e3d07dbd991c1f1a691b24655c37ddab660a9d9.zip
Fixed carc, cbox: no need for no_lookup and no_eq: use only no_cmp, no_hash if needed.
-rw-r--r--include/stc/carc.h12
-rw-r--r--include/stc/cbox.h12
-rw-r--r--include/stc/ccommon.h4
-rw-r--r--include/stc/priv/template.h6
-rw-r--r--misc/examples/arc_containers.c2
-rw-r--r--misc/examples/box2.c6
-rw-r--r--misc/examples/list.c2
-rw-r--r--misc/examples/music_arc.c4
8 files changed, 32 insertions, 16 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 82f8835d..d606ac6e 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -77,6 +77,9 @@ int main() {
#ifndef _i_prefix
#define _i_prefix carc_
#endif
+#ifdef i_eq
+#define _i_eq
+#endif
#include "priv/template.h"
typedef i_keyraw _cx_raw;
@@ -180,7 +183,7 @@ STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) {
}
#endif
-#ifndef i_no_eq
+#ifdef _i_eq
STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_eq(rx, ry); }
@@ -188,6 +191,12 @@ 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 i_eq((&rx), (&ry));
}
+#elif !defined i_no_cmp
+STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
+ { return i_cmp(rx, ry) == 0; }
+
+STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y)
+ { return _cx_memb(_cmp)(x, y) == 0; }
#endif
#ifndef i_no_hash
@@ -198,6 +207,7 @@ 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_eq
#undef _i_atomic_inc
#undef _i_atomic_dec_and_test
#include "priv/template.h"
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 08449031..44c819dd 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -70,6 +70,9 @@ int main() {
#ifndef _i_prefix
#define _i_prefix cbox_
#endif
+#ifdef i_eq
+#define _i_eq
+#endif
#include "priv/template.h"
typedef i_keyraw _cx_raw;
@@ -166,7 +169,7 @@ STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) {
}
#endif
-#ifndef i_no_eq
+#ifdef _i_eq
STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
{ return i_eq(rx, ry); }
@@ -174,6 +177,12 @@ 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 i_eq((&rx), (&ry));
}
+#elif !defined i_no_cmp
+STC_INLINE bool _cx_memb(_raw_eq)(const _cx_raw* rx, const _cx_raw* ry)
+ { return i_cmp(rx, ry) == 0; }
+
+STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y)
+ { return _cx_memb(_cmp)(x, y) == 0; }
#endif
#ifndef i_no_hash
@@ -184,4 +193,5 @@ 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_eq
#include "priv/template.h"
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index db9a2f5c..dae991ed 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -113,9 +113,7 @@
#define c_no_clone (1<<2)
#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)
+#define c_no_hash (1<<5)
/* Function macros and others */
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 4b5c60cf..3fddb998 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -99,9 +99,6 @@
#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
@@ -128,7 +125,7 @@
#elif defined i_keyboxed
#define i_keyclass i_keyboxed
#define i_rawclass c_PASTE(i_keyboxed, _raw)
- #ifndef i_no_eq
+ #ifndef i_no_cmp
#define i_eq c_PASTE(i_keyboxed, _raw_eq)
#endif
#endif
@@ -338,7 +335,6 @@
#undef i_free
#undef i_no_cmp
-#undef i_no_eq
#undef i_no_hash
#undef i_no_clone
#undef i_no_emplace
diff --git a/misc/examples/arc_containers.c b/misc/examples/arc_containers.c
index 201c73d5..b621c386 100644
--- a/misc/examples/arc_containers.c
+++ b/misc/examples/arc_containers.c
@@ -12,7 +12,7 @@
#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|c_no_lookup|c_no_clone
+#define i_opt c_no_atomic|c_no_cmp|c_no_clone
#include <stc/carc.h>
#define i_type Stack
diff --git a/misc/examples/box2.c b/misc/examples/box2.c
index b9628eeb..943b2ae8 100644
--- a/misc/examples/box2.c
+++ b/misc/examples/box2.c
@@ -18,18 +18,18 @@ struct {
} typedef Rectangle;
#define i_val Point
-#define i_opt c_no_lookup
+#define i_opt c_no_cmp
#include <stc/cbox.h> // cbox_Point
#define i_val Rectangle
-#define i_opt c_no_lookup
+#define i_opt c_no_cmp
#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
+#define i_opt c_no_cmp
#include <stc/cbox.h> // cbox_BoxPoint
Point origin(void) {
diff --git a/misc/examples/list.c b/misc/examples/list.c
index 79dcfcaf..6a655800 100644
--- a/misc/examples/list.c
+++ b/misc/examples/list.c
@@ -30,7 +30,7 @@ int main() {
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
- int last = 0;
+ double last = 0;
c_foreach (i, clist_fx, list) {
if (*i.ref < last) {printf("ERROR"); exit(-1);}
last = *i.ref;
diff --git a/misc/examples/music_arc.c b/misc/examples/music_arc.c
index 2a2d24c5..fcd24beb 100644
--- a/misc/examples/music_arc.c
+++ b/misc/examples/music_arc.c
@@ -11,6 +11,8 @@ typedef struct
int Song_cmp(const Song* x, const Song* y)
{ return cstr_cmp(&x->title, &y->title); }
+uint64_t Song_hash(const Song* x) { return cstr_hash(&x->title); }
+
Song Song_make(const char* artist, const char* title)
{ return (Song){cstr_from(artist), cstr_from(title)}; }
@@ -22,7 +24,7 @@ void Song_drop(Song* s) {
// Define the reference counted type
#define i_type SongArc
#define i_valclass Song
-#define i_opt c_no_hash
+//#define i_opt c_no_hash
#include <stc/carc.h>
// ... and a vector of it