Edinburgh Speech Tools  2.1-release
EST_StringTrie.h
Go to the documentation of this file.
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 
46 class EST_StringTrie;
47 
48 /** \class EST_TrieNode
49  * @ingroup containerclasses
50  * An internal class for \ref EST_StringTrie used to hold represent the
51  node in an string index tree.
52 
53  This basically represents a 128-branching node (on for each character)
54  plus a contents field for strings ending at this point.
55 
56  @author Alan W Black (awb@cstr.ed.ac.uk): June 1996
57 */
58 class EST_TrieNode {
59  private:
60  int w;
61  EST_TrieNode **d;
62  void *contents;
63  // will use EST_TrieContents when I have a list of contents
64  public:
65  ///
66  EST_TrieNode() {w=0; d=0; contents=0;}
67  ///
68  EST_TrieNode(const int width);
69  ///
70  ~EST_TrieNode();
71  /// Find the contents for given string, 0 if no current contents
72  void *lookup(const unsigned char *key) const;
73  /// add `item` for `key` overwriting previous contents
74  void add(const unsigned char *key,void *item);
75  /// copy all entries in trie node into trie
76  void copy_into(EST_StringTrie &trie, const EST_String &path) const;
77 };
78 
79 /** \class EST_StringTrie
80  * @ingroup containerclasses
81  * \brief A string tree index class for indexing arbitrary objects by
82  strings of characters.
83 
84  Note this only deals with 7 but characters, and can only hold
85  one item per index key.
86 */
88  private:
90  public:
91  ///
93  ///
94  EST_StringTrie(const EST_StringTrie &trie) { copy(trie); }
95  ///
96  ~EST_StringTrie();
97  ///
98  void copy(const EST_StringTrie &trie);
99  /// Find contents index by `key`, 0 if there is not contents
100  void *lookup(const EST_String &key) const;
101  /// Add `item` indexed by `key`, overwriting previous contents
102  void add(const EST_String &key,void *item);
103  /// Delete the tree
104  void clear(void);
105  /// Delete the tree, apply `deletenote` function to each `contents`
106  void clear(void (*deletenode)(void *n));
107 
108  ///
109  EST_StringTrie & operator = (const EST_StringTrie &a)
110  { copy(a); return *this; }
111 
112 };
113 
114 #endif // __EST_STRINGTRIE_H__
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 item for key overwriting previous contents
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
A string tree index class for indexing arbitrary objects by strings of characters.
void copy_into(EST_StringTrie &trie, const EST_String &path) const
copy all entries in trie node into trie
EST_StringTrie(const EST_StringTrie &trie)
int tree
Definition: rxp.c:21