summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-12 12:38:40 +0200
committertylov <[email protected]>2023-07-12 13:56:06 +0200
commit50cbc73d4fef3ce91d094b80a018769eac439965 (patch)
tree79492e482cf232ed4def920c015c5f86f030f295
parent0bcb0fcd981cb15329dfd4fb675097564164da18 (diff)
downloadSTC-modified-50cbc73d4fef3ce91d094b80a018769eac439965.tar.gz
STC-modified-50cbc73d4fef3ce91d094b80a018769eac439965.zip
template.h: i_valclone and i_valfrom are considered the same when only one is defined and i_valraw is not defined (directly or via valclass/valboxed/val_str). Also applies to key. Some adjustments for benchmarking.
-rw-r--r--include/stc/priv/template.h41
-rw-r--r--misc/benchmarks/plotbench/clist_benchmark.cpp2
-rw-r--r--misc/benchmarks/plotbench/run_clang.sh10
-rw-r--r--misc/benchmarks/plotbench/run_gcc.sh10
-rw-r--r--misc/examples/new_list.c5
5 files changed, 40 insertions, 28 deletions
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 5551eeae..30ed5732 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -105,6 +105,9 @@
#if c_option(c_native_cmp)
#define i_native_cmp
#endif
+#if c_option(c_no_clone) || defined _i_carc
+ #define i_no_clone
+#endif
#if defined i_key_str
#define i_keyclass cstr
@@ -160,14 +163,20 @@
#endif
#endif
+#if !defined i_keyraw && !defined i_no_clone
+ #if !defined i_keyfrom && defined i_keyclone
+ #define i_keyfrom i_keyclone
+ #elif !defined i_keyclone && defined i_keyfrom
+ #define i_keyclone i_keyfrom
+ #endif
+#endif
+
#if !defined i_key
#error "No i_key or i_val defined"
#elif defined i_keyraw ^ defined i_keyto
- #error "Both i_keyraw/valraw and i_keyto/valto must be defined, if any"
-#elif defined i_keyfrom && !defined i_keyraw && !defined i_keyclone
- #define i_keyclone i_keyfrom
-#elif defined i_keyfrom && !defined i_keyraw
- #error "i_keyfrom/valfrom defined without i_keyraw/valraw"
+ #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"
#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"
#endif
@@ -175,11 +184,6 @@
#ifndef i_tag
#define i_tag i_key
#endif
-#if c_option(c_no_clone) || defined _i_carc
- #define i_no_clone
-#elif !(defined i_keyclone || defined i_no_clone) && (defined i_keydrop || defined i_keyraw)
- #error i_keyclone/valclone should be defined when i_keydrop/valdrop or i_keyraw/valraw is defined
-#endif
#ifndef i_keyraw
#define i_keyraw i_key
#endif
@@ -259,15 +263,22 @@
#endif
#endif
+#if !defined i_valraw && !defined i_no_clone
+ #if !defined i_valfrom && defined i_valclone
+ #define i_valfrom i_valclone
+ #elif !defined i_valclone && defined i_valfrom
+ #define i_valclone i_valfrom
+ #endif
+#endif
+
#ifndef i_val
#error "i_val* must be defined for maps"
+#elif defined i_valraw ^ defined i_valto
+ #error "Both i_valraw and i_valto must be defined, if any"
+#elif !defined i_no_clone && (defined i_valclone ^ defined i_valdrop)
+ #error "Both i_valclone and i_valdrop must be defined, if any"
#endif
-#if !defined i_valclone && defined i_valfrom && !defined i_valraw
- #define i_valclone i_valfrom
-#elif !(defined i_valclone || defined i_no_clone) && (defined i_valdrop || defined i_valraw)
- #error i_valclone should be defined when i_valdrop or i_valraw is defined
-#endif
#ifndef i_valraw
#define i_valraw i_val
#endif
diff --git a/misc/benchmarks/plotbench/clist_benchmark.cpp b/misc/benchmarks/plotbench/clist_benchmark.cpp
index 703222b3..01bfbf83 100644
--- a/misc/benchmarks/plotbench/clist_benchmark.cpp
+++ b/misc/benchmarks/plotbench/clist_benchmark.cpp
@@ -12,7 +12,7 @@ enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
-enum {SAMPLES = 2, N = 25000000, S = 0x3ffc, R = 4};
+enum {SAMPLES = 2, N = 10000000, S = 0x3ffc, R = 4};
uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
diff --git a/misc/benchmarks/plotbench/run_clang.sh b/misc/benchmarks/plotbench/run_clang.sh
index c9dbac31..59d577d9 100644
--- a/misc/benchmarks/plotbench/run_clang.sh
+++ b/misc/benchmarks/plotbench/run_clang.sh
@@ -1,10 +1,10 @@
exe=''
if [ "$OS" = "Windows_NT" ] ; then exe=".exe" ; fi
-clang++ -I../../include -O3 -o cdeq_benchmark$exe cdeq_benchmark.cpp
-clang++ -I../../include -O3 -o clist_benchmark$exe clist_benchmark.cpp
-clang++ -I../../include -O3 -o cmap_benchmark$exe cmap_benchmark.cpp
-clang++ -I../../include -O3 -o csmap_benchmark$exe csmap_benchmark.cpp
-clang++ -I../../include -O3 -o cvec_benchmark$exe cvec_benchmark.cpp
+clang++ -DNDEBUG -I../../include -O3 -o cdeq_benchmark$exe cdeq_benchmark.cpp
+clang++ -DNDEBUG -I../../include -O3 -o clist_benchmark$exe clist_benchmark.cpp
+clang++ -DNDEBUG -I../../include -O3 -o cmap_benchmark$exe cmap_benchmark.cpp
+clang++ -DNDEBUG -I../../include -O3 -o csmap_benchmark$exe csmap_benchmark.cpp
+clang++ -DNDEBUG -I../../include -O3 -o cvec_benchmark$exe cvec_benchmark.cpp
c='Win-Clang-14.0.1'
./cdeq_benchmark$exe $c
diff --git a/misc/benchmarks/plotbench/run_gcc.sh b/misc/benchmarks/plotbench/run_gcc.sh
index 14d89b9a..73b979d3 100644
--- a/misc/benchmarks/plotbench/run_gcc.sh
+++ b/misc/benchmarks/plotbench/run_gcc.sh
@@ -1,8 +1,8 @@
-g++ -I../../include -O3 -o cdeq_benchmark cdeq_benchmark.cpp
-g++ -I../../include -O3 -o clist_benchmark clist_benchmark.cpp
-g++ -I../../include -O3 -o cmap_benchmark cmap_benchmark.cpp
-g++ -I../../include -O3 -o csmap_benchmark csmap_benchmark.cpp
-g++ -I../../include -O3 -o cvec_benchmark cvec_benchmark.cpp
+g++ -DNDEBUG -I../../include -O3 -o cdeq_benchmark cdeq_benchmark.cpp
+g++ -DNDEBUG -I../../include -O3 -o clist_benchmark clist_benchmark.cpp
+g++ -DNDEBUG -I../../include -O3 -o cmap_benchmark cmap_benchmark.cpp
+g++ -DNDEBUG -I../../include -O3 -o csmap_benchmark csmap_benchmark.cpp
+g++ -DNDEBUG -I../../include -O3 -o cvec_benchmark cvec_benchmark.cpp
c='Mingw-g++-11.3.0'
./cdeq_benchmark $c
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index 8083c315..5ffdaca2 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -32,8 +32,9 @@ int point_cmp(const Point* a, const Point* b) {
void MyStruct_drop(MyStruct* s);
#define i_type MyList
-#define i_valclass MyStruct // MyStruct contains "class"-types, so define as "class"
-#define i_opt c_no_clone|c_no_cmp // exclude cloning and comparison support
+#define i_val MyStruct
+#define i_valdrop MyStruct_drop // define drop function
+#define i_no_clone // must explicitely exclude or define cloning support because of drop.
#include <stc/clist.h>
void MyStruct_drop(MyStruct* s) {