Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
EST_StringTrie.h
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1996 */
6/* All Rights Reserved. */
7/* */
8/* Permission is hereby granted, free of charge, to use and distribute */
9/* this software and its documentation without restriction, including */
10/* without limitation the rights to use, copy, modify, merge, publish, */
11/* distribute, sublicense, and/or sell copies of this work, and to */
12/* permit persons to whom this work is furnished to do so, subject to */
13/* the following conditions: */
14/* 1. The code must retain the above copyright notice, this list of */
15/* conditions and the following disclaimer. */
16/* 2. Any modifications must be clearly marked as such. */
17/* 3. Original authors' names are not deleted. */
18/* 4. The authors' names are not used to endorse or promote products */
19/* derived from this software without specific prior written */
20/* permission. */
21/* */
22/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30/* THIS SOFTWARE. */
31/* */
32/*************************************************************************/
33/* Author : Alan W Black */
34/* Date : June 1996 */
35/*-----------------------------------------------------------------------*/
36/* */
37/* A class for building EST_String (char-based) tries for indexing */
38/* arbitrary objects by Strings */
39/* */
40/*=======================================================================*/
41#ifndef __EST_STRINGTRIE_H__
42#define __EST_STRINGTRIE_H__
43
44#include "EST_String.h"
45
46class EST_StringTrie;
47
48/** An internal class for \Ref{EST_StringTrie} used to hold represent the
49 node in an string index tree.
50
51 This basically represents a 128-branching node (on for each character)
52 plus a contents field for strings ending at this point.
53
54 @author Alan W Black (awb@cstr.ed.ac.uk): June 1996
55*/
57 private:
58 int w;
59 EST_TrieNode **d;
60 void *contents;
61 // will use EST_TrieContents when I have a list of contents
62 public:
63 ///
64 EST_TrieNode() {w=0; d=0; contents=0;}
65 ///
66 EST_TrieNode(const int width);
67 ///
69 /// Find the contents for given string, 0 if no current contents
70 void *lookup(const unsigned char *key) const;
71 /// add {\tt item} for {\tt key} overwriting previous contents
72 void add(const unsigned char *key,void *item);
73 /// copy all entries in trie node into trie
74 void copy_into(EST_StringTrie &trie, const EST_String &path) const;
75};
76
77/** A string tree index class for indexing arbitrary objects by
78 strings of characters.
79
80 Note this only deals with 7 but characters, and can only hold
81 one item per index key.
82*/
84 private:
85 EST_TrieNode *tree;
86 public:
87 ///
89 ///
90 EST_StringTrie(const EST_StringTrie &trie) { copy(trie); }
91 ///
93 ///
94 void copy(const EST_StringTrie &trie);
95 /// Find contents index by {\tt key}, 0 if there is not contents
96 void *lookup(const EST_String &key) const;
97 /// Add {\tt item} indexed by {\tt key}, overwriting previous contents
98 void add(const EST_String &key,void *item);
99 /// Delete the tree
100 void clear(void);
101 /// Delete the tree, apply {\tt deletenote} function to each {\tt contents}
102 void clear(void (*deletenode)(void *n));
103
104 ///
106 { copy(a); return *this; }
107
108};
109
110#endif // __EST_STRINGTRIE_H__
void add(const EST_String &key, void *item)
Add {\tt item} indexed by {\tt key}, overwriting previous contents.
void * lookup(const EST_String &key) const
Find contents index by {\tt key}, 0 if there is not contents.
void clear(void)
Delete the tree.
void copy_into(EST_StringTrie &trie, const EST_String &path) const
copy all entries in trie node into trie
void * lookup(const unsigned char *key) const
Find the contents for given string, 0 if no current contents.
void add(const unsigned char *key, void *item)
add {\tt item} for {\tt key} overwriting previous contents