]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / bin_search_tree_ / node_iterators.hpp
CommitLineData
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.
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/**
a345e45d 37 * @file bin_search_tree_/node_iterators.hpp
4569a895
AT
38 * Contains an implementation class for bin_search_tree_.
39 */
40
41#ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
42#define PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
43
44#include <ext/pb_ds/tag_and_trait.hpp>
45
5e11f978 46namespace __gnu_pbds
4569a895
AT
47{
48 namespace detail
49 {
30a96b3b
BK
50#define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC \
51 bin_search_tree_const_node_it_<Node, Const_Iterator, Iterator, _Alloc>
4569a895 52
a345e45d 53 /// Const node iterator.
4569a895
AT
54 template<typename Node,
55 class Const_Iterator,
56 class Iterator,
a345e45d 57 typename _Alloc>
4569a895
AT
58 class bin_search_tree_const_node_it_
59 {
4569a895 60 private:
ec541f1b 61 typedef typename rebind_traits<_Alloc, Node>::pointer node_pointer;
4569a895
AT
62
63 public:
30a96b3b 64 /// Category.
4569a895
AT
65 typedef trivial_iterator_tag iterator_category;
66
30a96b3b 67 /// Difference type.
4569a895
AT
68 typedef trivial_iterator_difference_type difference_type;
69
30a96b3b 70 /// Iterator's value type.
4569a895
AT
71 typedef Const_Iterator value_type;
72
30a96b3b 73 /// Iterator's reference type.
4569a895
AT
74 typedef Const_Iterator reference;
75
30a96b3b 76 /// Iterator's __const reference type.
4569a895
AT
77 typedef Const_Iterator const_reference;
78
30a96b3b 79 /// Metadata type.
4569a895
AT
80 typedef typename Node::metadata_type metadata_type;
81
30a96b3b 82 /// Const metadata reference type.
ec541f1b
JW
83 typedef typename rebind_traits<_Alloc, metadata_type>::const_reference
84 metadata_const_reference;
4569a895 85
4569a895 86
30a96b3b 87 bin_search_tree_const_node_it_(const node_pointer p_nd = 0)
a345e45d 88 : m_p_nd(const_cast<node_pointer>(p_nd))
4569a895
AT
89 { }
90
30a96b3b
BK
91 /// Access.
92 const_reference
4569a895 93 operator*() const
30a96b3b 94 { return Const_Iterator(m_p_nd); }
4569a895 95
30a96b3b
BK
96 /// Metadata access.
97 metadata_const_reference
4569a895 98 get_metadata() const
30a96b3b 99 { return m_p_nd->get_metadata(); }
4569a895 100
30a96b3b
BK
101 /// Returns the __const node iterator associated with the left node.
102 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 103 get_l_child() const
30a96b3b 104 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_left); }
4569a895 105
30a96b3b
BK
106 /// Returns the __const node iterator associated with the right node.
107 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 108 get_r_child() const
30a96b3b 109 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_right); }
4569a895 110
30a96b3b
BK
111 /// Compares to a different iterator object.
112 bool
4569a895 113 operator==(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
30a96b3b 114 { return m_p_nd == other.m_p_nd; }
4569a895 115
30a96b3b
BK
116 /// Compares (negatively) to a different iterator object.
117 bool
4569a895 118 operator!=(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
30a96b3b 119 { return m_p_nd != other.m_p_nd; }
4569a895 120
4569a895
AT
121 node_pointer m_p_nd;
122 };
123
30a96b3b
BK
124#define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC \
125 bin_search_tree_node_it_<Node, Const_Iterator, Iterator, _Alloc>
4569a895 126
a345e45d 127 /// Node iterator.
4569a895
AT
128 template<typename Node,
129 class Const_Iterator,
130 class Iterator,
a345e45d 131 typename _Alloc>
30a96b3b 132 class bin_search_tree_node_it_
a345e45d 133 : public PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 134 {
4569a895 135 private:
ec541f1b 136 typedef typename rebind_traits<_Alloc, Node>::pointer node_pointer;
4569a895
AT
137
138 public:
30a96b3b 139 /// Iterator's value type.
4569a895
AT
140 typedef Iterator value_type;
141
30a96b3b 142 /// Iterator's reference type.
4569a895
AT
143 typedef Iterator reference;
144
30a96b3b 145 /// Iterator's __const reference type.
4569a895
AT
146 typedef Iterator const_reference;
147
4569a895 148 inline
30a96b3b 149 bin_search_tree_node_it_(const node_pointer p_nd = 0)
a345e45d 150 : PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(const_cast<node_pointer>(p_nd))
4569a895
AT
151 { }
152
30a96b3b
BK
153 /// Access.
154 Iterator
4569a895 155 operator*() const
30a96b3b 156 { return Iterator(PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd); }
4569a895 157
30a96b3b
BK
158 /// Returns the node iterator associated with the left node.
159 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
160 get_l_child() const
161 {
30a96b3b
BK
162 return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC(
163 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_left);
4569a895
AT
164 }
165
30a96b3b
BK
166 /// Returns the node iterator associated with the right node.
167 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
168 get_r_child() const
169 {
30a96b3b
BK
170 return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC(
171 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_right);
4569a895
AT
172 }
173
174 };
175
176#undef PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
177#undef PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
178
179 } // namespace detail
5e11f978 180} // namespace __gnu_pbds
4569a895
AT
181
182#endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP