diff --git a/treeh.c b/treeh.c index 1b0ba3f..f8f8d60 100644 --- a/treeh.c +++ b/treeh.c @@ -27,6 +27,8 @@ void delete_tree(tree t){ + + //Casual functions bool is_empty(tree t){ return t==NULL; @@ -51,26 +53,36 @@ int hash(char c){ -// -bool addto_tree(tree t,string s,unsigned int index,bool isIn){ - //recursive, when called : set isIn to true + + +//loading functions +bool addto_tree(tree t,string s){ + //recursive, when called : set isIn to true, and reset index //return wether s is already in t or not + bool ret; if(s[0]=='\0'){ + ret=t->isEnd; t->isEnd=true; - return isIn; + return ret; + } + if(t->next[hash(s[0])]==NULL){ + t->next[hash(s[0])]=make_node(s[0],false); + addto_tree2(t->next[hash(s[0])],s+1); + return false; } - if(t->next[hash(s[0])]==NULL) - t->next[hash(s[0])]=make_node(s[0],false); + else + addto_tree(t->next[hash(s[0])],s+1,isIn); } void addto_tree2(tree t,string s){ - //faster than addto_tree, used when it is knowned the word is not yet in dictionnary + //faster than addto_treeused when it is knowned the word is not yet in dictionnary if(s[0]=='\0'){ t->isEnd=true; return; } t->next[hash(s[0])]=make_node(s[0],false); - addto_tree2(t->next[hash(s[0])], + addto_tree2(t->next[hash(s[0])],s+1); } + void loadfrom_file(tree,FILE*){} void loadfrom_keyboard(tree){} diff --git a/treeh.h b/treeh.h index 48ad5eb..7c9b0ec 100644 --- a/treeh.h +++ b/treeh.h @@ -24,14 +24,11 @@ void delete_tree(tree); bool is_empty(tree); bool is_end(tree); bool is_followed(tree);//tells if tree has following letters +int hash(char); void addto_tree(tree,char*,int); void loadfrom_file(tree,FILE*); void loadfrom_keyboard(tree); -int hash(char); - - - #endif //TREEH_H -- libgit2 0.21.2