diff --git a/DtsodC/src/Hashtable/Hashtable.c b/DtsodC/src/Hashtable/Hashtable.c index 331ab76..68da148 100644 --- a/DtsodC/src/Hashtable/Hashtable.c +++ b/DtsodC/src/Hashtable/Hashtable.c @@ -28,14 +28,27 @@ void Hashtable_free(Hashtable* 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))); - for(uint16 i=HT_HEIGHTS[ht->hein-1];ihein];i++) - ht->rows[i]=Autoarr2_create(KeyValuePair,4,16); +void Hashtable_resize(Hashtable* ht){ + Autoarr2(KeyValuePair)* newrows=malloc(HT_HEIGHTS[++ht->hein]*sizeof(Autoarr2(KeyValuePair))); + for(uint16 i=0;ihein];i++) + ht->rows[i]=Autoarr2_create(KeyValuePair,4,16); + for(uint16 i=0;ihein-1];i++){ + Autoarr2(KeyValuePair)* ar=ht->rows+i; + for(uint16 k=0;khein]; + Autoarr2(KeyValuePair)* newar=newrows+newrown; + Autoarr2_add(newar,p); + } } + ht->rows=newrows; +} + +Autoarr2(KeyValuePair)* getrow(Hashtable* ht, char* key){ + uint16 rown=ihash(key)%HT_HEIGHTS[ht->hein]; + if(rown>=HT_HEIGHTS[ht->hein]) + Hashtable_resize(ht); return ht->rows+rown; } diff --git a/DtsodC/src/base/mystr.c b/DtsodC/src/base/mystr.c index 915ee6e..a157d00 100644 --- a/DtsodC/src/base/mystr.c +++ b/DtsodC/src/base/mystr.c @@ -9,11 +9,10 @@ uint32 mystrlen(char* str){ //allocates new char[] and copies src there char* mystrcpy(char* src){ - uint32 len=mystrlen(src);dbg(len); + uint32 len=mystrlen(src); char* dst=malloc(len*sizeof(char)); while(len-->0) dst[len]=src[len]; - printf("dst: %s\n",dst); return dst; } diff --git a/DtsodC/src/main.c b/DtsodC/src/main.c index 4c11d95..c5c1c6e 100644 --- a/DtsodC/src/main.c +++ b/DtsodC/src/main.c @@ -6,8 +6,8 @@ int main(){ setlocale(LC_ALL, "en-US.Unicode"); printf("\e[92mdtsod parser in c language!\e[97m\n"); - //optime("test_all",1,{test_all();}); - test_hashtable(); + optime("test_all",1,{test_all();}); + //test_hashtable(); printf("\e[0m\n"); return 0; } diff --git a/DtsodC/src/tests/test_hashtable.c b/DtsodC/src/tests/test_hashtable.c index 5e91d07..0bb6bfc 100644 --- a/DtsodC/src/tests/test_hashtable.c +++ b/DtsodC/src/tests/test_hashtable.c @@ -14,7 +14,7 @@ void print_hashtable(Hashtable* ht){ void hashtable_fill(Hashtable* ht){ char* key=malloc(20); - for(uint32 i=0;i<255;i++){ + for(uint32 i=0;i<100;i++){ sprintf(key,"key__%u",i); Hashtable_add(ht,key,Uni(UInt32,i)); } @@ -23,7 +23,7 @@ void hashtable_fill(Hashtable* ht){ void hashtable_printval(Hashtable* ht){ char* key=malloc(20); - for(uint32 i=0;i<255;i++){ + for(uint32 i=0;i<100;i++){ sprintf(key,"key__%u",i); printuni(Hashtable_get(ht,key)); printf(" ");