another small optimization
This commit is contained in:
parent
56a97b14f9
commit
99da265217
@ -1,2 +1,31 @@
|
|||||||
#include "DtsodV24.h"
|
#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); }
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../base/base.h"
|
#include "../base/base.h"
|
||||||
|
#include "../Hashtable/Hashtable.h"
|
||||||
|
|
||||||
|
Hashtable* DtsodV24_parse(const char* text);
|
||||||
|
|||||||
@ -62,11 +62,6 @@ Autoarr2(KeyValuePair)* getrow(Hashtable* ht, char* key, bool can_expand){
|
|||||||
return ar;
|
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){
|
void Hashtable_add_pair(Hashtable* ht, KeyValuePair p){
|
||||||
Autoarr2_add(getrow(ht,p.key,true),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;
|
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)){
|
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)); } */
|
||||||
|
|||||||
@ -22,10 +22,12 @@ typedef struct Hashtable{
|
|||||||
Hashtable* Hashtable_create();
|
Hashtable* Hashtable_create();
|
||||||
void Hashtable_free(Hashtable* ht);
|
void Hashtable_free(Hashtable* ht);
|
||||||
|
|
||||||
|
//amount of rows
|
||||||
uint32 Hashtable_height(Hashtable* ht);
|
uint32 Hashtable_height(Hashtable* ht);
|
||||||
|
|
||||||
//copies string and value to new KeyValuePair
|
//adds charptr and value to new KeyValuePair
|
||||||
KeyValuePair cpair(char* key, Unitype value);
|
//use mystrcpy() to create new string if needed
|
||||||
|
#define cpair(key,value) (KeyValuePair){key,value}
|
||||||
|
|
||||||
|
|
||||||
void Hashtable_add_pair(Hashtable* ht, KeyValuePair p);
|
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);
|
KeyValuePair Hashtable_get_pair(Hashtable* ht, char* key);
|
||||||
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output);
|
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output);
|
||||||
|
|
||||||
|
//not implemented yet
|
||||||
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p);
|
void Hashtable_set_pair(Hashtable* ht, KeyValuePair p);
|
||||||
void Hashtable_set(Hashtable* ht, char* key, Unitype u);
|
void Hashtable_set(Hashtable* ht, char* key, Unitype u);
|
||||||
@ -42,21 +42,19 @@ void printrowgraph(Hashtable* ht){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fill(Hashtable* ht){
|
void fill(Hashtable* ht){
|
||||||
char* key=malloc(20);
|
|
||||||
for(uint32 i=0;i<100000;i++){
|
for(uint32 i=0;i<100000;i++){
|
||||||
|
char* key=malloc(12);
|
||||||
sprintf(key,"key__%u",i);
|
sprintf(key,"key__%u",i);
|
||||||
Hashtable_add(ht,key,Uni(UInt32,i));
|
Hashtable_add(ht,key,Uni(UInt32,i));
|
||||||
}
|
}
|
||||||
free(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Unitype gett(Hashtable* ht){
|
Unitype gett(Hashtable* ht){
|
||||||
char* key=malloc(20);
|
char* key=malloc(12);
|
||||||
Unitype u;
|
Unitype u;
|
||||||
for(uint32 i=0;i<100000;i++){
|
for(uint32 i=0;i<100000;i++){
|
||||||
sprintf(key,"key__%u",i);
|
sprintf(key,"key__%u",i);
|
||||||
u=Hashtable_get(ht,key);
|
u=Hashtable_get(ht,key);
|
||||||
//printuni(u); printf(" ");
|
|
||||||
}
|
}
|
||||||
free(key);
|
free(key);
|
||||||
return u;
|
return u;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user