commit
b8a5c0895e
@ -39,7 +39,7 @@ void Hashtable_expand(Hashtable* ht){
|
||||
uint32 arlen=Autoarr_length(ar);
|
||||
for(uint16 k=0;k<arlen;k++){
|
||||
KVPair p=Autoarr_get(ar,k);
|
||||
uint16 newrown=ihash(p.key)%HT_HEIGHTS[ht->hein];
|
||||
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)));
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
6
Makefile
6
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
|
||||
|
||||
######################################
|
||||
|
||||
@ -31,6 +31,9 @@ extern "C" {
|
||||
#else
|
||||
#define CALL
|
||||
#endif
|
||||
#ifndef typeof
|
||||
#define typeof __typeof__
|
||||
#endif
|
||||
#else
|
||||
#pragma GCC error "unknown compiler"
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user