mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-02-06 08:48:21 +01:00
uint_t -> dic_elt_t for dictionary
This commit is contained in:
parent
a3d86b2be6
commit
c8dde79bc3
2 changed files with 70 additions and 35 deletions
28
dic/dic.c
28
dic/dic.c
|
@ -16,7 +16,7 @@
|
||||||
/* along with this program; if not, write to the Free Software */
|
/* along with this program; if not, write to the Free Software */
|
||||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
/* 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 <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -97,8 +97,8 @@ Dic_destroy(Dictionary dic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint_t
|
dic_elt_t
|
||||||
Dic_next(Dictionary d, uint_t e)
|
Dic_next(Dictionary d, dic_elt_t e)
|
||||||
{
|
{
|
||||||
if (! Dic_last(d,e))
|
if (! Dic_last(d,e))
|
||||||
return e+1;
|
return e+1;
|
||||||
|
@ -106,14 +106,14 @@ Dic_next(Dictionary d, uint_t e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint_t
|
dic_elt_t
|
||||||
Dic_succ(Dictionary d, uint_t e)
|
Dic_succ(Dictionary d, dic_elt_t e)
|
||||||
{
|
{
|
||||||
return (d->dawg[e]).ptr;
|
return (d->dawg[e]).ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint_t
|
dic_elt_t
|
||||||
Dic_root(Dictionary d)
|
Dic_root(Dictionary d)
|
||||||
{
|
{
|
||||||
return d->root;
|
return d->root;
|
||||||
|
@ -121,41 +121,41 @@ Dic_root(Dictionary d)
|
||||||
|
|
||||||
|
|
||||||
char
|
char
|
||||||
Dic_chr(Dictionary d, uint_t e)
|
Dic_chr(Dictionary d, dic_elt_t e)
|
||||||
{
|
{
|
||||||
return (d->dawg[e]).chr;
|
return (d->dawg[e]).chr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Dic_last(Dictionary d, uint_t e)
|
Dic_last(Dictionary d, dic_elt_t e)
|
||||||
{
|
{
|
||||||
return (d->dawg[e]).last;
|
return (d->dawg[e]).last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Dic_word(Dictionary d, uint_t e)
|
Dic_word(Dictionary d, dic_elt_t e)
|
||||||
{
|
{
|
||||||
return (d->dawg[e]).term;
|
return (d->dawg[e]).term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
Dic_lookup(Dictionary d, unsigned int t, char* s)
|
Dic_lookup(Dictionary d, dic_elt_t root, char* s)
|
||||||
{
|
{
|
||||||
unsigned int p;
|
unsigned int p;
|
||||||
begin:
|
begin:
|
||||||
if (! *s)
|
if (! *s)
|
||||||
return t;
|
return root;
|
||||||
if (! Dic_succ(d, t))
|
if (! Dic_succ(d, root))
|
||||||
return 0;
|
return 0;
|
||||||
p = Dic_succ(d, t);
|
p = Dic_succ(d, root);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (Dic_chr(d, p) == *s)
|
if (Dic_chr(d, p) == *s)
|
||||||
{
|
{
|
||||||
t = p;
|
root = p;
|
||||||
s++;
|
s++;
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
|
77
dic/dic.h
77
dic/dic.h
|
@ -16,7 +16,7 @@
|
||||||
/* along with this program; if not, write to the Free Software */
|
/* along with this program; if not, write to the Free Software */
|
||||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
/* 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
|
* \file dic.h
|
||||||
|
@ -43,40 +43,75 @@ extern "C"
|
||||||
#define DIC_WORD_MAX 16
|
#define DIC_WORD_MAX 16
|
||||||
|
|
||||||
typedef struct _Dictionary* Dictionary;
|
typedef struct _Dictionary* Dictionary;
|
||||||
typedef unsigned int uint_t;
|
typedef unsigned int dic_elt_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Création et chargement d'un dictionnaire
|
* Dictionary creation and loading from a file
|
||||||
* @param dic : pointeur
|
* @param dic : pointer to a dictionary
|
||||||
* @param path : chemin
|
* @param path : compressed dictionary path
|
||||||
* @return 0 ok, 1 erreur
|
* @return 0 ok, 1 error
|
||||||
*/
|
*/
|
||||||
int Dic_load (Dictionary* dic,const char* path);
|
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 dic, dic_elt_t elt);
|
||||||
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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 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)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue