libsent/src/util/ptree.c File Reference

Patricia index tree for name lookup: data type = int. More...

#include <sent/stddefs.h>
#include <sent/ptree.h>

Include dependency graph for ptree.c:

Go to the source code of this file.

Functions

int testbit (char *str, int bitplace)
int where_the_bit_differ (char *str1, char *str2)
static PATNODEnew_node ()
PATNODEmake_ptree (char **words, int *data, int wordsnum, int bitplace)
void disp_ptree (PATNODE *node, int level)
static int testbit_local (int bitplace)
static int ptree_search_data_r (PATNODE *node)
int ptree_search_data (char *str, PATNODE *node)
PATNODEptree_make_root_node (int data)
static void ptree_add_entry_at (char *str, int bitloc, int data, PATNODE **parentlink)
void ptree_add_entry (char *str, int data, char *matchstr, PATNODE **rootnode)
void free_ptree (PATNODE *node)

Variables

static char * tmp_str
 Local work area: current string we are searching for.
static int maxbitplace
 Local work area: Maximum bit length of tmp_str.


Detailed Description

Patricia index tree for name lookup: data type = int.

Author:
Akinobu LEE
Date:
Thu Feb 17 15:34:39 2005
Revision
1.3

Definition in file ptree.c.


Function Documentation

int testbit ( char *  str,
int  bitplace 
)

String bit test function.

Parameters:
str [in] key string
bitplace [in] bit location to test
Returns:
the content of tested bit in tmp_str, either 0 or 1.

Definition at line 36 of file ptree.c.

Referenced by aptree_add_entry_at(), make_ptree(), ptree_add_entry_at(), and where_the_bit_differ().

int where_the_bit_differ ( char *  str1,
char *  str2 
)

Find in which bit the two strings differ, starting from the head.

Parameters:
str1 [in] string 1
str2 [in] string 2
Returns:
the bit location in which the string differs.

Definition at line 61 of file ptree.c.

Referenced by aptree_add_entry(), and ptree_add_entry().

static PATNODE* new_node (  )  [static]

Allocate a new node.

Returns:
pointer to the new node.

Definition at line 82 of file ptree.c.

PATNODE* make_ptree ( char **  words,
int *  data,
int  wordsnum,
int  bitplace 
)

Make a patricia tree for given string arrays. Recursively called by descending the scan bit.

Parameters:
words [in] list of word strings
data [in] integer value corresponding to each string in words
wordsnum [in] number of above
bitplace [in] current scan bit.
Returns:
pointer to the root node index.

Definition at line 105 of file ptree.c.

Referenced by make_ptree(), and ngram_make_lookup_tree().

void disp_ptree ( PATNODE node,
int  level 
)

Output a tree structure in text for debug, traversing pre-order

Parameters:
node [in] root index node
level [in] current tree depth

Definition at line 168 of file ptree.c.

static int testbit_local ( int  bitplace  )  [static]

Local bit test function for search.

Parameters:
bitplace [in] bit place to test.
Returns:
the content of tested bit in tmp_str, either 0 or 1.

Definition at line 200 of file ptree.c.

static int ptree_search_data_r ( PATNODE node  )  [static]

Recursive function to search the data in the tree

Parameters:
node [in] current node.
Returns:
the found integer value.

Definition at line 224 of file ptree.c.

Referenced by ptree_search_data().

int ptree_search_data ( char *  str,
PATNODE node 
)

Search for the data whose key string matches the given string.

Parameters:
str [in] search key string
node [in] root node of index tree
Returns:
the exactly found integer value, or the nearest one.

Definition at line 246 of file ptree.c.

Referenced by ngram_lookup_word(), and set_unigram().

PATNODE* ptree_make_root_node ( int  data  ) 

Make a root node of a index tree.

Parameters:
data [in] the first data
Returns:
the newly allocated root node.

Definition at line 268 of file ptree.c.

Referenced by ptree_add_entry(), and set_unigram().

static void ptree_add_entry_at ( char *  str,
int  bitloc,
int  data,
PATNODE **  parentlink 
) [static]

Insert a new node to the existing index tree.

Parameters:
str [in] new key string
bitloc [in] bit branch to which this node will be added
data [in] new data integer value
parentlink [i/o] the parent node to which this node will be added

Definition at line 286 of file ptree.c.

Referenced by ptree_add_entry().

void ptree_add_entry ( char *  str,
int  data,
char *  matchstr,
PATNODE **  rootnode 
)

Insert a new node to the index tree.

Parameters:
str [in] new key string
data [in] new data integer value
matchstr [in] the most matching data already exist in the index tree, as obtained by aptree_search_data()
rootnode [i/o] pointer to root index node

Definition at line 326 of file ptree.c.

Referenced by set_unigram().

void free_ptree ( PATNODE node  ) 

Free all the sub nodes from specified node.

Parameters:
node [in] current node.

Definition at line 345 of file ptree.c.

Referenced by free_ptree(), and ngram_info_free().


Generated on Tue Dec 26 16:18:22 2006 for Julius by  doxygen 1.5.0