]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
7adcbafe | 3 | // Copyright (C) 2005-2022 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. | |
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/>. | |
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 | /** | |
a345e45d | 37 | * @file left_child_next_sibling_heap_/const_iterator.hpp |
4569a895 | 38 | * Contains an iterator class returned by the table's const find and insert |
a345e45d | 39 | * methods. |
4569a895 AT |
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 | ||
a345e45d | 45 | #include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp> |
47bea7b8 | 46 | #include <debug/debug.h> |
4569a895 | 47 | |
5e11f978 | 48 | namespace __gnu_pbds |
4569a895 AT |
49 | { |
50 | namespace detail | |
51 | { | |
a345e45d BK |
52 | #define PB_DS_CLASS_C_DEC \ |
53 | left_child_next_sibling_heap_const_iterator_<Node, _Alloc> | |
4569a895 | 54 | |
a345e45d BK |
55 | #define PB_DS_BASIC_HEAP_CIT_BASE \ |
56 | left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc> | |
4569a895 | 57 | |
a345e45d BK |
58 | /// Const point-type iterator. |
59 | template<typename Node, typename _Alloc> | |
60 | class left_child_next_sibling_heap_const_iterator_ | |
61 | : public PB_DS_BASIC_HEAP_CIT_BASE | |
4569a895 | 62 | { |
4569a895 | 63 | private: |
a345e45d BK |
64 | typedef PB_DS_BASIC_HEAP_CIT_BASE base_type; |
65 | typedef typename base_type::node_pointer node_pointer; | |
4569a895 AT |
66 | |
67 | public: | |
30a96b3b | 68 | /// Category. |
a345e45d | 69 | typedef std::forward_iterator_tag iterator_category; |
4569a895 | 70 | |
30a96b3b | 71 | /// Difference type. |
a345e45d | 72 | typedef typename _Alloc::difference_type difference_type; |
4569a895 | 73 | |
30a96b3b | 74 | /// Iterator's value type. |
a345e45d | 75 | typedef typename base_type::value_type value_type; |
4569a895 | 76 | |
30a96b3b | 77 | /// Iterator's pointer type. |
a345e45d | 78 | typedef typename base_type::pointer pointer; |
4569a895 | 79 | |
30a96b3b | 80 | /// Iterator's const pointer type. |
a345e45d | 81 | typedef typename base_type::const_pointer const_pointer; |
4569a895 | 82 | |
30a96b3b | 83 | /// Iterator's reference type. |
a345e45d | 84 | typedef typename base_type::reference reference; |
4569a895 | 85 | |
30a96b3b | 86 | /// Iterator's const reference type. |
a345e45d | 87 | typedef typename base_type::const_reference const_reference; |
4569a895 AT |
88 | |
89 | inline | |
a345e45d BK |
90 | left_child_next_sibling_heap_const_iterator_(node_pointer p_nd) |
91 | : base_type(p_nd) | |
4569a895 AT |
92 | { } |
93 | ||
30a96b3b | 94 | /// Default constructor. |
4569a895 AT |
95 | inline |
96 | left_child_next_sibling_heap_const_iterator_() | |
97 | { } | |
98 | ||
30a96b3b | 99 | /// Copy constructor. |
4569a895 AT |
100 | inline |
101 | left_child_next_sibling_heap_const_iterator_(const PB_DS_CLASS_C_DEC& other) : base_type(other) | |
102 | { } | |
103 | ||
30a96b3b BK |
104 | /// Compares content to a different iterator object. |
105 | bool | |
4569a895 | 106 | operator==(const PB_DS_CLASS_C_DEC& other) const |
47bea7b8 | 107 | { return (base_type::m_p_nd == other.m_p_nd); } |
4569a895 | 108 | |
30a96b3b BK |
109 | /// Compares content (negatively) to a different iterator object. |
110 | bool | |
4569a895 | 111 | operator!=(const PB_DS_CLASS_C_DEC& other) const |
47bea7b8 | 112 | { return (base_type::m_p_nd != other.m_p_nd); } |
4569a895 | 113 | |
30a96b3b | 114 | PB_DS_CLASS_C_DEC& |
4569a895 AT |
115 | operator++() |
116 | { | |
8fc81078 | 117 | _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd != 0); |
4569a895 | 118 | inc(); |
4569a895 AT |
119 | return (*this); |
120 | } | |
121 | ||
30a96b3b | 122 | PB_DS_CLASS_C_DEC |
4569a895 AT |
123 | operator++(int) |
124 | { | |
125 | PB_DS_CLASS_C_DEC ret_it(base_type::m_p_nd); | |
4569a895 | 126 | operator++(); |
4569a895 AT |
127 | return (ret_it); |
128 | } | |
129 | ||
130 | private: | |
131 | void | |
132 | inc() | |
133 | { | |
8fc81078 | 134 | if (base_type::m_p_nd->m_p_next_sibling != 0) |
4569a895 AT |
135 | { |
136 | base_type::m_p_nd = base_type::m_p_nd->m_p_next_sibling; | |
8fc81078 | 137 | while (base_type::m_p_nd->m_p_l_child != 0) |
4569a895 | 138 | base_type::m_p_nd = base_type::m_p_nd->m_p_l_child; |
4569a895 AT |
139 | return; |
140 | } | |
141 | ||
142 | while (true) | |
143 | { | |
144 | node_pointer p_next = base_type::m_p_nd; | |
145 | base_type::m_p_nd = base_type::m_p_nd->m_p_prev_or_parent; | |
a345e45d BK |
146 | if (base_type::m_p_nd == 0 |
147 | || base_type::m_p_nd->m_p_l_child == p_next) | |
4569a895 AT |
148 | return; |
149 | } | |
150 | } | |
151 | }; | |
152 | ||
153 | #undef PB_DS_CLASS_C_DEC | |
a345e45d | 154 | #undef PB_DS_BASIC_HEAP_CIT_BASE |
4569a895 | 155 | |
4569a895 | 156 | } // namespace detail |
5e11f978 | 157 | } // namespace __gnu_pbds |
4569a895 | 158 | |
a345e45d | 159 | #endif |