#include "treeh.h" //initializers & destroyer tree make_empty_tree(){ return NULL; } node* make_empty_node(){ node*n=malloc(sizeof(node)); n->letter='\0'; n->isEnd=false; for(int i=0;inext[i]=make_empty_tree(); } node* make_node(char l,bool end){ node*n=malloc(sizeof(node)); n->letter=l; n->isEnd=end; for(int i=0;inext[i]=make_empty_tree(); } void delete_tree(tree t){ if(is_empty(t))return; for(int i=0;inext[i]); free(t); } //Casual functions bool is_empty(tree t){ return t==NULL; } bool is_followed(tree t){ int i; for(i=0;inext[i]!=NULL) return true; } return false; } bool is_end(tree t){return t->isEnd%2;} bool ends_with_apostrophe(tree t){return (t->isEnd/4)%2;} bool is_common_end(tree t){return !(t->isEnd/4);} bool is_proper_end(tree t){return (t->isEnd/4)%2;} bool is_acronyme_end(tree t){return t->isEnd/8;} int hash(char c){ //needs to check c wether isalpha return c%32-1; } bool is_proper_end(tree);//if true 1st letter is upper ;//if true all letters are lower //loading functions bool addto_tree(tree t,string s){ //recursive, need to check all letter in s are alpha or '\'s' //return wether s is already in t or not bool ret; if(s[0]=='\0'){ ret=is_end(t); t->isEnd=true; return ret; } if(s[0]=='\''){ } 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; } 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 known the word is not yet in dictionnary if(s[0]=='\0'){ t->isEnd=true; return; } if(s[0]=='\'') t->next[hash(s[0])]=make_node(s[0],false); addto_tree2(t->next[hash(s[0])],s+1); }