hash functions replaced

This commit is contained in:
2022-06-03 20:41:09 +03:00
parent 5b0098ad39
commit 11875856c2
6 changed files with 160 additions and 23 deletions

View File

@@ -1,19 +1,20 @@
#include "tests.h"
void test_all(){
test_autoarr();
test_string();
test_safethrow();
test_searchtree();
test_hashtable();
test_dtsod();
test_autoarr2();
// test_autoarr();
// test_string();
// test_safethrow();
// test_searchtree();
// test_hashtable();
// test_dtsod();
// test_autoarr2();
test_hash_collisions();
printf("\e[96m---------------------------------------\e[0m\n");
}
int main(){
setlocale(LC_ALL, "en-US.Unicode");
printf("\e[92mdtsod parser in c language!\e[97m\n");
printf("\e[92mkerep tests are starting!\e[97m\n");
optime("test_all",1,test_all());
printf("\e[0m\n");
return 0;

37
tests/test_hash.c Normal file
View File

@@ -0,0 +1,37 @@
#include "tests.h"
#include "../src/Hashtable/hash.h"
#include "../src/Autoarr/Autoarr.h"
#define AMOUNT_OF_TESTS 400000
#define test_hashf(hasht, hashf, tests_n)\
optime(#hashf,1,({\
printf("\e[94mfunction: " #hashf "\n");\
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
uint32 collisions=0;\
for(uint32 i=0;i<tests_n;i++){\
hasht h=hashf((uint8*)&i, 4);\
bool col=false;\
Autoarr_foreach(hashes,e,({\
if(e==h) {\
col=true;\
printf("\e[91mcollision: %lu\n", (uint64)h);\
break;\
}\
}));\
if(col) collisions++;\
else Autoarr_add(hashes,h);\
}\
printf("\e[92m%u collisions detected per %u numbers\n", collisions, tests_n);\
}))
void test_hash_collisions(){
optime("test_hash_collisions",1,({
printf("\e[96m--------[test_hash_collisions]--------\n");
char buf[]="iojihiojopijiugbjmoihftytryfdrh";
printf("\e[92mhashb_crc32: %x\n", hashb_crc32(buf,cptr_length(buf)));
printf("\e[92mhashb_sdbm32: %x\n", hashb_sdbm32(buf,cptr_length(buf)));
test_hashf(uint32, hashb_crc32, 20000);
test_hashf(uint32, hashb_sdbm32, 20000);
}));
}

View File

@@ -12,6 +12,7 @@ void test_string();
void test_dtsod();
void test_safethrow();
void test_autoarr2();
void test_hash_collisions();
#if __cplusplus
}
#endif