simplified Autoarr/Hashtable _foreach
This commit is contained in:
@@ -21,7 +21,7 @@ i64 _autoarrVsVector(u16 blockCount, u16 blockLength){
|
||||
}
|
||||
|
||||
void test_autoarrVsVector(){
|
||||
optime(__func__, 1, ({
|
||||
optime(__func__, 1,
|
||||
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
|
||||
_autoarrVsVector(4, 16);
|
||||
_autoarrVsVector(16, 64);
|
||||
@@ -30,5 +30,5 @@ void test_autoarrVsVector(){
|
||||
_autoarrVsVector(32, 1024);
|
||||
_autoarrVsVector(256, 256);
|
||||
_autoarrVsVector(1024, 1024);
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ static void printallval(Autoarr(u16)* ar){
|
||||
}
|
||||
|
||||
void test_autoarr(){
|
||||
optime("test_autoarr",1,({
|
||||
optime("test_autoarr",1,
|
||||
kprintf("\e[96m------------[test_autoarr]------------\n");
|
||||
Autoarr(u16)* ar=Autoarr_create(u16,10,16);
|
||||
kprintf("\e[92mautoarr created\n");
|
||||
@@ -49,5 +49,5 @@ void test_autoarr(){
|
||||
printallval(ar);
|
||||
Autoarr_free(ar, true);
|
||||
kprintf("\e[92mautoarr deleted\n");
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,50 +16,50 @@ const char text[]=
|
||||
|
||||
void print_dtsod(Hashtable* dtsod){
|
||||
kprintf("\e[92m");
|
||||
Hashtable_foreach(dtsod, p,({
|
||||
Hashtable_foreach(dtsod, p,
|
||||
printkvp(p);
|
||||
if(p.value.typeId==ktid_ptrName(Hashtable)){
|
||||
kprintf(": {\n");
|
||||
Hashtable* sub=p.value.VoidPtr;
|
||||
Hashtable_foreach(sub, _p,({
|
||||
Hashtable_foreach(sub, _p,
|
||||
kprintf(" ");
|
||||
printkvp(_p);
|
||||
kprintf("\n");
|
||||
}));
|
||||
);
|
||||
kprintf("}");
|
||||
}
|
||||
kprintf("\n");
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
void test_dtsod(){
|
||||
optime(__func__,1,({
|
||||
optime(__func__,1,
|
||||
kprintf("\e[96m-------------[test_dtsod]-------------\n");
|
||||
Hashtable* dtsod;
|
||||
char* s;
|
||||
|
||||
optime("deserialize",1,({
|
||||
optime("deserialize",1,
|
||||
tryLast(DtsodV24_deserialize(text),r)
|
||||
dtsod=r.value.VoidPtr;
|
||||
}));
|
||||
);
|
||||
print_dtsod(dtsod);
|
||||
|
||||
optime("serialize",1,({
|
||||
optime("serialize",1,
|
||||
tryLast(DtsodV24_serialize(dtsod),r)
|
||||
s=r.value.VoidPtr;
|
||||
}));
|
||||
);
|
||||
DtsodV24_free(dtsod);
|
||||
kprintf("\e[92m%s",s);
|
||||
|
||||
optime("reserialize",10,({
|
||||
optime("reserialize",10,
|
||||
tryLast(DtsodV24_deserialize(s),r)
|
||||
dtsod=r.value.VoidPtr;
|
||||
free(s);
|
||||
tryLast(DtsodV24_serialize(dtsod),rr)
|
||||
s=rr.value.VoidPtr;
|
||||
DtsodV24_free(dtsod);
|
||||
}));
|
||||
);
|
||||
|
||||
free(s);
|
||||
}));
|
||||
);
|
||||
}
|
||||
@@ -8,39 +8,39 @@
|
||||
|
||||
char data[]="iojihiojopijiugbjmoihftytryfdrh";
|
||||
|
||||
#define test_hashfunc(hasht, hashf)({ \
|
||||
#define test_hashfunc(hasht, hashf) { \
|
||||
kprintf("\e[94mfunction: \e[92m" #hashf "\n"); \
|
||||
hasht h=0; \
|
||||
optime("speed test", 1, ({ \
|
||||
optime("speed test", 1, \
|
||||
for(u32 i=0; i<SPEED_TESTS; i++) \
|
||||
h=hashf(h, data, sizeof(data)); \
|
||||
})); \
|
||||
); \
|
||||
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/ \
|
||||
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768); \
|
||||
optime("collision test",1,({ \
|
||||
optime("collision test",1, \
|
||||
u32 collisions=0; \
|
||||
for(u64 i=0;i< COLLISION_TESTS;i++){ \
|
||||
hasht h=hashb(hashf, (u8*)&i, sizeof(i)); \
|
||||
bool col=false; \
|
||||
Autoarr_foreach(hashes,e,({ \
|
||||
Autoarr_foreach(hashes,e, \
|
||||
if(e==h) { \
|
||||
col=true; \
|
||||
break; \
|
||||
} \
|
||||
})); \
|
||||
); \
|
||||
if(col) collisions++; \
|
||||
else Autoarr_add(hashes,h); \
|
||||
} \
|
||||
kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS); \
|
||||
})); \
|
||||
); \
|
||||
Autoarr_free(hashes, true); \
|
||||
kprintf("\e[96m--------------------------------------\n"); \
|
||||
})
|
||||
}
|
||||
|
||||
void test_hash_functions(){
|
||||
optime("test_hash_functions",1,({
|
||||
optime("test_hash_functions",1,
|
||||
kprintf("\e[96m--------[test_hash_functions]---------\n");
|
||||
test_hashfunc(u32, hash_crc32);
|
||||
test_hashfunc(u32, hash_sdbm32);
|
||||
}));
|
||||
);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ Unitype gett(Hashtable* ht){
|
||||
|
||||
|
||||
void test_hashtable(){
|
||||
optime("test_hashtable",1,({
|
||||
optime("test_hashtable",1,
|
||||
kprintf("\e[96m-----------[test_hashtable]-----------\n");
|
||||
Hashtable* ht=Hashtable_create();
|
||||
kprintf("\e[92mhashtable created\n");
|
||||
@@ -73,5 +73,5 @@ void test_hashtable(){
|
||||
print_hashtable(ht);
|
||||
Hashtable_free(ht);
|
||||
kprintf("\e[92mhashtable freed\n");
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "../src/random/krandom.h"
|
||||
|
||||
|
||||
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){ \
|
||||
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO) { \
|
||||
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n"); \
|
||||
void* s= ALG##_init(0); \
|
||||
u##VALUE_SIZE r=ALG##_next(s); \
|
||||
@@ -20,7 +20,7 @@
|
||||
}
|
||||
|
||||
void test_rng_algorithms(){
|
||||
optime("test_rng_algorithms",1,({
|
||||
optime("test_rng_algorithms",1,
|
||||
kprintf("\e[96m--------[test_rng_algorithms]---------\n");
|
||||
// for ALG32
|
||||
// xoroshiro64
|
||||
@@ -41,5 +41,5 @@ void test_rng_algorithms(){
|
||||
test_alg(xoshiro256starstar, 64, 11091344671253066420ULL)
|
||||
// splitmix64
|
||||
test_alg(splitmix64, 64, 16294208416658607535ULL)
|
||||
}));
|
||||
);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ Maybe a(){ try(b(),_,;) return MaybeNull; }
|
||||
|
||||
void test_safethrow(){
|
||||
kprintf("\e[96m-----------[test_safethrow]-----------\n");
|
||||
optime("test_safethrow", 1, ({
|
||||
optime("test_safethrow", 1,
|
||||
Maybe e=test_maybe();
|
||||
kprintf("\e[94mthrow_error:\n\e[92m");
|
||||
printMaybe(e);
|
||||
@@ -39,5 +39,5 @@ void test_safethrow(){
|
||||
e=a();
|
||||
printMaybe(e);
|
||||
Maybe_free(e);
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void printstnode(STNode* node){
|
||||
}
|
||||
|
||||
void test_searchtree(){
|
||||
optime("test_searchtree",1,({
|
||||
optime("test_searchtree",1,
|
||||
kprintf("\e[96m-----------[test_searchtree]----------\n");
|
||||
STNode* node=STNode_create();
|
||||
kprintf("\e[92mnode created\n");
|
||||
@@ -70,5 +70,5 @@ void test_searchtree(){
|
||||
printstnode(node);
|
||||
STNode_free(node);
|
||||
kprintf("\e[92mnode deleted\n");
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "../src/String/string.h"
|
||||
|
||||
void test_string(){
|
||||
optime(__func__,1,({
|
||||
optime(__func__,1,
|
||||
kprintf("\e[96m-------------[test_string]------------\n");
|
||||
char c[]="0123456789abcdef";
|
||||
string s={.ptr=c, .length=cptr_length(c)};
|
||||
@@ -10,5 +10,5 @@ void test_string(){
|
||||
char* p=string_extract(s);
|
||||
kprintf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p);
|
||||
free(p);
|
||||
}));
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ void test_type_system();
|
||||
|
||||
inline void test_all(){
|
||||
kprintf("\e[97mkerep tests are starting!\n");
|
||||
optime(__func__, 1, ({
|
||||
optime(__func__, 1,
|
||||
test_type_system();
|
||||
test_string();
|
||||
test_safethrow();
|
||||
@@ -35,7 +35,7 @@ inline void test_all(){
|
||||
test_hashtable();
|
||||
test_dtsod();
|
||||
kprintf("\e[96m--------------------------------------\e[0m\n");
|
||||
}));
|
||||
);
|
||||
}
|
||||
|
||||
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
|
||||
|
||||
Reference in New Issue
Block a user