STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trie_policy.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26 
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
35 
41 #ifndef PB_DS_TRIE_POLICY_HPP
42 #define PB_DS_TRIE_POLICY_HPP
43 
44 #include <bits/c++config.h>
45 #include <string>
48 
49 namespace __gnu_pbds
50 {
51 #define PB_DS_CLASS_T_DEC \
52  template<typename String, typename String::value_type Min_E_Val, \
53  typename String::value_type Max_E_Val, bool Reverse, \
54  typename _Alloc>
55 
56 #define PB_DS_CLASS_C_DEC \
57  trie_string_access_traits<String, Min_E_Val,Max_E_Val,Reverse,_Alloc>
58 
69  template<typename String = std::string,
70  typename String::value_type Min_E_Val = detail::__numeric_traits<typename String::value_type>::__min,
71  typename String::value_type Max_E_Val = detail::__numeric_traits<typename String::value_type>::__max,
72  bool Reverse = false,
73  typename _Alloc = std::allocator<char> >
75  {
76  public:
77  typedef typename _Alloc::size_type size_type;
78  typedef String key_type;
79  typedef typename _Alloc::template rebind<key_type> __rebind_k;
80  typedef typename __rebind_k::other::const_reference key_const_reference;
81 
82  enum
83  {
84  reverse = Reverse
85  };
86 
88  typedef typename detail::__conditional_type<Reverse, \
89  typename String::const_reverse_iterator, \
90  typename String::const_iterator>::__type const_iterator;
91 
93  typedef typename std::iterator_traits<const_iterator>::value_type e_type;
94 
95  enum
96  {
97  min_e_val = Min_E_Val,
98  max_e_val = Max_E_Val,
100  };
101  PB_DS_STATIC_ASSERT(min_max_size, max_size >= 2);
102 
105  inline static const_iterator
107 
110  inline static const_iterator
112 
114  inline static size_type
115  e_pos(e_type e);
116 
117  private:
118  inline static const_iterator
120 
121  inline static const_iterator
123 
124  inline static const_iterator
126 
127  inline static const_iterator
129 
130  static detail::integral_constant<int, Reverse> s_rev_ind;
131  };
132 
134 
135 #undef PB_DS_CLASS_T_DEC
136 #undef PB_DS_CLASS_C_DEC
137 
138 #define PB_DS_CLASS_T_DEC \
139  template<typename Node_CItr,typename Node_Itr, \
140  typename _ATraits, typename _Alloc>
141 
142 #define PB_DS_CLASS_C_DEC \
143  trie_prefix_search_node_update<Node_CItr, Node_Itr, \
144  _ATraits,_Alloc>
145 
146 #define PB_DS_TRIE_POLICY_BASE \
147  detail::trie_policy_base<Node_CItr,Node_Itr,_ATraits, _Alloc>
148 
151  template<typename Node_CItr,
152  typename Node_Itr,
153  typename _ATraits,
154  typename _Alloc>
156  {
157  private:
159 
160  public:
161  typedef typename base_type::key_type key_type;
162  typedef typename base_type::key_const_reference key_const_reference;
163 
165  typedef _ATraits access_traits;
166 
168  typedef typename access_traits::const_iterator a_const_iterator;
169 
171  typedef _Alloc allocator_type;
172 
174  typedef typename allocator_type::size_type size_type;
176  typedef Node_Itr node_iterator;
177  typedef Node_CItr node_const_iterator;
178  typedef typename node_iterator::value_type iterator;
179  typedef typename node_const_iterator::value_type const_iterator;
180 
183  std::pair<const_iterator, const_iterator>
185 
188  std::pair<iterator, iterator>
190 
193  std::pair<const_iterator, const_iterator>
195 
198  std::pair<iterator, iterator>
200 
201  protected:
203  inline void
204  operator()(node_iterator node_it, node_const_iterator end_nd_it) const;
205 
206  private:
209  node_iterator, const access_traits&);
210 
212  virtual const_iterator
213  end() const = 0;
214 
216  virtual iterator
217  end() = 0;
218 
220  virtual node_const_iterator
221  node_begin() const = 0;
222 
224  virtual node_iterator
225  node_begin() = 0;
226 
228  virtual node_const_iterator
229  node_end() const = 0;
230 
232  virtual node_iterator
233  node_end() = 0;
234 
236  virtual const access_traits&
237  get_access_traits() const = 0;
238  };
239 
241 
242 #undef PB_DS_CLASS_C_DEC
243 
244 #define PB_DS_CLASS_C_DEC \
245  trie_order_statistics_node_update<Node_CItr, Node_Itr, \
246  _ATraits, _Alloc>
247 
249  template<typename Node_CItr,
250  typename Node_Itr,
251  typename _ATraits,
252  typename _Alloc>
254  {
255  private:
257 
258  public:
259  typedef _ATraits access_traits;
260  typedef typename access_traits::const_iterator a_const_iterator;
261  typedef _Alloc allocator_type;
262  typedef typename allocator_type::size_type size_type;
263  typedef typename base_type::key_type key_type;
264  typedef typename base_type::key_const_reference key_const_reference;
265 
267  typedef Node_CItr node_const_iterator;
268  typedef Node_Itr node_iterator;
269  typedef typename node_const_iterator::value_type const_iterator;
270  typedef typename node_iterator::value_type iterator;
271 
276  inline const_iterator
277  find_by_order(size_type) const;
278 
283  inline iterator
285 
291  inline size_type
293 
299  inline size_type
301 
302  protected:
305  inline void
307 
308  private:
309  typedef typename base_type::const_reference const_reference;
310  typedef typename base_type::const_pointer const_pointer;
311 
312  typedef typename _Alloc::template rebind<metadata_type> __rebind_m;
313  typedef typename __rebind_m::other __rebind_ma;
314  typedef typename __rebind_ma::const_reference metadata_const_reference;
315  typedef typename __rebind_ma::reference metadata_reference;
316 
318  virtual bool
319  empty() const = 0;
320 
322  virtual iterator
323  begin() = 0;
324 
327  virtual iterator
328  end() = 0;
329 
331  virtual node_const_iterator
332  node_begin() const = 0;
333 
335  virtual node_iterator
336  node_begin() = 0;
337 
340  virtual node_const_iterator
341  node_end() const = 0;
342 
344  virtual node_iterator
345  node_end() = 0;
346 
348  virtual access_traits&
349  get_access_traits() = 0;
350  };
351 
353 
354 #undef PB_DS_CLASS_T_DEC
355 #undef PB_DS_CLASS_C_DEC
356 #undef PB_DS_TRIE_POLICY_BASE
357 
358 } // namespace __gnu_pbds
359 
360 #endif
size_type metadata_type
Definition: trie_policy.hpp:266
std::iterator_traits< const_iterator >::value_type e_type
Element type.
Definition: trie_policy.hpp:93
node_iterator::value_type iterator
Definition: trie_policy.hpp:270
__rebind_k::other::const_reference key_const_reference
Definition: trie_policy.hpp:80
static const_iterator begin(key_const_reference)
Definition: trie_policy.hpp:74
_Alloc allocator_type
Definition: trie_policy.hpp:261
base_type::key_const_reference key_const_reference
Definition: trie_policy.hpp:162
const_iterator find_by_order(size_type) const
node_const_iterator::value_type const_iterator
Definition: trie_policy.hpp:179
virtual const access_traits & get_access_traits() const =0
Access to the cmp_fn object.
virtual node_const_iterator node_end() const =0
static const_iterator end_imp(key_const_reference, detail::false_type)
access_traits::const_iterator a_const_iterator
Const element iterator.
Definition: trie_policy.hpp:168
allocator_type::size_type size_type
Size type.
Definition: trie_policy.hpp:174
_Alloc allocator_type
_Alloc type.
Definition: trie_policy.hpp:171
Node_Itr node_iterator
Definition: trie_policy.hpp:268
base_type::const_pointer const_pointer
Definition: trie_policy.hpp:310
virtual node_const_iterator node_begin() const =0
Returns the node_const_iterator associated with the trie's root node.
Represents no type, or absence of type, for template tricks.
Definition: tag_and_trait.hpp:210
static detail::integral_constant< int, Reverse > s_rev_ind
Definition: trie_policy.hpp:130
PB_DS_TRIE_POLICY_BASE base_type
Definition: trie_policy.hpp:256
size_type order_of_prefix(a_const_iterator, a_const_iterator) const
basic_string< char > string
Definition: string:1153
base_type::key_type key_type
Definition: trie_policy.hpp:263
static const_iterator end(key_const_reference)
_Alloc::template rebind< key_type > __rebind_k
Definition: trie_policy.hpp:79
virtual node_const_iterator node_end() const =0
Returns the node_const_iterator associated with a just-after leaf node.
base_type::key_const_reference key_const_reference
Definition: trie_policy.hpp:264
String key_type
Definition: trie_policy.hpp:78
node_iterator next_child(node_iterator, a_const_iterator, a_const_iterator, node_iterator, const access_traits &)
node_const_iterator::value_type const_iterator
Definition: trie_policy.hpp:269
virtual const_iterator end() const =0
Returns the const iterator associated with the just-after last element.
_Alloc::size_type size_type
Definition: trie_policy.hpp:77
__rebind_m::other __rebind_ma
Definition: trie_policy.hpp:313
PB_DS_STATIC_ASSERT(min_max_size, max_size >=2)
allocator_type::size_type size_type
Definition: trie_policy.hpp:262
virtual access_traits & get_access_traits()=0
Access to the cmp_fn object.
access_traits::const_iterator a_const_iterator
Definition: trie_policy.hpp:260
PB_DS_TRIE_POLICY_BASE base_type
Definition: trie_policy.hpp:158
node_iterator::value_type iterator
Definition: trie_policy.hpp:178
detail::__conditional_type< Reverse, typename String::const_reverse_iterator, typename String::const_iterator >::__type const_iterator
Element const iterator type.
Definition: trie_policy.hpp:90
std::tr1::integral_constant< int, 1 > true_type
Definition: type_utils.hpp:70
Node_CItr node_const_iterator
Definition: trie_policy.hpp:267
virtual iterator begin()=0
Returns the iterator associated with the trie's first element.
null_type metadata_type
Definition: trie_policy.hpp:175
base_type::const_reference const_reference
Definition: trie_policy.hpp:309
void operator()(node_iterator, node_const_iterator) const
virtual node_const_iterator node_begin() const =0
Returns the node_const_iterator associated with the trie's root node.
_Alloc::template rebind< metadata_type > __rebind_m
Definition: trie_policy.hpp:312
Definition: trie_policy.hpp:155
base_type::key_type key_type
Definition: trie_policy.hpp:161
static size_type e_pos(e_type e)
Maps an element to a position.
Functor updating ranks of entrees.
Definition: trie_policy.hpp:253
_ATraits access_traits
Element access traits.
Definition: trie_policy.hpp:165
Node_CItr node_const_iterator
Definition: trie_policy.hpp:177
std::pair< const_iterator, const_iterator > prefix_range(key_const_reference) const
__rebind_ma::reference metadata_reference
Definition: trie_policy.hpp:315
_ATraits access_traits
Definition: trie_policy.hpp:259
size_type order_of_key(key_const_reference) const
void operator()(node_iterator node_it, node_const_iterator end_nd_it) const
Called to update a node's metadata.
__rebind_ma::const_reference metadata_const_reference
Definition: trie_policy.hpp:314
static const_iterator begin_imp(key_const_reference, detail::false_type)
virtual bool empty() const =0
Returns true if the container is empty.
#define PB_DS_TRIE_POLICY_BASE
Definition: trie_policy.hpp:146
Node_Itr node_iterator
Definition: trie_policy.hpp:176
std::tr1::integral_constant< int, 0 > false_type
Definition: type_utils.hpp:71