]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
d652f226 | 3 | // Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc. |
4569a895 AT |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
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 | ||
748086b7 JJ |
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. | |
4569a895 | 19 | |
748086b7 JJ |
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/>. | |
4569a895 AT |
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 | /** | |
37 | * @file find_fn_imps.hpp | |
38 | * Contains an implementation class for bin_search_tree_. | |
39 | */ | |
40 | ||
41 | PB_DS_CLASS_T_DEC | |
42 | inline typename PB_DS_CLASS_C_DEC::const_point_iterator | |
43 | PB_DS_CLASS_C_DEC:: | |
44 | lower_bound(const_key_reference r_key) const | |
45 | { | |
46 | node_pointer p_pot = m_p_head; | |
47 | node_pointer p_nd = m_p_head->m_p_parent; | |
48 | ||
8fc81078 | 49 | while (p_nd != 0) |
4569a895 AT |
50 | if (Cmp_Fn::operator()( |
51 | PB_DS_V2F(p_nd->m_value), | |
52 | r_key)) | |
53 | p_nd = p_nd->m_p_right; | |
54 | else | |
55 | { | |
56 | p_pot = p_nd; | |
57 | ||
58 | p_nd = p_nd->m_p_left; | |
59 | } | |
60 | ||
61 | return (iterator(p_pot)); | |
62 | } | |
63 | ||
64 | PB_DS_CLASS_T_DEC | |
65 | inline typename PB_DS_CLASS_C_DEC::point_iterator | |
66 | PB_DS_CLASS_C_DEC:: | |
67 | lower_bound(const_key_reference r_key) | |
68 | { | |
69 | node_pointer p_pot = m_p_head; | |
70 | node_pointer p_nd = m_p_head->m_p_parent; | |
71 | ||
8fc81078 | 72 | while (p_nd != 0) |
4569a895 AT |
73 | if (Cmp_Fn::operator()( |
74 | PB_DS_V2F(p_nd->m_value), | |
75 | r_key)) | |
76 | p_nd = p_nd->m_p_right; | |
77 | else | |
78 | { | |
79 | p_pot = p_nd; | |
80 | ||
81 | p_nd = p_nd->m_p_left; | |
82 | } | |
83 | ||
84 | return (iterator(p_pot)); | |
85 | } | |
86 | ||
87 | PB_DS_CLASS_T_DEC | |
88 | inline typename PB_DS_CLASS_C_DEC::const_point_iterator | |
89 | PB_DS_CLASS_C_DEC:: | |
90 | upper_bound(const_key_reference r_key) const | |
91 | { | |
92 | node_pointer p_pot = m_p_head; | |
93 | node_pointer p_nd = m_p_head->m_p_parent; | |
94 | ||
8fc81078 | 95 | while (p_nd != 0) |
4569a895 AT |
96 | if (Cmp_Fn::operator()(r_key, |
97 | PB_DS_V2F(p_nd->m_value))) | |
98 | { | |
99 | p_pot = p_nd, | |
100 | ||
101 | p_nd = p_nd->m_p_left; | |
102 | } | |
103 | else | |
104 | p_nd = p_nd->m_p_right; | |
105 | ||
106 | return (const_iterator(p_pot)); | |
107 | } | |
108 | ||
109 | PB_DS_CLASS_T_DEC | |
110 | inline typename PB_DS_CLASS_C_DEC::point_iterator | |
111 | PB_DS_CLASS_C_DEC:: | |
112 | upper_bound(const_key_reference r_key) | |
113 | { | |
114 | node_pointer p_pot = m_p_head; | |
115 | node_pointer p_nd = m_p_head->m_p_parent; | |
116 | ||
8fc81078 | 117 | while (p_nd != 0) |
4569a895 AT |
118 | if (Cmp_Fn::operator()(r_key, |
119 | PB_DS_V2F(p_nd->m_value))) | |
120 | { | |
121 | p_pot = p_nd, | |
122 | ||
123 | p_nd = p_nd->m_p_left; | |
124 | } | |
125 | else | |
126 | p_nd = p_nd->m_p_right; | |
127 | ||
128 | return (point_iterator(p_pot)); | |
129 | } | |
130 | ||
131 | PB_DS_CLASS_T_DEC | |
132 | inline typename PB_DS_CLASS_C_DEC::point_iterator | |
133 | PB_DS_CLASS_C_DEC:: | |
134 | find(const_key_reference r_key) | |
135 | { | |
47bea7b8 | 136 | _GLIBCXX_DEBUG_ONLY(structure_only_assert_valid();) |
4569a895 AT |
137 | |
138 | node_pointer p_pot = m_p_head; | |
139 | node_pointer p_nd = m_p_head->m_p_parent; | |
140 | ||
8fc81078 | 141 | while (p_nd != 0) |
4569a895 AT |
142 | if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) |
143 | { | |
144 | p_pot = p_nd; | |
145 | ||
146 | p_nd = p_nd->m_p_left; | |
147 | } | |
148 | else | |
149 | p_nd = p_nd->m_p_right; | |
150 | ||
151 | return point_iterator((p_pot != m_p_head&& Cmp_Fn::operator()( | |
152 | r_key, | |
153 | PB_DS_V2F(p_pot->m_value)))? | |
154 | m_p_head : p_pot); | |
155 | } | |
156 | ||
157 | PB_DS_CLASS_T_DEC | |
158 | inline typename PB_DS_CLASS_C_DEC::const_point_iterator | |
159 | PB_DS_CLASS_C_DEC:: | |
160 | find(const_key_reference r_key) const | |
161 | { | |
47bea7b8 | 162 | _GLIBCXX_DEBUG_ONLY(structure_only_assert_valid();) |
4569a895 AT |
163 | |
164 | node_pointer p_pot = m_p_head; | |
165 | node_pointer p_nd = m_p_head->m_p_parent; | |
166 | ||
8fc81078 | 167 | while (p_nd != 0) |
4569a895 AT |
168 | if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) |
169 | { | |
170 | p_pot = p_nd; | |
171 | ||
172 | p_nd = p_nd->m_p_left; | |
173 | } | |
174 | else | |
175 | p_nd = p_nd->m_p_right; | |
176 | ||
177 | return const_point_iterator((p_pot != m_p_head&& Cmp_Fn::operator()( | |
178 | r_key, | |
179 | PB_DS_V2F(p_pot->m_value)))? | |
180 | m_p_head : p_pot); | |
181 | } | |
182 |