changed hash functions names

This commit is contained in:
Timerix22 2022-05-07 23:15:22 +03:00
parent c6cbcea963
commit 703bd4bef4
3 changed files with 6 additions and 6 deletions

View File

@ -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)));

View File

@ -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;

View File

@ -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
} }