commit
b8a5c0895e
@ -39,7 +39,7 @@ void Hashtable_expand(Hashtable* ht){
|
|||||||
uint32 arlen=Autoarr_length(ar);
|
uint32 arlen=Autoarr_length(ar);
|
||||||
for(uint16 k=0;k<arlen;k++){
|
for(uint16 k=0;k<arlen;k++){
|
||||||
KVPair p=Autoarr_get(ar,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(KVPair)* newar=newrows[newrown];
|
||||||
Autoarr_add(newar,p);
|
Autoarr_add(newar,p);
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ void Hashtable_expand(Hashtable* ht){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){
|
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]];
|
Autoarr(KVPair)* ar=ht->rows[hash%HT_HEIGHTS[ht->hein]];
|
||||||
if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar))
|
if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar))
|
||||||
optime("expand",1,(Hashtable_expand(ht)));
|
optime("expand",1,(Hashtable_expand(ht)));
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
uint32 ihash(char *str){
|
uint32 hash32(char *str){
|
||||||
uint32 hash=5381;
|
uint32 hash=5381;
|
||||||
for (char c=*str;c;c=*(++str))
|
for (char c=*str;c;c=*(++str))
|
||||||
hash=((hash<<5)+hash)+c;
|
hash=((hash<<5)+hash)+c;
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 lhash(char* str){
|
uint64 hash64(char* str){
|
||||||
uint64 hash = 0;
|
uint64 hash = 0;
|
||||||
for (char c=*str;c;c=*(++str))
|
for (char c=*str;c;c=*(++str))
|
||||||
hash=c+(hash<<6)+(hash<<16)-hash;
|
hash=c+(hash<<6)+(hash<<16)-hash;
|
||||||
|
|||||||
@ -7,9 +7,9 @@ extern "C" {
|
|||||||
#include "../base/base.h"
|
#include "../base/base.h"
|
||||||
|
|
||||||
// djb2 hash function from http:// www.cse.yorku.ca/~oz/hash.html
|
// djb2 hash function from http:// www.cse.yorku.ca/~oz/hash.html
|
||||||
uint32 ihash(char *str);
|
uint32 hash32(char *str);
|
||||||
// sdbm hash function
|
// sdbm hash function
|
||||||
uint64 lhash(char* str);
|
uint64 hash64(char* str);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
6
Makefile
6
Makefile
@ -4,9 +4,9 @@ TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c)
|
|||||||
OUTDIR=bin
|
OUTDIR=bin
|
||||||
CMP=gcc
|
CMP=gcc
|
||||||
OPT_ARGS=-O2 -flto
|
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_c:
|
||||||
clear
|
clear
|
||||||
@ -17,7 +17,7 @@ clear_bin:
|
|||||||
mkdir $(OUTDIR)
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
clang: CMP=clang
|
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
|
clang: all
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
|
|||||||
@ -31,6 +31,9 @@ extern "C" {
|
|||||||
#else
|
#else
|
||||||
#define CALL
|
#define CALL
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef typeof
|
||||||
|
#define typeof __typeof__
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#pragma GCC error "unknown compiler"
|
#pragma GCC error "unknown compiler"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user