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_PAT_TRIE_FIND_ITERATORS_HPP
48 #define PB_DS_PAT_TRIE_FIND_ITERATORS_HPP
50 #ifdef PB_DS_PAT_TRIE_DEBUG_
52 #endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
59 #define PB_DS_CONST_IT_C_DEC \
66 Is_Forward_Iterator, \
69 #define PB_DS_CONST_ODIR_IT_C_DEC \
76 !Is_Forward_Iterator, \
79 #define PB_DS_IT_C_DEC \
86 Is_Forward_Iterator, \
89 #define PB_DS_ODIR_IT_C_DEC \
96 !Is_Forward_Iterator, \
99 #ifdef PB_DS_PAT_TRIE_DEBUG_
100 #define PB_DS_DBG_ASSERT(X) assert(X)
101 #define PB_DS_DBG_VERIFY(X) assert(X)
102 #define PB_DS_DBG_ONLY(X) X
103 #else // #ifdef PB_DS_PAT_TRIE_DEBUG_
104 #define PB_DS_DBG_ASSERT(X)
105 #define PB_DS_DBG_VERIFY(X) {if((X)==0);}
106 #define PB_DS_DBG_ONLY(X) ;
107 #endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
110 template<typename Type_Traits,
115 bool Is_Forward_Iterator,
117 class pat_trie_const_it_
122 typename Allocator::template rebind<
123 Node>::other::pointer
127 typename Allocator::template rebind<
128 Leaf>::other::const_pointer
132 typename Allocator::template rebind<
133 Leaf>::other::pointer
137 typename Allocator::template rebind<
138 Head>::other::pointer
142 typename Allocator::template rebind<
143 Internal_Node>::other::pointer
144 internal_node_pointer;
148 typedef std::bidirectional_iterator_tag iterator_category;
150 typedef typename Allocator::difference_type difference_type;
152 typedef typename Type_Traits::value_type value_type;
154 typedef typename Type_Traits::pointer pointer;
156 typedef typename Type_Traits::const_pointer const_pointer;
158 typedef typename Type_Traits::reference reference;
160 typedef typename Type_Traits::const_reference const_reference;
165 pat_trie_const_it_(node_pointer p_nd = NULL) : m_p_nd(p_nd)
169 pat_trie_const_it_(const PB_DS_CONST_ODIR_IT_C_DEC&
170 other) : m_p_nd(other.m_p_nd)
174 PB_DS_CONST_IT_C_DEC&
175 operator=(const PB_DS_CONST_IT_C_DEC&
178 m_p_nd = other.m_p_nd;
184 PB_DS_CONST_IT_C_DEC&
185 operator=(const PB_DS_CONST_ODIR_IT_C_DEC&
188 m_p_nd = other.m_p_nd;
196 PB_DS_DBG_ASSERT(m_p_nd->m_type == pat_trie_leaf_node_type);
198 return (&static_cast<leaf_pointer>(m_p_nd)->value());
201 inline const_reference
204 PB_DS_DBG_ASSERT(m_p_nd->m_type == pat_trie_leaf_node_type);
206 return (static_cast<leaf_pointer>(m_p_nd)->value());
210 operator==(const PB_DS_CONST_IT_C_DEC
213 return (m_p_nd == other.m_p_nd);
217 operator==(const PB_DS_CONST_ODIR_IT_C_DEC
220 return (m_p_nd == other.m_p_nd);
224 operator!=(const PB_DS_CONST_IT_C_DEC&
227 return (m_p_nd != other.m_p_nd);
231 operator!=(const PB_DS_CONST_ODIR_IT_C_DEC&
234 return (m_p_nd != other.m_p_nd);
237 inline PB_DS_CONST_IT_C_DEC&
240 inc(integral_constant<int,Is_Forward_Iterator>());
245 inline PB_DS_CONST_IT_C_DEC
256 inline PB_DS_CONST_IT_C_DEC&
259 dec(integral_constant<int,Is_Forward_Iterator>());
264 inline PB_DS_CONST_IT_C_DEC
285 if (m_p_nd->m_type == pat_trie_head_node_type)
287 m_p_nd = static_cast<head_pointer>(m_p_nd)->m_p_min;
292 node_pointer p_y = m_p_nd->m_p_parent;
294 while (p_y->m_type != pat_trie_head_node_type&&
295 get_larger_sibling(m_p_nd) == NULL)
299 p_y = p_y->m_p_parent;
302 if (p_y->m_type == pat_trie_head_node_type)
309 m_p_nd = leftmost_descendant(get_larger_sibling(m_p_nd));
321 if (m_p_nd->m_type == pat_trie_head_node_type)
323 m_p_nd = static_cast<head_pointer>(m_p_nd)->m_p_max;
328 node_pointer p_y = m_p_nd->m_p_parent;
330 while (p_y->m_type != pat_trie_head_node_type&&
331 get_smaller_sibling(m_p_nd) == NULL)
335 p_y = p_y->m_p_parent;
338 if (p_y->m_type == pat_trie_head_node_type)
345 m_p_nd = rightmost_descendant(get_smaller_sibling(m_p_nd));
348 inline static node_pointer
349 get_larger_sibling(node_pointer p_nd)
351 internal_node_pointer p_parent =
352 static_cast<internal_node_pointer>(p_nd->m_p_parent);
354 typename Internal_Node::iterator it = p_parent->begin();
359 typename Internal_Node::iterator next_it = it;
362 return ((next_it == p_parent->end())? NULL :* next_it);
365 inline static node_pointer
366 get_smaller_sibling(node_pointer p_nd)
368 internal_node_pointer p_parent =
369 static_cast<internal_node_pointer>(p_nd->m_p_parent);
371 typename Internal_Node::iterator it = p_parent->begin();
376 typename Internal_Node::iterator prev_it;
389 PB_DS_DBG_ASSERT(false);
394 inline static leaf_pointer
395 leftmost_descendant(node_pointer p_nd)
397 if (p_nd->m_type == pat_trie_leaf_node_type)
398 return (static_cast<leaf_pointer>(p_nd));
400 return (static_cast<internal_node_pointer>(p_nd)->leftmost_descendant());
403 inline static leaf_pointer
404 rightmost_descendant(node_pointer p_nd)
406 if (p_nd->m_type == pat_trie_leaf_node_type)
407 return (static_cast<leaf_pointer>(p_nd));
409 return (static_cast<internal_node_pointer>(p_nd)->rightmost_descendant());
417 template<typename Type_Traits,
422 bool Is_Forward_Iterator,
425 public PB_DS_CONST_IT_C_DEC
431 typename Allocator::template rebind<
432 Node>::other::pointer
436 typename Allocator::template rebind<
437 Leaf>::other::const_pointer
441 typename Allocator::template rebind<
442 Leaf>::other::pointer
446 typename Allocator::template rebind<
447 Head>::other::pointer
451 typename Allocator::template rebind<
452 Internal_Node>::other::pointer
453 internal_node_pointer;
456 typedef typename Type_Traits::value_type value_type;
458 typedef typename Type_Traits::const_pointer const_pointer;
460 typedef typename Type_Traits::pointer pointer;
462 typedef typename Type_Traits::const_reference const_reference;
464 typedef typename Type_Traits::reference reference;
469 pat_trie_it_(node_pointer p_nd = NULL) : PB_DS_CONST_IT_C_DEC((node_pointer)p_nd)
473 pat_trie_it_(const PB_DS_ODIR_IT_C_DEC& other) : PB_DS_CONST_IT_C_DEC(other.m_p_nd)
478 operator=(const PB_DS_IT_C_DEC& other)
480 base_it_type::m_p_nd = other.m_p_nd;
487 operator=(const PB_DS_ODIR_IT_C_DEC& other)
489 base_it_type::m_p_nd = other.m_p_nd;
497 PB_DS_DBG_ASSERT(base_it_type::m_p_nd->m_type ==
498 pat_trie_leaf_node_type);
500 return (&static_cast<leaf_pointer>(base_it_type::m_p_nd)->value());
506 PB_DS_DBG_ASSERT(base_it_type::m_p_nd->m_type ==
507 pat_trie_leaf_node_type);
509 return (static_cast<leaf_pointer>(base_it_type::m_p_nd)->value());
512 inline PB_DS_IT_C_DEC&
515 PB_DS_CONST_IT_C_DEC::
521 inline PB_DS_IT_C_DEC
525 ret_it(base_it_type::m_p_nd);
532 inline PB_DS_IT_C_DEC&
535 PB_DS_CONST_IT_C_DEC::
541 inline PB_DS_IT_C_DEC
545 ret_it(base_it_type::m_p_nd);
553 typedef PB_DS_CONST_IT_C_DEC base_it_type;
555 friend class PB_DS_CLASS_C_DEC;
558 #undef PB_DS_CONST_IT_C_DEC
560 #undef PB_DS_CONST_ODIR_IT_C_DEC
562 #undef PB_DS_IT_C_DEC
564 #undef PB_DS_ODIR_IT_C_DEC
566 #undef PB_DS_DBG_ASSERT
567 #undef PB_DS_DBG_VERIFY
568 #undef PB_DS_DBG_ONLY
570 } // namespace detail
573 #endif // #ifndef PB_DS_PAT_TRIE_FIND_ITERATORS_HPP