From de5faa60f5039efbe9081710c74127b66d1d5116 Mon Sep 17 00:00:00 2001 From: Baptiste JL Date: Wed, 10 Apr 2019 15:21:38 +0200 Subject: [PATCH] Update isEnd --- treeh.c | 30 ++++++++++++++++-------------- treeh.h | 27 ++++++++++++++++++--------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/treeh.c b/treeh.c index 32e20fd..f4975b4 100644 --- a/treeh.c +++ b/treeh.c @@ -41,30 +41,34 @@ bool is_followed(tree t){ } return false; } -bool is_end(tree t){ - return t->isEnd; -} + +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 or '\'' - if(c='\'') - return 0; - return c%32; + //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, when called : set isIn to true, and reset index + //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=t->isEnd; + 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); @@ -80,10 +84,8 @@ void addto_tree2(tree t,string s){ 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); } -void loadfrom_file(tree,FILE*){} -void loadfrom_keyboard(tree){} - diff --git a/treeh.h b/treeh.h index f82714a..d42ea04 100644 --- a/treeh.h +++ b/treeh.h @@ -6,26 +6,35 @@ #include #include -#define NBCHAR 27 //A-Z + ' +#define NBCHAR 26 //A-Z typedef struct _node node, *tree; struct _node{ char letter; - bool isEnd; + char isEnd; + //0 no,1 yes,+2 if ends with 's + //+4if proper, +8if allUpper node* next[NBCHAR]; }; -tree make_empty_tree(); -node* make_empty_node(); -node* make_node(char,bool); -void delete_tree(tree); +tree make_empty_tree();//create a null node* +node* make_empty_node();//malloc a node and initialize it +node* make_node(char,bool);//id +void delete_tree(tree);//free(tree) and delete tree on all t->next + +bool is_empty(tree);//==NULL +bool is_followed(tree);//if true tree has following letters + +bool is_end(tree);//if true word can end here +bool is_proper_end(tree);//if true 1st letter is upper +bool is_common_end(tree);//if true all letters are lower +bool is_acronyme_end(tree);//if true all letters are upper +bool ends_with_apostrophe(tree);//if true word can be word's -bool is_empty(tree); -bool is_end(tree); -bool is_followed(tree);//tells if tree has following letters int hash(char);//need to check if isalpha +//recursive can only be called in a dico instance void addto_tree(tree,string,int); void addto_tree2(tree,string); -- libgit2 0.21.2