some fixes

This commit is contained in:
timerix 2023-06-08 15:59:52 +06:00
parent 080bbb28fd
commit 32ce7d3a70
11 changed files with 35 additions and 41 deletions

10
.vscode/launch.json vendored
View File

@ -42,16 +42,6 @@
"pipeArgs": ["-c"],
"pipeCwd": "${workspaceFolder}"
}
},
{
"name": "(msvc) Debug",
"type": "cppvsdbg",
"request": "launch",
"preLaunchTask": "build_dbg",
"program": "${workspaceFolder}\\bin\\kerep",
"cwd": "${workspaceFolder}\\bin",
"stopAtEntry": false,
"console": "integratedTerminal"
}
]
}

3
.vscode/tasks.json vendored
View File

@ -23,8 +23,7 @@
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": false,
"clean": true
"showReuseMessage": false
}
}
]

View File

@ -158,8 +158,8 @@ char* __cptr_concat(allocator_ptr al, u32 n, ...){
totality+=lengths[k];
}
free(strs);
free(lengths);
allocator_free(al, lengths);
allocator_free(al, strs);
return output;
}

View File

@ -28,7 +28,7 @@ void StackingAllocator_free(allocator_ptr _self, void* data_ptr){
assert(data_ptr!=NULL);
StackingAllocator* self = (StackingAllocator*)_self;
AllocationHeader* header_ptr = data_ptr - sizeof(AllocationHeader);
// TODO check is data_ptr pointer to the last allocation
// chunk is empty
if(curr_chunk->occupied_size==0){
// isn't the first chunk

View File

@ -13,7 +13,8 @@
tni=1; \
} else tni=2; \
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n", \
opname, t, tnames[tni]);
opname, t, tnames[tni]); \
fflush(stdout);
#ifdef CLOCK_REALTIME
/// executes codeblock and prints execution time

View File

@ -91,7 +91,7 @@ char *Unitype_toString(allocator_ptr al, Unitype u, u32 fmt)
void printuni(Unitype v)
{
LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
LinearAllocator_construct(&_al, 128);
allocator_ptr al=&_al.base;
char *s = Unitype_toString(al, v, 0);
fputs(s, stdout);

View File

@ -83,7 +83,6 @@ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
kp_fmt fmt=formats[i];
kprint_setColor(fmt);
tryLast(__next_toString(al, fmt, &objects[i]), maybeStr,
LinearAllocator_destruct(&_al);
kprint_setColor(kp_bgBlack|kp_fgGray););
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF)
throw("can't write string to stdout");

View File

@ -50,7 +50,7 @@ void kprintf(const char* format, ...){
va_start(vl, format);
u32 i=0;
LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
LinearAllocator_construct(&_al, 128);
allocator_ptr al=(allocator_ptr)&_al;
for(char c=format[i++]; c!=0; c=format[i++]){
// value format specifiers

View File

@ -29,6 +29,6 @@ void test_autoarrVsVector(){
_autoarrVsVector(64, 64);
_autoarrVsVector(32, 1024);
_autoarrVsVector(256, 256);
_autoarrVsVector(1024, 1024);
_autoarrVsVector(512, 4096);
);
}

View File

@ -1,26 +1,31 @@
#include "tests.h"
#include "../src/HashFunctions/hash.h"
#include "../src/Autoarr/Autoarr.h"
#include "../src/random/random.h"
#define SPEED_TESTS 1000000
#define COLLISION_TESTS 64000
char data[]="iojihi2ojo8la14nhvi3311pi[jiugbja38mo0ih6gfty88tryf-drh0lanvj03";
#define SPEED_TESTS 100000
#define COLLISION_TESTS 16000
char data[]="iojihiojopijiugbjmoihftytryfdrh";
#define rng() splitmix64_next(&rng_state)
#define test_hashfunc(hasht, hashf) { \
kprintf("\e[94mfunction: \e[92m" #hashf "\n"); \
hasht h=0; \
optime("speed test", 1, \
for(u32 i=0; i<SPEED_TESTS; i++) \
optime("speed test", SPEED_TESTS, \
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); \
Autoarr(hasht)* hashes=Autoarr_create(hasht,1,COLLISION_TESTS); \
splitmix64_state rng_state; \
splitmix64_construct(&rng_state, random_seedFromTime()); \
optime("collision test",1, \
u32 collisions=0; \
for(u64 i=0;i< COLLISION_TESTS;i++){ \
hasht h=hashb(hashf, (u8*)&i, sizeof(i)); \
u64 rn[8]; \
rn[0]=rng(); rn[1]=rng(); rn[2]=rng(); rn[3]=rng();\
rn[4]=rng(); rn[5]=rng(); rn[6]=rng(); rn[7]=rng();\
hasht h=hashb(hashf, rn, sizeof(rn)); \
bool col=false; \
Autoarr_foreach(hashes,e, \
if(e==h) { \
@ -40,7 +45,7 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
void test_hash_functions(){
optime("test_hash_functions",1,
kprintf("\e[96m--------[test_hash_functions]---------\n");
test_hashfunc(u32, hash_crc32);
test_hashfunc(u32, hash_sdbm32);
test_hashfunc(u32, hash_crc32);
);
}

View File

@ -24,20 +24,20 @@ void test_type_system();
static inline void test_all(){
kprintf("\e[97mkerep tests are starting!\n");
optime(__func__, 1,
// test_type_system();
test_type_system();
test_allocators();
// test_kprint_colors();
// test_kprint();
// test_safethrow();
// test_rng_algorithms();
// test_cptr();
// test_string();
test_kprint_colors();
test_kprint();
test_safethrow();
test_rng_algorithms();
test_cptr();
test_string();
// test_searchtree();
// test_autoarr();
// test_autoarrVsVector();
// test_hash_functions();
test_autoarr();
test_autoarrVsVector();
// test_hash_functions(); /* long test */
// test_hashtable();
// test_dtsod();*/
// test_dtsod();
kprintf("\e[96m--------------------------------------\e[0m\n");
);
}