From c6cbcea963e75609584a415e6d7ad54b688f0b74 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Thu, 5 May 2022 14:19:12 +0300 Subject: [PATCH 1/2] std c17 --- Makefile | 6 +++--- base/std.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7433d24..f6c333c 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c) OUTDIR=bin CMP=gcc OPT_ARGS=-O2 -flto -WARN_ARGS=-Wall -Wno-discarded-qualifiers +WARN_ARGS=-Wall -Wno-discarded-qualifiers -std=c17 -all: clear_c clear_bin build_test build_test_dbg build_lib build_dll +all: clear_c clear_bin build_test build_lib clear_c: clear @@ -17,7 +17,7 @@ clear_bin: mkdir $(OUTDIR) clang: CMP=clang -clang: WARN_ARGS=-Wall -Wno-ignored-qualifiers -Wno-incompatible-pointer-types-discards-qualifiers +clang: WARN_ARGS=-Wall -Wno-ignored-qualifiers -Wno-incompatible-pointer-types-discards-qualifiers -std=c17 clang: all ###################################### diff --git a/base/std.h b/base/std.h index a2415d2..4607014 100644 --- a/base/std.h +++ b/base/std.h @@ -31,6 +31,9 @@ extern "C" { #else #define CALL #endif + #ifndef typeof + #define typeof __typeof__ + #endif #else #pragma GCC error "unknown compiler" #endif From 703bd4bef4a0f06d5606ddf785c0865e084f1157 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sat, 7 May 2022 23:15:22 +0300 Subject: [PATCH 2/2] changed hash functions names --- Hashtable/Hashtable.c | 4 ++-- Hashtable/hash.c | 4 ++-- Hashtable/hash.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Hashtable/Hashtable.c b/Hashtable/Hashtable.c index 33ec495..d8c680b 100644 --- a/Hashtable/Hashtable.c +++ b/Hashtable/Hashtable.c @@ -39,7 +39,7 @@ void Hashtable_expand(Hashtable* ht){ uint32 arlen=Autoarr_length(ar); for(uint16 k=0;khein]; + uint16 newrown=hash32(p.key)%HT_HEIGHTS[ht->hein]; Autoarr(KVPair)* newar=newrows[newrown]; Autoarr_add(newar,p); } @@ -53,7 +53,7 @@ void Hashtable_expand(Hashtable* ht){ } Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){ - uint32 hash=ihash(key); + uint32 hash=hash32(key); Autoarr(KVPair)* ar=ht->rows[hash%HT_HEIGHTS[ht->hein]]; if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar)) optime("expand",1,(Hashtable_expand(ht))); diff --git a/Hashtable/hash.c b/Hashtable/hash.c index 32ff34f..dfa6cb7 100644 --- a/Hashtable/hash.c +++ b/Hashtable/hash.c @@ -1,13 +1,13 @@ #include "hash.h" -uint32 ihash(char *str){ +uint32 hash32(char *str){ uint32 hash=5381; for (char c=*str;c;c=*(++str)) hash=((hash<<5)+hash)+c; return hash; } -uint64 lhash(char* str){ +uint64 hash64(char* str){ uint64 hash = 0; for (char c=*str;c;c=*(++str)) hash=c+(hash<<6)+(hash<<16)-hash; diff --git a/Hashtable/hash.h b/Hashtable/hash.h index 2f575c5..b3b7d2b 100644 --- a/Hashtable/hash.h +++ b/Hashtable/hash.h @@ -7,9 +7,9 @@ extern "C" { #include "../base/base.h" // djb2 hash function from http:// www.cse.yorku.ca/~oz/hash.html -uint32 ihash(char *str); +uint32 hash32(char *str); // sdbm hash function -uint64 lhash(char* str); +uint64 hash64(char* str); #if __cplusplus }