Claw  1.7.3
trie.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #ifndef __CLAW_TRIE_HPP__
31 #define __CLAW_TRIE_HPP__
32 
33 #include <list>
34 #include <functional>
35 #include <claw/binary_node.hpp>
36 
37 namespace claw
38 {
39 
62  template<class T, class Comp = std::equal_to<T> > class trie
63  {
64  private:
65  //************************ trie::trie_node ********************************
66 
73  struct trie_node : public binary_node< trie_node >
74  {
76  T value;
81  unsigned int count;
82 
83  trie_node( const T& val, unsigned int c = 0 );
84  trie_node( const trie_node& that );
85 
86  }; // trie_node;
87 
88  public:
89  //****************************** trie *************************************
90 
91  typedef const T value_type;
92  typedef Comp value_equal_to;
93 
94  private:
95  typedef trie_node* trie_node_ptr;
96 
97  public:
98 
99  trie();
100  trie( const trie<T, Comp>& that );
101  ~trie();
102 
103  unsigned int size() const;
104  bool empty() const;
105 
106  void clear();
107 
108  template<class InputIterator>
109  void insert(InputIterator first, InputIterator last);
110 
111  template <class InputIterator>
112  unsigned int count(InputIterator first, InputIterator last);
113 
114  private:
116  static value_equal_to s_value_equal_to;
117 
119  trie_node_ptr m_tree;
120 
122  unsigned int m_size;
123  }; // class trie
124 
125 } // namespace claw
126 
127 #include <claw/impl/trie.tpp>
128 
129 #endif // __CLAW_TRIE_HPP__