From c8dde79bc3da38a984b9459786eaae30472b086f Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Wed, 20 Apr 2005 18:11:00 +0000 Subject: [PATCH] uint_t -> dic_elt_t for dictionary --- dic/dic.c | 28 ++++++++++---------- dic/dic.h | 77 ++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/dic/dic.c b/dic/dic.c index 885b81b..3ad0771 100644 --- a/dic/dic.c +++ b/dic/dic.c @@ -16,7 +16,7 @@ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* - * $Id: dic.c,v 1.3 2005/04/19 16:26:51 afrab Exp $ + * $Id: dic.c,v 1.4 2005/04/20 18:11:00 afrab Exp $ */ #include @@ -97,8 +97,8 @@ Dic_destroy(Dictionary dic) } -uint_t -Dic_next(Dictionary d, uint_t e) +dic_elt_t +Dic_next(Dictionary d, dic_elt_t e) { if (! Dic_last(d,e)) return e+1; @@ -106,14 +106,14 @@ Dic_next(Dictionary d, uint_t e) } -uint_t -Dic_succ(Dictionary d, uint_t e) +dic_elt_t +Dic_succ(Dictionary d, dic_elt_t e) { return (d->dawg[e]).ptr; } -uint_t +dic_elt_t Dic_root(Dictionary d) { return d->root; @@ -121,41 +121,41 @@ Dic_root(Dictionary d) char -Dic_chr(Dictionary d, uint_t e) +Dic_chr(Dictionary d, dic_elt_t e) { return (d->dawg[e]).chr; } int -Dic_last(Dictionary d, uint_t e) +Dic_last(Dictionary d, dic_elt_t e) { return (d->dawg[e]).last; } int -Dic_word(Dictionary d, uint_t e) +Dic_word(Dictionary d, dic_elt_t e) { return (d->dawg[e]).term; } unsigned int -Dic_lookup(Dictionary d, unsigned int t, char* s) +Dic_lookup(Dictionary d, dic_elt_t root, char* s) { unsigned int p; begin: if (! *s) - return t; - if (! Dic_succ(d, t)) + return root; + if (! Dic_succ(d, root)) return 0; - p = Dic_succ(d, t); + p = Dic_succ(d, root); do { if (Dic_chr(d, p) == *s) { - t = p; + root = p; s++; goto begin; } diff --git a/dic/dic.h b/dic/dic.h index 319646a..3e73af8 100644 --- a/dic/dic.h +++ b/dic/dic.h @@ -16,7 +16,7 @@ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: dic.h,v 1.5 2005/04/19 16:26:51 afrab Exp $ */ +/* $Id: dic.h,v 1.6 2005/04/20 18:11:00 afrab Exp $ */ /** * \file dic.h @@ -43,40 +43,75 @@ extern "C" #define DIC_WORD_MAX 16 typedef struct _Dictionary* Dictionary; -typedef unsigned int uint_t; +typedef unsigned int dic_elt_t; /** - * Création et chargement d'un dictionnaire - * @param dic : pointeur - * @param path : chemin - * @return 0 ok, 1 erreur + * Dictionary creation and loading from a file + * @param dic : pointer to a dictionary + * @param path : compressed dictionary path + * @return 0 ok, 1 error */ int Dic_load (Dictionary* dic,const char* path); /** - * Détruit un dictionnaire - * + * Destroy a dictionary */ -int Dic_destroy(Dictionary); +int Dic_destroy(Dictionary dic); /** - * functions to access the elements + * Dic_chr returns the character code associated with an element, + * codes may range from 0 to 31. 0 is the null character. + * @returns code for the encoded character */ - -char Dic_chr (Dictionary,uint_t); -int Dic_last(Dictionary,uint_t); -int Dic_word(Dictionary,uint_t); - - -uint_t Dic_root(Dictionary); -uint_t Dic_next(Dictionary,uint_t); -uint_t Dic_succ(Dictionary,uint_t); +char Dic_chr (Dictionary dic, dic_elt_t elt); /** - * + * Returns a boolean to show if there is another available + * character in the current depth (a neighbor in the tree) + * @returns 0 or 1 (true) */ +int Dic_last(Dictionary dic, dic_elt_t elt); -unsigned int Dic_lookup(Dictionary, unsigned int, char*); + /** + * Returns a boolean to show if we are at the end of a word + * (see Dic_next) + * @returns 0 or 1 (true) + */ +int Dic_word(Dictionary dic, dic_elt_t elt); + + /** + * Returns the root of the dictionary + * @returns root element + */ +dic_elt_t Dic_root(Dictionary dic); + + /** + * Returns the next available neighbor (see Dic_last) + * @returns next dictionary element at the same depth + */ +dic_elt_t Dic_next(Dictionary dic, dic_elt_t elt); + + /** + * Returns the first element available at the next depth + * in the dictionary + * @params dic : dictionary + * @params elt : current dictionary element + * @returns next element (successor) + */ +dic_elt_t Dic_succ(Dictionary dic, dic_elt_t elt); + + /** + * Find the dictionary element matching the pattern starting + * from the given root node by walking the dictionary tree + * @params dic : valid dictionary + * @params root : starting dictionary node for the search + * @params pattern : string encoded according to the dictionary codes, + * the pattern must be null ('\0') terminated + * @returns 0 if the string cannot be matched otherwise returns the + * element that results from walking the dictionary according to the + * pattern + */ +unsigned int Dic_lookup(Dictionary dic, dic_elt_t root, char* pattern); #if defined(__cplusplus) }