3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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 2, or (at your option) any later
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file trie_policy_base.hpp
44 * Contains an implementation of trie_policy_base.
47 #ifndef PB_DS_TRIE_POLICY_BASE_HPP
48 #define PB_DS_TRIE_POLICY_BASE_HPP
50 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
57 #define PB_DS_CLASS_T_DEC \
59 class Const_Node_Iterator, \
60 class Node_Iterator, \
61 class E_Access_Traits, \
64 #define PB_DS_CLASS_C_DEC \
66 Const_Node_Iterator, \
71 #define PB_DS_BASE_C_DEC \
72 basic_tree_policy_base< \
73 Const_Node_Iterator, \
77 template<typename Const_Node_Iterator,
79 class E_Access_Traits,
81 class trie_policy_base : public PB_DS_BASE_C_DEC
86 typedef E_Access_Traits e_access_traits;
88 typedef Allocator allocator;
90 typedef typename allocator::size_type size_type;
92 typedef null_node_metadata metadata_type;
94 typedef Const_Node_Iterator const_node_iterator;
96 typedef Node_Iterator node_iterator;
98 typedef typename const_node_iterator::value_type const_iterator;
100 typedef typename node_iterator::value_type iterator;
104 typedef typename PB_DS_BASE_C_DEC::key_type key_type;
107 typename PB_DS_BASE_C_DEC::const_key_reference
112 virtual const_iterator
118 virtual const_node_iterator
119 node_begin() const = 0;
121 virtual node_iterator
124 virtual const_node_iterator
125 node_end() const = 0;
127 virtual node_iterator
130 virtual const e_access_traits&
131 get_e_access_traits() const = 0;
136 typename e_access_traits::const_iterator,
137 typename e_access_traits::const_iterator>
140 typedef PB_DS_BASE_C_DEC base_type;
144 common_prefix_len(node_iterator nd_it, typename e_access_traits::const_iterator b_r, typename e_access_traits::const_iterator e_r, const e_access_traits& r_traits);
147 leftmost_it(node_iterator nd_it);
150 rightmost_it(node_iterator nd_it);
153 less(typename e_access_traits::const_iterator b_l, typename e_access_traits::const_iterator e_l, typename e_access_traits::const_iterator b_r, typename e_access_traits::const_iterator e_r, const e_access_traits& r_traits);
157 typename PB_DS_CLASS_C_DEC::size_type
159 common_prefix_len(node_iterator nd_it, typename e_access_traits::const_iterator b_r, typename e_access_traits::const_iterator e_r, const e_access_traits& r_traits)
161 prefix_range_t pref_range = nd_it.valid_prefix();
163 typename e_access_traits::const_iterator b_l = pref_range.first;
164 typename e_access_traits::const_iterator e_l = pref_range.second;
166 const size_type range_length_l =
167 std::distance(b_l, e_l);
169 const size_type range_length_r =
170 std::distance(b_r, e_r);
172 if (range_length_r < range_length_l)
183 if (r_traits.e_pos(*b_l) != r_traits.e_pos(*b_r))
197 typename PB_DS_CLASS_C_DEC::iterator
199 leftmost_it(node_iterator nd_it)
201 if (nd_it.num_children() == 0)
204 return (leftmost_it(nd_it.get_child(0)));
208 typename PB_DS_CLASS_C_DEC::iterator
210 rightmost_it(node_iterator nd_it)
212 const size_type num_children = nd_it.num_children();
214 if (num_children == 0)
217 return (rightmost_it(nd_it.get_child(num_children - 1)));
223 less(typename e_access_traits::const_iterator b_l, typename e_access_traits::const_iterator e_l, typename e_access_traits::const_iterator b_r, typename e_access_traits::const_iterator e_r, const e_access_traits& r_traits)
231 r_traits.e_pos(*b_l);
233 r_traits.e_pos(*b_r);
236 return (l_pos < r_pos);
245 #undef PB_DS_CLASS_T_DEC
247 #undef PB_DS_CLASS_C_DEC
249 #undef PB_DS_BASE_C_DEC
251 } // namespace detail
254 #endif // #ifndef PB_DS_TRIE_POLICY_BASE_HPP