81
This commit is contained in:
parent
99c06d1b66
commit
c7a3fb10b5
@ -7,7 +7,7 @@ all: clear_c build test
|
||||
clear_c:
|
||||
clear
|
||||
clear_bin:
|
||||
@echo -e "\e[36m-------------[clear_bin]---------------\e[0m"
|
||||
@echo -e '\e[96m--------------[clear_bin]--------------\e[0m'
|
||||
touch $(OUTDIR)_.com
|
||||
rm $(OUTDIR)*.com
|
||||
|
||||
@ -16,14 +16,15 @@ clang: all
|
||||
|
||||
CMPARGS= -Wall $(SRC) -o $(OUTFILE)
|
||||
build:
|
||||
@echo -e "\e[36m-------------[build]---------------\e[0m"
|
||||
@echo -e '\n\e[96m----------------[build]----------------\e[0m'
|
||||
$(CMP) -O1 -flto $(CMPARGS)
|
||||
build_dbg:
|
||||
@echo -e "\e[36m-------------[build_dbg]---------------\e[0m"
|
||||
$(CMP) -O0 $(CMPARGS).dbg
|
||||
@echo -e '\n\e[96m--------------[build_dbg]--------------\e[0m'
|
||||
$(CMP) -O0 -g $(CMPARGS).dbg
|
||||
test:
|
||||
@echo -e "\e[36m-------------[test]----------------\e[0m"
|
||||
@echo -e '\n\e[96m----------------[test]-----------------\e[0m'
|
||||
$(OUTFILE)
|
||||
valgrind: clear_c build_dbg
|
||||
@echo -e "\e[36m-----------[valgrind]--------------\e[0m"
|
||||
valgrind -s --read-var-info=yes --fullpath-after=DtsodC/ $(OUTFILE).dbg
|
||||
@echo -e '\n\e[96m--------------[valgrind]---------------\e[0m'
|
||||
valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=DtsodC/ \
|
||||
--leak-check=full --show-leak-kinds=all $(OUTFILE).dbg
|
||||
|
||||
@ -9,6 +9,7 @@ struct Autoarr2_##type;\
|
||||
typedef struct {\
|
||||
void (*add)(struct Autoarr2_##type* ar, type element);\
|
||||
type (*get)(struct Autoarr2_##type* ar, uint32 index);\
|
||||
type* (*getptr)(struct Autoarr2_##type* ar, uint32 index);\
|
||||
void (*set)(struct Autoarr2_##type* ar, uint32 index, type element);\
|
||||
void (*clear)(struct Autoarr2_##type* ar);\
|
||||
} __functions_list_t_##type;\
|
||||
@ -24,6 +25,7 @@ typedef struct Autoarr2_##type{\
|
||||
\
|
||||
void __Autoarr2_add_##type(Autoarr2_##type* ar, type element);\
|
||||
type __Autoarr2_get_##type(Autoarr2_##type* ar, uint32 index);\
|
||||
type* __Autoarr2_getptr_##type(Autoarr2_##type* ar, uint32 index);\
|
||||
void __Autoarr2_set_##type(Autoarr2_##type* ar, uint32 index, type element);\
|
||||
void __Autoarr2_clear_##type(Autoarr2_##type* ar);\
|
||||
Autoarr2_##type __Autoarr2_create_##type(uint16 max_blocks_count, uint16 max_block_length);
|
||||
@ -34,6 +36,8 @@ Autoarr2_##type __Autoarr2_create_##type(uint16 max_blocks_count, uint16 max_blo
|
||||
autoarr->functions->add(autoarr, element)
|
||||
#define Autoarr2_get(autoarr, index)\
|
||||
autoarr->functions->get(autoarr,index)
|
||||
#define Autoarr2_getptr(autoarr, index)\
|
||||
autoarr->functions->getptr(autoarr,index)
|
||||
#define Autoarr2_set(autoarr, index, element)\
|
||||
autoarr->functions->set(autoarr, index, element)
|
||||
#define Autoarr2_clear(autoarr)\
|
||||
|
||||
@ -25,6 +25,11 @@ type __Autoarr2_get_##type(Autoarr2_##type* ar, uint32 index){\
|
||||
return ar->values[index/ar->max_block_length][index%ar->max_block_length];\
|
||||
}\
|
||||
\
|
||||
type* __Autoarr2_getptr_##type(Autoarr2_##type* ar, uint32 index){\
|
||||
if(index>=Autoarr2_length(ar)) throw(ERR_WRONGINDEX);\
|
||||
return ar->values[index/ar->max_block_length]+(index%ar->max_block_length);\
|
||||
}\
|
||||
\
|
||||
void __Autoarr2_set_##type(Autoarr2_##type* ar, uint32 index, type element){\
|
||||
if(index>=Autoarr2_length(ar)) throw(ERR_WRONGINDEX);\
|
||||
ar->values[index/ar->max_block_length][index%ar->max_block_length]=element;\
|
||||
@ -42,6 +47,7 @@ void __Autoarr2_clear_##type(Autoarr2_##type* ar){\
|
||||
__functions_list_t_##type __functions_list_##type={\
|
||||
&__Autoarr2_add_##type,\
|
||||
&__Autoarr2_get_##type,\
|
||||
&__Autoarr2_getptr_##type,\
|
||||
&__Autoarr2_set_##type,\
|
||||
&__Autoarr2_clear_##type\
|
||||
};\
|
||||
|
||||
@ -2,16 +2,34 @@
|
||||
|
||||
define_Autoarr2(KeyValuePair)
|
||||
|
||||
// amount of rows
|
||||
static const uint16 HT_HEIGHTS[]={61,631,3889,19441,65521};
|
||||
|
||||
|
||||
Hashtable* Hashtable_create(){
|
||||
Hashtable* ht=malloc(sizeof(Hashtable));
|
||||
ht->hein=HT_HEIGHTS[0];
|
||||
ht->hein=0;
|
||||
ht->rows=malloc(HT_HEIGHTS[0]*sizeof(Autoarr2(KeyValuePair)));
|
||||
for(uint16 i;i<HT_HEIGHTS[0];i++)
|
||||
for(uint16 i=0;i<HT_HEIGHTS[0];i++)
|
||||
ht->rows[i]=Autoarr2_create(KeyValuePair,4,16);
|
||||
return ht;
|
||||
}
|
||||
|
||||
static Autoarr2(KeyValuePair)* getrow(Hashtable* ht,char* key){
|
||||
void Hashtable_free(Hashtable* ht){
|
||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein];i++){
|
||||
Autoarr2(KeyValuePair)* ar=(Autoarr2(KeyValuePair)*)(ht->rows+i);
|
||||
for(uint32 i=0;i<Autoarr2_length(ar);i++)
|
||||
free(Autoarr2_getptr(ar,i)->key);
|
||||
Autoarr2_clear(ar);
|
||||
}
|
||||
free(ht->rows);
|
||||
free(ht);
|
||||
}
|
||||
|
||||
uint32 Hashtable_height(Hashtable* ht){ return HT_HEIGHTS[ht->hein]; }
|
||||
|
||||
Autoarr2(KeyValuePair)* getrow(Hashtable* ht, char* key){
|
||||
|
||||
uint16 rown=HT_HEIGHTS[ht->hein]%ihash(key);
|
||||
if(rown>=HT_HEIGHTS[ht->hein]){
|
||||
ht->rows=realloc(ht->rows,HT_HEIGHTS[++ht->hein]*sizeof(Autoarr2(KeyValuePair)));
|
||||
@ -21,47 +39,28 @@ static Autoarr2(KeyValuePair)* getrow(Hashtable* ht,char* key){
|
||||
return ht->rows+rown;
|
||||
}
|
||||
|
||||
void Hashtable_free(Hashtable* ht){
|
||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein];i++)
|
||||
Autoarr2_clear(((Autoarr2(KeyValuePair)*)(ht->rows+i)));
|
||||
free(ht->rows);
|
||||
free(ht);
|
||||
//copies string and value to new KeyValuePair
|
||||
KeyValuePair cpair(char* key, Unitype value){
|
||||
return (KeyValuePair){.key=mystrcpy(key),.value=value};
|
||||
}
|
||||
|
||||
void Hashtable_add_pair(Hashtable* ht, KeyValuePair pair){
|
||||
Autoarr2_add(getrow(ht,pair.key),pair);
|
||||
|
||||
void Hashtable_add_pair(Hashtable* ht, KeyValuePair p){
|
||||
Autoarr2_add(getrow(ht,p.key),p);
|
||||
}
|
||||
void Hashtable_add(Hashtable* ht, char* key, Unitype u){
|
||||
Hashtable_add_pair(ht,cpair(key,u));
|
||||
}
|
||||
|
||||
//returns length of string (including \0)
|
||||
uint32 mystrlen(char* str){
|
||||
uint32 len=0;
|
||||
while(*(str++)) len++;
|
||||
return len++;
|
||||
}
|
||||
|
||||
//allocates new char[] and copies src there
|
||||
char* mystrcpy(char* src){
|
||||
uint32 len=mystrlen(src);
|
||||
char* dst=malloc(len*sizeof(char));
|
||||
while(--len<0)
|
||||
dst[len]=src[len];
|
||||
return dst;
|
||||
}
|
||||
|
||||
//compares two strings, NullPtr-friendly
|
||||
bool mystrcmp(char* key0, char* key1){
|
||||
if(!key0) return key1 ? 0 : 1;
|
||||
else if(!key1) return 0;
|
||||
while(*key0&&*key1){
|
||||
if(*key0!=*key1) return 0;
|
||||
key0++;
|
||||
key1++;
|
||||
//returns null or pointer to value in hashtable
|
||||
Unitype* Hashtable_getptr(Hashtable* ht, char* key){
|
||||
Autoarr2(KeyValuePair)* ar=getrow(ht,key);
|
||||
uint32 arlen=Autoarr2_length(ar);
|
||||
for(uint32 i=0;i<arlen;i++){
|
||||
KeyValuePair* p=Autoarr2_getptr(ar,i);
|
||||
if(mystrcmp(key,p->key)) return &p->value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Hashtable_add(Hashtable* ht, char* key, Unitype value){
|
||||
Hashtable_add_pair(ht,(KeyValuePair){key,value});
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Unitype Hashtable_get(Hashtable* ht, char* key){
|
||||
@ -73,16 +72,18 @@ Unitype Hashtable_get(Hashtable* ht, char* key){
|
||||
}
|
||||
return (Unitype){.type=Null,.VoidPtr=NULL};
|
||||
}
|
||||
|
||||
KeyValuePair Hashtable_get_pair(Hashtable* ht, char* key){
|
||||
return (KeyValuePair){
|
||||
.key=key,
|
||||
.value=Hashtable_get(ht,key)
|
||||
};
|
||||
return cpair(key,Hashtable_get(ht,key));
|
||||
}
|
||||
|
||||
bool Hashtable_try_get(Hashtable* ht, char* key,Unitype* output){
|
||||
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output){
|
||||
Unitype u=Hashtable_get(ht,key);
|
||||
*output=u;
|
||||
return u.type==Null;
|
||||
}
|
||||
|
||||
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p){
|
||||
if(Hashtable_try_get(ht,p.key, NULL)){
|
||||
|
||||
}
|
||||
}
|
||||
void Hashtable_set(Hashtable* ht, char* key, Unitype u){ Hashtable_set_pair(ht,cpair(key,u)); }
|
||||
|
||||
@ -9,6 +9,9 @@ typedef struct KeyValuePair{
|
||||
Unitype value;
|
||||
} KeyValuePair;
|
||||
|
||||
//copies string and value to new KeyValuePair
|
||||
KeyValuePair cpair(char* key, Unitype value);
|
||||
|
||||
declare_Autoarr2(KeyValuePair)
|
||||
|
||||
typedef struct Hashtable{
|
||||
@ -16,5 +19,24 @@ typedef struct Hashtable{
|
||||
Autoarr2(KeyValuePair)* rows; // Autoarr[height]
|
||||
} Hashtable;
|
||||
|
||||
// amount of rows
|
||||
const uint16 HT_HEIGHTS[]={61,631,3889,19441,65521};
|
||||
Hashtable* Hashtable_create();
|
||||
void Hashtable_free(Hashtable* ht);
|
||||
|
||||
uint32 Hashtable_height(Hashtable* ht);
|
||||
|
||||
//copies string and value to new KeyValuePair
|
||||
KeyValuePair cpair(char* key, Unitype value);
|
||||
|
||||
|
||||
void Hashtable_add_pair(Hashtable* ht, KeyValuePair p);
|
||||
void Hashtable_add(Hashtable* ht, char* key, Unitype u);
|
||||
|
||||
//returns null or pointer to value in hashtable
|
||||
Unitype* Hashtable_getptr(Hashtable* ht, char* key);
|
||||
|
||||
Unitype Hashtable_get(Hashtable* ht, char* key);
|
||||
KeyValuePair Hashtable_get_pair(Hashtable* ht, char* key);
|
||||
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output);
|
||||
|
||||
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p);
|
||||
void Hashtable_set(Hashtable* ht, char* key, Unitype u);
|
||||
@ -3,7 +3,7 @@
|
||||
uint32 ihash(char *str){
|
||||
uint32 hash=5381;
|
||||
for (char c=*str;c;c=*(++str))
|
||||
hash=((hash<<5)+hash)+c; //hash=hash*33^c
|
||||
hash=((hash<<5)+hash)+c;
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "std.h"
|
||||
#include "types.h"
|
||||
#include "errors.h"
|
||||
#include "mystr.h"
|
||||
|
||||
// sleep function based on std nanosleep()
|
||||
void fsleep(float sec);
|
||||
|
||||
30
DtsodC/src/base/mystr.c
Normal file
30
DtsodC/src/base/mystr.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "base.h"
|
||||
|
||||
//returns length of string (including \0)
|
||||
uint32 mystrlen(char* str){
|
||||
uint32 len=0;
|
||||
while(*(str++)) len++;
|
||||
return ++len;
|
||||
}
|
||||
|
||||
//allocates new char[] and copies src there
|
||||
char* mystrcpy(char* src){
|
||||
uint32 len=mystrlen(src);dbg(len);
|
||||
char* dst=malloc(len*sizeof(char));
|
||||
while(len-->0)
|
||||
dst[len]=src[len];
|
||||
printf("dst: %s\n",dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
//compares two strings, NullPtr-friendly
|
||||
bool mystrcmp(char* key0, char* key1){
|
||||
if(!key0) return key1 ? 0 : 1;
|
||||
else if(!key1) return 0;
|
||||
while(*key0&&*key1){
|
||||
if(*key0!=*key1) return 0;
|
||||
key0++;
|
||||
key1++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
14
DtsodC/src/base/mystr.h
Normal file
14
DtsodC/src/base/mystr.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
|
||||
//returns length of string (including \0)
|
||||
uint32 mystrlen(char* str);
|
||||
|
||||
|
||||
//allocates new char[] and copies src there
|
||||
char* mystrcpy(char* src);
|
||||
|
||||
//compares two strings, NullPtr-friendly
|
||||
bool mystrcmp(char* key0, char* key1);
|
||||
@ -40,3 +40,5 @@ typedef struct Unitype{
|
||||
void* VoidPtr;
|
||||
};
|
||||
} Unitype;
|
||||
|
||||
#define Uni(TYPE,VAL) (Unitype){.type=TYPE,.TYPE=VAL}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
#include "base/base.h"
|
||||
#include "tests/tests.h"
|
||||
#include "Autoarr/Autoarr2.h"
|
||||
#include "Hashtable/Hashtable.h"
|
||||
|
||||
int main(){
|
||||
setlocale(LC_ALL, "en-US.Unicode");
|
||||
printf("\e[92mdtsod parser in c language!\e[97m\n");
|
||||
optime({test_all();});
|
||||
//optime("test_all",1,{test_all();});
|
||||
test_hashtable();
|
||||
printf("\e[0m\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../base/base.h"
|
||||
|
||||
const wchar_t* slimak =
|
||||
U" ▄▄▄ \n"
|
||||
"▄▀░▄░▀▄ \n"
|
||||
"█░█▄▀░█ \n"
|
||||
"█░▀▄▄▀█▄█▄▀ \n"
|
||||
"▄▄█▄▄▄▄███▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
"█░█░▄▀░░█ \n"
|
||||
"█░▀▄▄▄▀░█▄█▄▄▀ \n"
|
||||
"▄▄█▄▄▄▄███▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
"█░█░▄▀░░█ \n"
|
||||
"█░▀▄▄▄▀░█▄█▄▄▀ \n"
|
||||
"▄▄█▄▄▄▄████▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" ▄▀░▄░▀▄ \n"
|
||||
" █░█▄▀░█ \n"
|
||||
" █░▀▄▄▀█▄█▄▀ \n"
|
||||
" ▄▄█▄▄▄▄███▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
" █░█░▄▀░░█ \n"
|
||||
" █░▀▄▄▄▀░█▄█▄▄▀ \n"
|
||||
" ▄▄█▄▄▄▄███▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
" █░█░▄▀░░█ \n"
|
||||
" █░▀▄▄▄▀░█▄█▄▄▀ \n"
|
||||
" ▄▄█▄▄▄▄████▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" ▄▀░▄░▀▄ \n"
|
||||
" █░█▄▀░█ \n"
|
||||
" █░▀▄▄▀█▄█▄▀ \n"
|
||||
" ▄▄█▄▄▄▄███▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
" █░█░▄▀░░█ \n"
|
||||
" █░▀▄▄▄▀░█▄█▄▄▀\n"
|
||||
" ▄▄█▄▄▄▄███▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" █▀▄▄░▀█ \n"
|
||||
" █░█░▄▀░░█ \n"
|
||||
" █░▀▄▄▄▀░█▄█▄▄▀\n"
|
||||
" ▄▄█▄▄▄▄████▀▀ \n"
|
||||
" ▄▄▄ \n"
|
||||
" ▄▀░▄░▀▄ \n"
|
||||
" █░█▄▀░█ \n"
|
||||
" █░▀▄▄▀█▄█▄▀\n"
|
||||
" ▄▄█▄▄▄▄███▀ \n";
|
||||
@ -2,7 +2,7 @@
|
||||
#include "../Autoarr/Autoarr2.h"
|
||||
|
||||
static void printautoarr(Autoarr2(uint16)* ar){
|
||||
printf("\e[94mAUTOARR:%lu\n"
|
||||
printf("\e[94mAutoarr2(uint16): %lu\n"
|
||||
" max_blocks_count: %u\n"
|
||||
" blocks_count: %u\n"
|
||||
" max_block_length: %u\n"
|
||||
@ -35,16 +35,18 @@ static void printallval(Autoarr2(uint16)* ar){
|
||||
}
|
||||
|
||||
void test_autoarr2(){
|
||||
printf("\e[96m------------[test_autoarr2]-------------\n");
|
||||
Autoarr2(uint16) ar=Autoarr2_create(uint16,10,16);
|
||||
printf("\e[92mautoarr created\n");
|
||||
fillar(&ar);
|
||||
printf("\e[92mautoarr filled up\n");
|
||||
printautoarr(&ar);
|
||||
printallval(&ar);
|
||||
resetar(&ar);
|
||||
printf("\e[92mautoarr values reset\n");
|
||||
printallval(&ar);
|
||||
Autoarr2_clear(((&ar)));
|
||||
printf("\e[92mautoarr cleared\n");
|
||||
optime("test_autoarr2",1,({
|
||||
printf("\e[96m------------[test_autoarr2]------------\n");
|
||||
Autoarr2(uint16) ar=Autoarr2_create(uint16,10,16);
|
||||
printf("\e[92mautoarr created\n");
|
||||
fillar(&ar);
|
||||
printf("\e[92mautoarr filled up\n");
|
||||
printautoarr(&ar);
|
||||
printallval(&ar);
|
||||
resetar(&ar);
|
||||
printf("\e[92mautoarr values reset\n");
|
||||
printallval(&ar);
|
||||
Autoarr2_clear(((&ar)));
|
||||
printf("\e[92mautoarr cleared\n");
|
||||
}));
|
||||
}
|
||||
|
||||
46
DtsodC/src/tests/test_hashtable.c
Normal file
46
DtsodC/src/tests/test_hashtable.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include "tests.h"
|
||||
#include "../Hashtable/Hashtable.h"
|
||||
|
||||
void print_hashtable(Hashtable* ht){
|
||||
printf("\e[94mHashtable:%lu\n"
|
||||
" hein: %u\n"
|
||||
" height: %u\n"
|
||||
" rows: %p\n",
|
||||
sizeof(Hashtable),
|
||||
ht->hein,
|
||||
Hashtable_height(ht),
|
||||
ht->rows);
|
||||
}
|
||||
|
||||
void hashtable_fill(Hashtable* ht){
|
||||
char* key=malloc(20);
|
||||
for(uint32 i=0;i<255;i++){
|
||||
sprintf(key,"key__%u",i);
|
||||
Hashtable_add(ht,key,Uni(UInt32,i));
|
||||
}
|
||||
free(key);
|
||||
}
|
||||
|
||||
void hashtable_printval(Hashtable* ht){
|
||||
char* key=malloc(20);
|
||||
for(uint32 i=0;i<255;i++){
|
||||
sprintf(key,"key__%u",i);
|
||||
printuni(Hashtable_get(ht,key));
|
||||
printf(" ");
|
||||
}
|
||||
free(key);
|
||||
}
|
||||
|
||||
|
||||
void test_hashtable(void){
|
||||
optime("test_hashtable",1,({
|
||||
printf("\e[96m-----------[test_hashtable]------------\n");
|
||||
Hashtable* ht=Hashtable_create();
|
||||
print_hashtable(ht);
|
||||
hashtable_fill(ht);
|
||||
printf("\e[92mhashtable filled\n\e[90m");
|
||||
hashtable_printval(ht);
|
||||
Hashtable_free(ht);
|
||||
printf("\n\e[92mhashtable freed\n");
|
||||
}));
|
||||
}
|
||||
@ -20,50 +20,52 @@ void printstnode(STNode* node){
|
||||
}
|
||||
|
||||
void test_searchtree(){
|
||||
printf("\e[96m-----------[test_searchtree]-----------\n");
|
||||
STNode* node=STNode_create();
|
||||
printf("\e[92mnode created\n");
|
||||
printf("push:\e[94m\n ");
|
||||
Unitype u={.type=Int16,.Int16=-3};
|
||||
printuni(u);
|
||||
ST_push(node,"type", u);
|
||||
printf(" -> type\n ");
|
||||
u=(Unitype){.type=Int16,.Int16=25};
|
||||
printuni(u);
|
||||
ST_push(node,"time", u);
|
||||
printf(" -> time\n ");
|
||||
u=(Unitype){.type=Double,.Double=-542.00600};
|
||||
printuni(u);
|
||||
ST_push(node,"author_id", u);
|
||||
printf(" -> author_id\n ");
|
||||
u=(Unitype){.type=Int64,.Int64=-31255};
|
||||
printuni(u);
|
||||
ST_push(node,"channel_id", u);
|
||||
printf(" -> channel_id\n ");
|
||||
u=(Unitype){.type=Float,.Float=32.2004};
|
||||
printuni(u);
|
||||
ST_push(node,"message_id", u);
|
||||
printf(" -> message_id\n ");
|
||||
u=(Unitype){.type=Int8Ptr,.VoidPtr=malloc(1)};
|
||||
printuni(u);
|
||||
ST_push(node,"text", u);
|
||||
printf(" -> text\n");
|
||||
printf("\e[92mpull:\e[94m");
|
||||
printf("\n type -> ");
|
||||
printuni(ST_pull(node,"type"));
|
||||
printf("\n time -> ");
|
||||
printuni(ST_pull(node,"time"));
|
||||
printf("\n author_id -> ");
|
||||
printuni(ST_pull(node,"author_id"));
|
||||
printf("\n channel_id -> ");
|
||||
printuni(ST_pull(node,"channel_id"));
|
||||
printf("\n message_id -> ");
|
||||
printuni(ST_pull(node,"message_id"));
|
||||
printf("\n text -> ");
|
||||
printuni(ST_pull(node,"text"));
|
||||
printf("\n");
|
||||
printf("\e[92mfirst node: ");
|
||||
printstnode(node);
|
||||
STNode_free(node);
|
||||
printf("\e[92mnode deleted\n");
|
||||
optime("test_searchtree",1,({
|
||||
printf("\e[96m-----------[test_searchtree]-----------\n");
|
||||
STNode* node=STNode_create();
|
||||
printf("\e[92mnode created\n");
|
||||
printf("push:\e[94m\n ");
|
||||
Unitype u={.type=Int16,.Int16=-3};
|
||||
printuni(u);
|
||||
ST_push(node,"type", u);
|
||||
printf(" -> type\n ");
|
||||
u=(Unitype){.type=Int16,.Int16=25};
|
||||
printuni(u);
|
||||
ST_push(node,"time", u);
|
||||
printf(" -> time\n ");
|
||||
u=(Unitype){.type=Double,.Double=-542.00600};
|
||||
printuni(u);
|
||||
ST_push(node,"author_id", u);
|
||||
printf(" -> author_id\n ");
|
||||
u=(Unitype){.type=Int64,.Int64=-31255};
|
||||
printuni(u);
|
||||
ST_push(node,"channel_id", u);
|
||||
printf(" -> channel_id\n ");
|
||||
u=(Unitype){.type=Float,.Float=32.2004};
|
||||
printuni(u);
|
||||
ST_push(node,"message_id", u);
|
||||
printf(" -> message_id\n ");
|
||||
u=(Unitype){.type=Int8Ptr,.VoidPtr=malloc(1)};
|
||||
printuni(u);
|
||||
ST_push(node,"text", u);
|
||||
printf(" -> text\n");
|
||||
printf("\e[92mpull:\e[94m");
|
||||
printf("\n type -> ");
|
||||
printuni(ST_pull(node,"type"));
|
||||
printf("\n time -> ");
|
||||
printuni(ST_pull(node,"time"));
|
||||
printf("\n author_id -> ");
|
||||
printuni(ST_pull(node,"author_id"));
|
||||
printf("\n channel_id -> ");
|
||||
printuni(ST_pull(node,"channel_id"));
|
||||
printf("\n message_id -> ");
|
||||
printuni(ST_pull(node,"message_id"));
|
||||
printf("\n text -> ");
|
||||
printuni(ST_pull(node,"text"));
|
||||
printf("\n");
|
||||
printf("\e[92mfirst node: ");
|
||||
printstnode(node);
|
||||
STNode_free(node);
|
||||
printf("\e[92mnode deleted\n");
|
||||
}));
|
||||
}
|
||||
|
||||
@ -29,7 +29,8 @@ void printuni(Unitype v){
|
||||
}
|
||||
|
||||
void test_all(void){
|
||||
optime({test_searchtree();});
|
||||
optime({test_autoarr2();});
|
||||
printf("\e[96m---------------------------------------\n");
|
||||
test_searchtree();
|
||||
test_autoarr2();
|
||||
test_hashtable();
|
||||
printf("\e[96m---------------------------------------\e[0m\n");
|
||||
}
|
||||
@ -7,12 +7,14 @@ void printuni(Unitype v);
|
||||
void test_all(void);
|
||||
void test_searchtree(void);
|
||||
void test_autoarr2(void);
|
||||
void test_hashtable(void);
|
||||
|
||||
// executes codeblock and prints execution time
|
||||
// should be used like optime({foo();}), because just optime(foo()) works slower
|
||||
#define optime(codeblock) ({\
|
||||
#define optime(opname,repeats,codeblock) ({\
|
||||
clock_t start=clock();\
|
||||
(codeblock);\
|
||||
for(uint64 ___OPREP=0;___OPREP<repeats;___OPREP++)\
|
||||
(codeblock);\
|
||||
clock_t stop=clock();\
|
||||
printf("\e[93m%li\n",(stop-start));\
|
||||
printf("\e[93moperation %s took \e[94m%ld \e[93mticks\n",opname,(stop-start));\
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user