• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/arm-none-eabi/include/c++/4.6.1/ext/pb_ds/detail/left_child_next_sibling_heap_/
1// -*- C++ -*-
2
3// Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
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
8// Foundation; either version 3, or (at your option) any later
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
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.
19
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/>.
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 const_iterator.hpp
38 * Contains an iterator class returned by the table's const find and insert
39 *     methods.
40 */
41
42#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP
43#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP
44
45#include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_point_iterator.hpp>
46#include <debug/debug.h>
47
48namespace __gnu_pbds
49{
50  namespace detail
51  {
52
53#define PB_DS_CLASS_C_DEC						\
54    left_child_next_sibling_heap_const_iterator_<Node, Allocator>
55
56#define PB_DS_BASE_C_DEC						\
57    left_child_next_sibling_heap_node_const_point_iterator_<Node, Allocator>
58
59    // Const point-type iterator.
60    template<typename Node, class Allocator>
61    class left_child_next_sibling_heap_const_iterator_ : public PB_DS_BASE_C_DEC
62    {
63
64    private:
65      typedef typename PB_DS_BASE_C_DEC::node_pointer node_pointer;
66
67      typedef PB_DS_BASE_C_DEC base_type;
68
69    public:
70
71      // Category.
72      typedef std::forward_iterator_tag iterator_category;
73
74      // Difference type.
75      typedef typename Allocator::difference_type difference_type;
76
77      // Iterator's value type.
78      typedef typename base_type::value_type value_type;
79
80      // Iterator's pointer type.
81      typedef typename base_type::pointer pointer;
82
83      // Iterator's const pointer type.
84      typedef typename base_type::const_pointer const_pointer;
85
86      // Iterator's reference type.
87      typedef typename base_type::reference reference;
88
89      // Iterator's const reference type.
90      typedef typename base_type::const_reference const_reference;
91
92    public:
93
94      inline
95      left_child_next_sibling_heap_const_iterator_(node_pointer p_nd) : base_type(p_nd)
96      { }
97
98      // Default constructor.
99      inline
100      left_child_next_sibling_heap_const_iterator_()
101      { }
102
103      // Copy constructor.
104      inline
105      left_child_next_sibling_heap_const_iterator_(const PB_DS_CLASS_C_DEC& other) : base_type(other)
106      { }
107
108      // Compares content to a different iterator object.
109      inline bool
110      operator==(const PB_DS_CLASS_C_DEC& other) const
111      { return (base_type::m_p_nd == other.m_p_nd); }
112
113      // Compares content (negatively) to a different iterator object.
114      inline bool
115      operator!=(const PB_DS_CLASS_C_DEC& other) const
116      { return (base_type::m_p_nd != other.m_p_nd); }
117
118      inline PB_DS_CLASS_C_DEC&
119      operator++()
120      {
121	_GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd != 0);
122	inc();
123	return (*this);
124      }
125
126      inline PB_DS_CLASS_C_DEC
127      operator++(int)
128      {
129	PB_DS_CLASS_C_DEC ret_it(base_type::m_p_nd);
130	operator++();
131	return (ret_it);
132      }
133
134    private:
135      void
136      inc()
137      {
138	if (base_type::m_p_nd->m_p_next_sibling != 0)
139	  {
140	    base_type::m_p_nd = base_type::m_p_nd->m_p_next_sibling;
141	    while (base_type::m_p_nd->m_p_l_child != 0)
142	      base_type::m_p_nd = base_type::m_p_nd->m_p_l_child;
143	    return;
144	  }
145
146	while (true)
147	  {
148	    node_pointer p_next = base_type::m_p_nd;
149	    base_type::m_p_nd = base_type::m_p_nd->m_p_prev_or_parent;
150	    if (base_type::m_p_nd == 0 || base_type::m_p_nd->m_p_l_child == p_next)
151	      return;
152	  }
153      }
154    };
155
156#undef PB_DS_CLASS_C_DEC
157#undef PB_DS_BASE_C_DEC
158
159  } // namespace detail
160} // namespace __gnu_pbds
161
162#endif
163