another small optimization

This commit is contained in:
Timerix22 2022-02-23 21:13:11 +03:00
parent 56a97b14f9
commit 99da265217
5 changed files with 40 additions and 13 deletions

View File

@ -1,2 +1,31 @@
#include "DtsodV24.h"
Hashtable* __parse(const char* text, bool called_recursively){
Hashtable* dict=Hashtable_create();
/* char c;
char* ReadName(){
};
Unitype ReadValue(){
};
void SkipComment(){
};
while ((c=*text)){
char* n=ReadName();
Unitype v=ReadValue();
Hashtable_add(dict,n,v);
text++;
} */
return dict;
}
Hashtable* DtsodV24_parse(const char* text) { return __parse(text,false); }

View File

@ -1,3 +1,5 @@
#pragma once
#include "../base/base.h"
#include "../Hashtable/Hashtable.h"
Hashtable* DtsodV24_parse(const char* text);

View File

@ -62,11 +62,6 @@ Autoarr2(KeyValuePair)* getrow(Hashtable* ht, char* key, bool can_expand){
return ar;
}
//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 p){
Autoarr2_add(getrow(ht,p.key,true),p);
@ -104,9 +99,9 @@ bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output){
return u.type==Null;
}
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p){
/* 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)); }
void Hashtable_set(Hashtable* ht, char* key, Unitype u){ Hashtable_set_pair(ht,cpair(key,u)); } */

View File

@ -22,10 +22,12 @@ typedef struct Hashtable{
Hashtable* Hashtable_create();
void Hashtable_free(Hashtable* ht);
//amount of rows
uint32 Hashtable_height(Hashtable* ht);
//copies string and value to new KeyValuePair
KeyValuePair cpair(char* key, Unitype value);
//adds charptr and value to new KeyValuePair
//use mystrcpy() to create new string if needed
#define cpair(key,value) (KeyValuePair){key,value}
void Hashtable_add_pair(Hashtable* ht, KeyValuePair p);
@ -38,5 +40,6 @@ 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);
//not implemented yet
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p);
void Hashtable_set(Hashtable* ht, char* key, Unitype u);

View File

@ -42,21 +42,19 @@ void printrowgraph(Hashtable* ht){
}
void fill(Hashtable* ht){
char* key=malloc(20);
for(uint32 i=0;i<100000;i++){
char* key=malloc(12);
sprintf(key,"key__%u",i);
Hashtable_add(ht,key,Uni(UInt32,i));
}
free(key);
}
Unitype gett(Hashtable* ht){
char* key=malloc(20);
char* key=malloc(12);
Unitype u;
for(uint32 i=0;i<100000;i++){
sprintf(key,"key__%u",i);
u=Hashtable_get(ht,key);
//printuni(u); printf(" ");
}
free(key);
return u;