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 point_iterators.hpp
44 * Contains an implementation class for bin_search_tree_.
47 #ifndef PB_DS_BIN_SEARCH_TREE_FIND_ITERATORS_HPP
48 #define PB_DS_BIN_SEARCH_TREE_FIND_ITERATORS_HPP
50 #ifdef PB_DS_BIN_SEARCH_TREE_DEBUG_
52 #endif // #ifdef PB_DS_BIN_SEARCH_TREE_DEBUG_
53 #include <ext/pb_ds/tag_and_trait.hpp>
60 #define PB_DS_TREE_CONST_IT_C_DEC \
61 bin_search_tree_const_it_< \
68 Is_Forward_Iterator, \
71 #define PB_DS_TREE_CONST_ODIR_IT_C_DEC \
72 bin_search_tree_const_it_< \
79 !Is_Forward_Iterator, \
82 #define PB_DS_TREE_IT_C_DEC \
83 bin_search_tree_it_< \
90 Is_Forward_Iterator, \
93 #define PB_DS_TREE_ODIR_IT_C_DEC \
94 bin_search_tree_it_< \
101 !Is_Forward_Iterator, \
104 #ifdef PB_DS_BIN_SEARCH_TREE_DEBUG_
105 #define PB_DS_DBG_ASSERT(X) assert(X)
106 #define PB_DS_DBG_VERIFY(X) assert(X)
107 #define PB_DS_DBG_ONLY(X) X
108 #else // #ifdef PB_DS_BIN_SEARCH_TREE_DEBUG_
109 #define PB_DS_DBG_ASSERT(X)
110 #define PB_DS_DBG_VERIFY(X) {if((X)==0);}
111 #define PB_DS_DBG_ONLY(X) ;
112 #endif // #ifdef PB_DS_BIN_SEARCH_TREE_DEBUG_
115 template<typename Node_Pointer,
118 typename Const_Pointer,
120 typename Const_Reference,
121 bool Is_Forward_Iterator,
123 class bin_search_tree_const_it_
128 typedef std::bidirectional_iterator_tag iterator_category;
130 typedef typename Allocator::difference_type difference_type;
132 typedef Value_Type value_type;
134 typedef Pointer pointer;
136 typedef Const_Pointer const_pointer;
138 typedef Reference reference;
140 typedef Const_Reference const_reference;
145 bin_search_tree_const_it_(const Node_Pointer p_nd = NULL) : m_p_nd(const_cast<Node_Pointer>(p_nd))
149 bin_search_tree_const_it_(const PB_DS_TREE_CONST_ODIR_IT_C_DEC&
150 other) : m_p_nd(other.m_p_nd)
154 PB_DS_TREE_CONST_IT_C_DEC&
155 operator=(const PB_DS_TREE_CONST_IT_C_DEC&
158 m_p_nd = other.m_p_nd;
164 PB_DS_TREE_CONST_IT_C_DEC&
165 operator=(const PB_DS_TREE_CONST_ODIR_IT_C_DEC&
168 m_p_nd = other.m_p_nd;
176 PB_DS_DBG_ASSERT(m_p_nd != NULL);
178 return (&m_p_nd->m_value);
181 inline const_reference
184 PB_DS_DBG_ASSERT(m_p_nd != NULL);
186 return (m_p_nd->m_value);
190 operator==(const PB_DS_TREE_CONST_IT_C_DEC
193 return (m_p_nd == other.m_p_nd);
197 operator==(const PB_DS_TREE_CONST_ODIR_IT_C_DEC
200 return (m_p_nd == other.m_p_nd);
204 operator!=(const PB_DS_TREE_CONST_IT_C_DEC&
207 return (m_p_nd != other.m_p_nd);
211 operator!=(const PB_DS_TREE_CONST_ODIR_IT_C_DEC&
214 return (m_p_nd != other.m_p_nd);
217 inline PB_DS_TREE_CONST_IT_C_DEC&
220 PB_DS_DBG_ASSERT(m_p_nd != NULL);
222 inc(integral_constant<int,Is_Forward_Iterator>());
227 inline PB_DS_TREE_CONST_IT_C_DEC
230 PB_DS_TREE_CONST_IT_C_DEC
238 inline PB_DS_TREE_CONST_IT_C_DEC&
241 dec(integral_constant<int,Is_Forward_Iterator>());
246 inline PB_DS_TREE_CONST_IT_C_DEC
249 PB_DS_TREE_CONST_IT_C_DEC
267 if (m_p_nd->special()&&
268 m_p_nd->m_p_parent->m_p_parent == m_p_nd)
270 m_p_nd = m_p_nd->m_p_left;
275 if (m_p_nd->m_p_right != NULL)
277 m_p_nd = m_p_nd->m_p_right;
279 while (m_p_nd->m_p_left != NULL)
280 m_p_nd = m_p_nd->m_p_left;
285 Node_Pointer p_y = m_p_nd->m_p_parent;
287 while (m_p_nd == p_y->m_p_right)
291 p_y = p_y->m_p_parent;
294 if (m_p_nd->m_p_right != p_y)
307 if (m_p_nd->special()&&
308 m_p_nd->m_p_parent->m_p_parent == m_p_nd)
310 m_p_nd = m_p_nd->m_p_right;
315 if (m_p_nd->m_p_left != NULL)
317 Node_Pointer p_y = m_p_nd->m_p_left;
319 while (p_y->m_p_right != NULL)
320 p_y = p_y->m_p_right;
327 Node_Pointer p_y = m_p_nd->m_p_parent;
329 while (m_p_nd == p_y->m_p_left)
333 p_y = p_y->m_p_parent;
336 if (m_p_nd->m_p_left != p_y)
345 template<typename Node_Pointer,
348 typename Const_Pointer,
350 typename Const_Reference,
351 bool Is_Forward_Iterator,
353 class bin_search_tree_it_ :
354 public PB_DS_TREE_CONST_IT_C_DEC
361 bin_search_tree_it_(const Node_Pointer p_nd = NULL) : PB_DS_TREE_CONST_IT_C_DEC((Node_Pointer)p_nd)
365 bin_search_tree_it_(const PB_DS_TREE_ODIR_IT_C_DEC& other) : PB_DS_TREE_CONST_IT_C_DEC(other.m_p_nd)
370 operator=(const PB_DS_TREE_IT_C_DEC& other)
372 base_it_type::m_p_nd = other.m_p_nd;
379 operator=(const PB_DS_TREE_ODIR_IT_C_DEC& other)
381 base_it_type::m_p_nd = other.m_p_nd;
386 inline typename PB_DS_TREE_CONST_IT_C_DEC::pointer
389 PB_DS_DBG_ASSERT(base_it_type::m_p_nd != NULL);
391 return (&base_it_type::m_p_nd->m_value);
394 inline typename PB_DS_TREE_CONST_IT_C_DEC::reference
397 PB_DS_DBG_ASSERT(base_it_type::m_p_nd != NULL);
399 return (base_it_type::m_p_nd->m_value);
402 inline PB_DS_TREE_IT_C_DEC&
405 PB_DS_TREE_CONST_IT_C_DEC::
411 inline PB_DS_TREE_IT_C_DEC
415 ret_it(base_it_type::m_p_nd);
422 inline PB_DS_TREE_IT_C_DEC&
425 PB_DS_TREE_CONST_IT_C_DEC::
431 inline PB_DS_TREE_IT_C_DEC
435 ret_it(base_it_type::m_p_nd);
443 typedef PB_DS_TREE_CONST_IT_C_DEC base_it_type;
446 #undef PB_DS_TREE_CONST_IT_C_DEC
448 #undef PB_DS_TREE_CONST_ODIR_IT_C_DEC
450 #undef PB_DS_TREE_IT_C_DEC
452 #undef PB_DS_TREE_ODIR_IT_C_DEC
454 #undef PB_DS_DBG_ASSERT
455 #undef PB_DS_DBG_VERIFY
456 #undef PB_DS_DBG_ONLY
458 } // namespace detail
461 #endif // #ifndef PB_DS_BIN_SEARCH_TREE_FIND_ITERATORS_HPP