]>
Commit | Line | Data |
---|---|---|
36fed23c | 1 | // -*- C++ -*- |
2 | ||
fbd26352 | 3 | // Copyright (C) 2005-2019 Free Software Foundation, Inc. |
36fed23c | 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 | |
6bc9506f | 8 | // Foundation; either version 3, or (at your option) any later |
36fed23c | 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 | ||
6bc9506f | 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. | |
36fed23c | 19 | |
6bc9506f | 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/>. | |
36fed23c | 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 | ||
36 | /** | |
4f4a327e | 37 | * @file trie_policy/prefix_search_node_update_imp.hpp |
36fed23c | 38 | * Contains an implementation of prefix_search_node_update. |
39 | */ | |
40 | ||
41 | PB_DS_CLASS_T_DEC | |
42 | std::pair< | |
43 | typename PB_DS_CLASS_C_DEC::const_iterator, | |
44 | typename PB_DS_CLASS_C_DEC::const_iterator> | |
45 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 46 | prefix_range(key_const_reference r_key) const |
36fed23c | 47 | { |
4f4a327e | 48 | const access_traits& r_traits = get_access_traits(); |
49 | return (prefix_range(r_traits.begin(r_key), r_traits.end(r_key))); | |
36fed23c | 50 | } |
51 | ||
52 | PB_DS_CLASS_T_DEC | |
53 | std::pair< | |
54 | typename PB_DS_CLASS_C_DEC::iterator, | |
55 | typename PB_DS_CLASS_C_DEC::iterator> | |
56 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 57 | prefix_range(key_const_reference r_key) |
36fed23c | 58 | { |
4f4a327e | 59 | return (prefix_range(get_access_traits().begin(r_key), |
60 | get_access_traits().end(r_key))); | |
36fed23c | 61 | } |
62 | ||
63 | PB_DS_CLASS_T_DEC | |
64 | std::pair< | |
65 | typename PB_DS_CLASS_C_DEC::const_iterator, | |
66 | typename PB_DS_CLASS_C_DEC::const_iterator> | |
67 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 68 | prefix_range(typename access_traits::const_iterator b, |
69 | typename access_traits::const_iterator e) const | |
36fed23c | 70 | { |
71 | const std::pair<iterator, iterator> non_const_ret = | |
72 | const_cast<PB_DS_CLASS_C_DEC* >(this)->prefix_range(b, e); | |
73 | ||
4f4a327e | 74 | return (std::make_pair(const_iterator(non_const_ret.first), |
36fed23c | 75 | const_iterator(non_const_ret.second))); |
76 | } | |
77 | ||
78 | PB_DS_CLASS_T_DEC | |
79 | std::pair< | |
80 | typename PB_DS_CLASS_C_DEC::iterator, | |
81 | typename PB_DS_CLASS_C_DEC::iterator> | |
82 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 83 | prefix_range(typename access_traits::const_iterator b, |
84 | typename access_traits::const_iterator e) | |
36fed23c | 85 | { |
4f4a327e | 86 | Node_Itr nd_it = node_begin(); |
87 | Node_Itr end_nd_it = node_end(); | |
36fed23c | 88 | |
4f4a327e | 89 | const access_traits& r_traits = get_access_traits(); |
36fed23c | 90 | const size_type given_range_length = std::distance(b, e); |
91 | ||
92 | while (true) | |
93 | { | |
94 | if (nd_it == end_nd_it) | |
95 | return (std::make_pair(end(), end())); | |
96 | ||
97 | const size_type common_range_length = | |
4f4a327e | 98 | base_type::common_prefix_len(nd_it, b, e, r_traits); |
36fed23c | 99 | |
100 | if (common_range_length >= given_range_length) | |
4f4a327e | 101 | { |
8411500a | 102 | iterator ret_b = this->leftmost_it(nd_it); |
8411500a | 103 | iterator ret_e = this->rightmost_it(nd_it); |
36fed23c | 104 | return (std::make_pair(ret_b, ++ret_e)); |
4f4a327e | 105 | } |
36fed23c | 106 | nd_it = next_child(nd_it, b, e, end_nd_it, r_traits); |
107 | } | |
108 | } | |
109 | ||
110 | PB_DS_CLASS_T_DEC | |
111 | typename PB_DS_CLASS_C_DEC::node_iterator | |
112 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 113 | next_child(node_iterator nd_it, typename access_traits::const_iterator b, |
114 | typename access_traits::const_iterator e, node_iterator end_nd_it, | |
115 | const access_traits& r_traits) | |
36fed23c | 116 | { |
117 | const size_type num_children = nd_it.num_children(); | |
36fed23c | 118 | node_iterator ret = end_nd_it; |
36fed23c | 119 | size_type max_length = 0; |
36fed23c | 120 | for (size_type i = 0; i < num_children; ++i) |
121 | { | |
122 | node_iterator pot = nd_it.get_child(i); | |
36fed23c | 123 | const size_type common_range_length = |
4f4a327e | 124 | base_type::common_prefix_len(pot, b, e, r_traits); |
36fed23c | 125 | |
126 | if (common_range_length > max_length) | |
4f4a327e | 127 | { |
36fed23c | 128 | ret = pot; |
36fed23c | 129 | max_length = common_range_length; |
4f4a327e | 130 | } |
36fed23c | 131 | } |
36fed23c | 132 | return (ret); |
133 | } | |
134 | ||
135 | PB_DS_CLASS_T_DEC | |
136 | inline void | |
137 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 138 | operator()(node_iterator /*nd_it*/, node_const_iterator /*end_nd_it*/) const |
36fed23c | 139 | { } |