From 8da81e7a625f06ec667793ff624c6876d03abbde Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 19 Sep 2021 13:49:41 +0200 Subject: Fixed errors caused by gcc -std=c99 -pedantic. --- benchmarks/build_all.sh | 35 +++++++++++++++++++++++++++++++++++ benchmarks/cpque_benchmark.cpp | 4 ++-- benchmarks/run_clang.sh | 24 +++++++++++++----------- benchmarks/run_gcc.sh | 22 +++++++++++----------- benchmarks/shootout1_cmap.cpp | 7 ------- benchmarks/shootout2_cmap.cpp | 13 ------------- benchmarks/shootout5_crand.cpp | 8 ++++---- docs/cmap_api.md | 2 +- docs/cstr_api.md | 1 + examples/advanced.c | 2 +- examples/csmap_find.c | 4 ++-- examples/runall.sh | 4 ++-- include/stc/ccommon.h | 3 ++- 13 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 benchmarks/build_all.sh diff --git a/benchmarks/build_all.sh b/benchmarks/build_all.sh new file mode 100644 index 00000000..6217d5e1 --- /dev/null +++ b/benchmarks/build_all.sh @@ -0,0 +1,35 @@ +#!/bin/sh +cc='g++ -std=c++17' +#cc='clang' +#cc='clang -c -DSTC_HEADER' +#cc='cl -nologo' +#cc='cl -nologo -TP' +#cc='cl -nologo -std:c11' +run=0 +if [ "$1" == '-h' -o "$1" == '--help' ]; then + echo usage: runall.sh [-run] [compiler + options] + exit +fi +if [ "$1" == '-run' ]; then + run=1 + shift +fi +if [ ! -z "$1" ] ; then + cc=$@ +fi +if [ $run = 0 ] ; then + for i in *.cpp ; do + echo $cc -I../include $i + $cc -I../include $i + done +else + for i in *.c ; do + echo $cc -I../include $i + $cc -I../include $i + if [ -f $(basename -s .c $i).exe ]; then ./$(basename -s .c $i).exe; fi + if [ -f ./a.exe ]; then ./a.exe; fi + if [ -f ./a.out ]; then ./a.out; fi + done +fi + +rm -f a.out *.o *.obj *.exe diff --git a/benchmarks/cpque_benchmark.cpp b/benchmarks/cpque_benchmark.cpp index 2b6445c5..5f7dd364 100644 --- a/benchmarks/cpque_benchmark.cpp +++ b/benchmarks/cpque_benchmark.cpp @@ -2,7 +2,7 @@ #include #include -#define i_tag x +#define i_tag f #define i_val float #define i_cmp -c_default_compare #include @@ -18,7 +18,7 @@ int main() rng = stc64_init(seed); clock_t start = clock(); c_forrange (i, int, N) - cvec_f_push_back(&pq, (float) stc64_randf(&rng)*100000); + cpque_f_push_back(&pq, (float) stc64_randf(&rng)*100000); cpque_f_make_heap(&pq); printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); diff --git a/benchmarks/run_clang.sh b/benchmarks/run_clang.sh index e8e9910f..f7575882 100644 --- a/benchmarks/run_clang.sh +++ b/benchmarks/run_clang.sh @@ -1,12 +1,14 @@ -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 +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 -c=Win-Clang-12 -./cdeq_benchmark.exe $c -./clist_benchmark.exe $c -./cmap_benchmark.exe $c -./csmap_benchmark.exe $c -./cvec_benchmark.exe $c +c='Win-Clang-12' +./cdeq_benchmark$exe $c +./clist_benchmark$exe $c +./cmap_benchmark$exe $c +./csmap_benchmark$exe $c +./cvec_benchmark$exe $c diff --git a/benchmarks/run_gcc.sh b/benchmarks/run_gcc.sh index 460afe16..6a6472c0 100644 --- a/benchmarks/run_gcc.sh +++ b/benchmarks/run_gcc.sh @@ -1,12 +1,12 @@ -g++ -I../include -O3 -o cdeq_benchmark.exe cdeq_benchmark.cpp -g++ -I../include -O3 -o clist_benchmark.exe clist_benchmark.cpp -g++ -I../include -O3 -o cmap_benchmark.exe cmap_benchmark.cpp -g++ -I../include -O3 -o csmap_benchmark.exe csmap_benchmark.cpp -g++ -I../include -O3 -o cvec_benchmark.exe cvec_benchmark.cpp +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 -c=Mingw-g++-10.30 -./cdeq_benchmark.exe $c -./clist_benchmark.exe $c -./cmap_benchmark.exe $c -./csmap_benchmark.exe $c -./cvec_benchmark.exe $c \ No newline at end of file +c='Mingw-g++-10.30' +./cdeq_benchmark $c +./clist_benchmark $c +./cmap_benchmark $c +./csmap_benchmark $c +./cvec_benchmark $c \ No newline at end of file diff --git a/benchmarks/shootout1_cmap.cpp b/benchmarks/shootout1_cmap.cpp index 5fd32586..2cdb919f 100644 --- a/benchmarks/shootout1_cmap.cpp +++ b/benchmarks/shootout1_cmap.cpp @@ -7,7 +7,6 @@ #include "others/robin_hood.hpp" #include "others/skarupke/bytell_hash_map.hpp" #include "others/tsl/hopscotch_map.h" -#include "others/tsl/robin_map.h" #include "others/sparsepp/spp.h" #define PICOBENCH_IMPLEMENT_WITH_MAIN @@ -20,7 +19,6 @@ template using umap = std::unordered_map; template using bmap = ska::bytell_hash_map; template using fmap = ska::flat_hash_map; template using hmap = tsl::hopscotch_map; -template using omap = tsl::robin_map; template using smap = spp::sparse_hash_map; template using rmap = robin_hood::unordered_flat_map, std::equal_to, MaxLoadFactor100>; @@ -29,7 +27,6 @@ template using rmap = robin_hood::unordered_flat_map).P; PICOBENCH(ins_and_erase_i).P; PICOBENCH(ins_and_erase_i).P; PICOBENCH(ins_and_erase_i).P; -PICOBENCH(ins_and_erase_i).P; PICOBENCH(ins_and_erase_i).P; PICOBENCH(ins_and_erase_i).P; PICOBENCH(ins_and_erase_cmap_x).P; @@ -165,7 +161,6 @@ PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_i).P; -PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_i).P; PICOBENCH(ins_and_access_cmap_i).P; @@ -223,7 +218,6 @@ PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_s).P; -PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_s).P; PICOBENCH(ins_and_access_cmap_s).P; @@ -297,7 +291,6 @@ PICOBENCH(iterate_x).P; PICOBENCH(iterate_x).P; PICOBENCH(iterate_x).P; PICOBENCH(iterate_x).P; -PICOBENCH(iterate_x).P; PICOBENCH(iterate_x).P; PICOBENCH(iterate_x).P; PICOBENCH(iterate_cmap_x).P; diff --git a/benchmarks/shootout2_cmap.cpp b/benchmarks/shootout2_cmap.cpp index 669c336c..6224c1f3 100644 --- a/benchmarks/shootout2_cmap.cpp +++ b/benchmarks/shootout2_cmap.cpp @@ -9,7 +9,6 @@ #include "others/robin_hood.hpp" #include "others/skarupke/bytell_hash_map.hpp" #include "others/tsl/hopscotch_map.h" -#include "others/tsl/robin_map.h" #include "others/sparsepp/spp.h" template inline void destroy_me(C& c) { C().swap(c); } #endif @@ -105,18 +104,6 @@ stc64_t rng; #define HMAP_CLEAR(X) UMAP_CLEAR(X) #define HMAP_DTOR(X) UMAP_DTOR(X) -#define OMAP_SETUP(X, Key, Value) tsl::robin_map map; map.max_load_factor(max_load_factor) -#define OMAP_PUT(X, key, val) UMAP_PUT(X, key, val) -#define OMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val) -#define OMAP_FIND(X, key) UMAP_FIND(X, key) -#define OMAP_ERASE(X, key) UMAP_ERASE(X, key) -#define OMAP_FOR(X, i) UMAP_FOR(X, i) -#define OMAP_ITEM(X, i) UMAP_ITEM(X, i) -#define OMAP_SIZE(X) UMAP_SIZE(X) -#define OMAP_BUCKETS(X) UMAP_BUCKETS(X) -#define OMAP_CLEAR(X) UMAP_CLEAR(X) -#define OMAP_DTOR(X) UMAP_DTOR(X) - #define RMAP_SETUP(X, Key, Value) robin_hood::unordered_map map #define RMAP_PUT(X, key, val) UMAP_PUT(X, key, val) #define RMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val) diff --git a/benchmarks/shootout5_crand.cpp b/benchmarks/shootout5_crand.cpp index eacca54a..0a034fc4 100644 --- a/benchmarks/shootout5_crand.cpp +++ b/benchmarks/shootout5_crand.cpp @@ -2,7 +2,7 @@ #include #include #include "stc/crandom.h" -#include "others/pcg_random.hpp" +//#include "pcg_random.hpp" static struct stc32_state { stc64_t rng; uint64_t spare; unsigned n; } stc32_global = {{0x7a5fed, 0x8e3f52, 0x9bc713, 0x6a09e667a7541669}, 0, 0}; @@ -59,7 +59,7 @@ void test1(void) c_forrange (8) printf("%f ", fdist(rng)); puts("\n"); } - +/* void test2() { clock_t diff, before; @@ -96,7 +96,7 @@ void test2() c_forrange (8) printf("%f ", fdist(rng)); puts("\n"); } - +*/ void test3(void) { @@ -132,6 +132,6 @@ void test3(void) int main() { test1(); - test2(); + //test2(); test3(); } \ No newline at end of file diff --git a/docs/cmap_api.md b/docs/cmap_api.md index f72ee280..3fcc8ff8 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -346,7 +346,7 @@ static int RViking_equals(const RViking* r1, const RViking* r2) { return !strcmp(r1->name, r2->name) && !strcmp(r1->country, r2->country); } static uint32_t RViking_hash(const RViking* r, int ignored) - { return c_rawstr_hash(&r->name) ^ (c_rawstr_hash(&r->country) >> 15); } + { return c_strhash(r->name) ^ (c_strhash(r->country) >> 15); } static Viking Viking_fromR(RViking r) { return (Viking){cstr_from(r.name), cstr_from(r.country)}; } diff --git a/docs/cstr_api.md b/docs/cstr_api.md index b922092d..ecb58637 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -93,6 +93,7 @@ int c_rawstr_compare(const char** x, const char** y); bool c_rawstr_equals(const char** x, const char** y); uint64_t c_rawstr_hash(const char* const* x, ...); +uint64_t c_strhash(const char* str); char* c_strnstrn(const char* str, const char* needle, size_t slen, size_t nlen); int c_strncasecmp(const char* str1, const char* str2, size_t n); ``` diff --git a/examples/advanced.c b/examples/advanced.c index 8044594e..e4d3411e 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -19,7 +19,7 @@ typedef struct VikingRaw { } VikingRaw; uint64_t vikingraw_hash(const VikingRaw* raw, size_t ignore) { - uint64_t hash = c_rawstr_hash(&raw->name) ^ (c_rawstr_hash(&raw->country) >> 15); + uint64_t hash = c_strhash(raw->name) ^ (c_strhash(raw->country) >> 15); return hash; } static inline int vikingraw_equals(const VikingRaw* rx, const VikingRaw* ry) { diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 66768016..30c7a685 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -26,8 +26,8 @@ void print_elem(csmap_istr_rawvalue_t p) { puts(""); \ } -using_print_collection(csmap_istr); -using_print_collection(cvec_istr); +using_print_collection(csmap_istr) +using_print_collection(cvec_istr) void findit(csmap_istr c, csmap_istr_key_t val) diff --git a/examples/runall.sh b/examples/runall.sh index c476c6e1..71b1c383 100644 --- a/examples/runall.sh +++ b/examples/runall.sh @@ -1,6 +1,6 @@ #!/bin/sh -cc=gcc -#cc=clang +cc='gcc -std=c99 -pedantic' +#cc='clang' #cc='clang -c -DSTC_HEADER' #cc='cl -nologo' #cc='cl -nologo -TP' diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index a64bff40..d11f1b3f 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -102,7 +102,8 @@ #define c_rawstr_compare(x, y) strcmp(*(x), *(y)) #define c_rawstr_equals(x, y) (strcmp(*(x), *(y)) == 0) -#define c_rawstr_hash(p, ...) c_default_hash(*(p), strlen(*(p))) +#define c_rawstr_hash(p, dummy) c_default_hash(*(p), strlen(*(p))) +#define c_strhash(s) c_default_hash(s, strlen(s)) #define c_no_clone(x) (assert(!"c_no_clone() called"), x) #define c_default_fromraw(x) (x) -- cgit v1.2.3