3 // Copyright (C) 2005, 2006, 2009 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 3, 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 // 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.
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/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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
37 * @file synth_e_access_traits.hpp
38 * Contains an implementation class for a patricia tree.
41 #ifndef PB_DS_SYNTH_E_ACCESS_TRAITS_HPP
42 #define PB_DS_SYNTH_E_ACCESS_TRAITS_HPP
44 #include <ext/pb_ds/detail/type_utils.hpp>
51 #define PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC \
52 template<typename Type_Traits, bool Set, class E_Access_Traits>
54 #define PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC \
55 synth_e_access_traits< \
60 template<typename Type_Traits
, bool Set
, class E_Access_Traits
>
61 struct synth_e_access_traits
: public E_Access_Traits
65 typedef E_Access_Traits base_type
;
67 typedef Type_Traits type_traits
;
69 typedef typename
type_traits::const_key_reference const_key_reference
;
71 typedef typename
type_traits::const_reference const_reference
;
74 synth_e_access_traits();
76 synth_e_access_traits(const E_Access_Traits
& r_traits
);
79 equal_prefixes(typename
base_type::const_iterator b_l
, typename
base_type::const_iterator e_l
, typename
base_type::const_iterator b_r
, typename
base_type::const_iterator e_r
, bool compare_after
= true) const;
82 equal_keys(const_key_reference r_lhs_key
, const_key_reference r_rhs_key
) const;
85 cmp_prefixes(typename
base_type::const_iterator b_l
, typename
base_type::const_iterator e_l
, typename
base_type::const_iterator b_r
, typename
base_type::const_iterator e_r
, bool compare_after
= false) const;
88 cmp_keys(const_key_reference r_lhs_key
, const_key_reference r_rhs_key
) const;
90 inline static const_key_reference
91 extract_key(const_reference r_val
);
95 operator()(const_key_reference r_lhs
, const_key_reference r_rhs
);
99 inline static const_key_reference
100 extract_key(const_reference r_val
, true_type
);
102 inline static const_key_reference
103 extract_key(const_reference r_val
, false_type
);
106 static integral_constant
<int,Set
> s_set_ind
;
109 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
110 integral_constant
<int,Set
>
111 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::s_set_ind
;
113 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
114 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
115 synth_e_access_traits()
118 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
119 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
120 synth_e_access_traits(const E_Access_Traits
& r_traits
) :
121 E_Access_Traits(r_traits
)
124 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
126 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
127 equal_prefixes(typename
base_type::const_iterator b_l
, typename
base_type::const_iterator e_l
, typename
base_type::const_iterator b_r
, typename
base_type::const_iterator e_r
, bool compare_after
/*= false */) const
133 if (base_type::e_pos(*b_l
) != base_type::e_pos(*b_r
))
138 return (!compare_after
|| b_r
== e_r
);
141 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
143 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
144 equal_keys(const_key_reference r_lhs_key
, const_key_reference r_rhs_key
) const
146 return (equal_prefixes(base_type::begin(r_lhs_key
),
147 base_type::end(r_lhs_key
),
148 base_type::begin(r_rhs_key
),
149 base_type::end(r_rhs_key
),
153 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
155 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
156 cmp_prefixes(typename
base_type::const_iterator b_l
, typename
base_type::const_iterator e_l
, typename
base_type::const_iterator b_r
, typename
base_type::const_iterator e_r
, bool compare_after
/* = false*/) const
162 const typename
base_type::size_type l_pos
=
163 base_type::e_pos(*b_l
);
164 const typename
base_type::size_type r_pos
=
165 base_type::e_pos(*b_r
);
167 return (l_pos
< r_pos
);
177 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
179 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
180 cmp_keys(const_key_reference r_lhs_key
, const_key_reference r_rhs_key
) const
182 return (cmp_prefixes(base_type::begin(r_lhs_key
),
183 base_type::end(r_lhs_key
),
184 base_type::begin(r_rhs_key
),
185 base_type::end(r_rhs_key
),
189 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
190 inline typename
PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::const_key_reference
191 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
192 extract_key(const_reference r_val
)
194 return (extract_key(r_val
, s_set_ind
));
197 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
198 inline typename
PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::const_key_reference
199 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
200 extract_key(const_reference r_val
, true_type
)
205 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
206 inline typename
PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::const_key_reference
207 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
208 extract_key(const_reference r_val
, false_type
)
210 return (r_val
.first
);
213 #ifdef _GLIBCXX_DEBUG
214 PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
216 PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
217 operator()(const_key_reference r_lhs
, const_key_reference r_rhs
)
219 return (cmp_keys(r_lhs
, r_rhs
));
223 #undef PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
224 #undef PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC
226 } // namespace detail
227 } // namespace __gnu_pbds