41 #ifndef PB_DS_OV_TREE_NODE_ITERATORS_HPP
42 #define PB_DS_OV_TREE_NODE_ITERATORS_HPP
52 #define PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC \
53 ov_tree_node_const_it_<Value_Type, Metadata_Type, _Alloc>
56 template<
typename Value_Type,
typename Metadata_Type,
typename _Alloc>
62 typename _Alloc::template rebind<
63 Value_Type>::other::pointer
67 typename _Alloc::template rebind<
68 Value_Type>::other::const_pointer
72 typename _Alloc::template rebind<
73 Metadata_Type>::other::const_pointer
74 const_metadata_pointer;
76 typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
this_type;
80 template<
typename Ptr>
82 mid_pointer(Ptr p_begin, Ptr p_end)
84 _GLIBCXX_DEBUG_ASSERT(p_end >= p_begin);
85 return (p_begin + (p_end - p_begin) / 2);
95 typename _Alloc::template rebind<
96 Value_Type>::other::const_pointer
100 typename _Alloc::template rebind<
101 typename remove_const<
102 Value_Type>::type>::other::const_pointer
106 typename _Alloc::template rebind<
107 typename remove_const<
108 Value_Type>::type>::other::const_pointer
111 typedef Metadata_Type metadata_type;
114 typename _Alloc::template rebind<
115 metadata_type>::other::const_reference
116 metadata_const_reference;
120 ov_tree_node_const_it_(const_pointer p_nd = 0, const_pointer p_begin_nd = 0, const_pointer p_end_nd = 0, const_metadata_pointer p_metadata = 0) : m_p_value(const_cast<pointer>(p_nd)), m_p_begin_value(const_cast<pointer>(p_begin_nd)), m_p_end_value(const_cast<pointer>(p_end_nd)), m_p_metadata(p_metadata)
123 inline const_reference
125 {
return m_p_value; }
127 inline metadata_const_reference
132 has_metadata = !is_same<Metadata_Type, null_type>::value
135 PB_DS_STATIC_ASSERT(should_have_metadata, has_metadata);
136 _GLIBCXX_DEBUG_ASSERT(m_p_metadata != 0);
137 return *m_p_metadata;
144 if (m_p_begin_value == m_p_value)
145 return (
this_type(m_p_begin_value, m_p_begin_value, m_p_begin_value));
147 const_metadata_pointer p_begin_metadata =
148 m_p_metadata - (m_p_value - m_p_begin_value);
150 return (
this_type(mid_pointer(m_p_begin_value, m_p_value),
153 mid_pointer(p_begin_metadata, m_p_metadata)));
160 if (m_p_value == m_p_end_value)
161 return (
this_type(m_p_end_value, m_p_end_value, m_p_end_value));
163 const_metadata_pointer p_end_metadata =
164 m_p_metadata + (m_p_end_value - m_p_value);
166 return (
this_type(mid_pointer(m_p_value + 1, m_p_end_value),
168 m_p_end_value,(m_p_metadata == 0) ?
169 0 : mid_pointer(m_p_metadata + 1, p_end_metadata)));
173 operator==(
const this_type& other)
const
175 const bool is_end = m_p_begin_value == m_p_end_value;
176 const bool is_other_end = other.m_p_begin_value == other.m_p_end_value;
179 return (is_other_end);
184 return m_p_value == other.m_p_value;
188 operator!=(
const this_type& other)
const
189 {
return !operator==(other); }
193 pointer m_p_begin_value;
194 pointer m_p_end_value;
196 const_metadata_pointer m_p_metadata;
199 #define PB_DS_OV_TREE_NODE_ITERATOR_C_DEC \
200 ov_tree_node_it_<Value_Type, Metadata_Type, _Alloc>
203 template<
typename Value_Type,
typename Metadata_Type,
typename _Alloc>
207 typedef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC
this_type;
209 typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
base_type;
211 typedef typename base_type::pointer pointer;
213 typedef typename base_type::const_pointer const_pointer;
216 typename base_type::const_metadata_pointer
217 const_metadata_pointer;
225 typename _Alloc::template rebind<
226 Value_Type>::other::pointer
230 typename _Alloc::template rebind<
231 typename remove_const<
232 Value_Type>::type>::other::pointer
236 typename _Alloc::template rebind<
237 typename remove_const<
238 Value_Type>::type>::other::pointer
242 ov_tree_node_it_(const_pointer p_nd = 0, const_pointer p_begin_nd = 0, const_pointer p_end_nd = 0, const_metadata_pointer p_metadata = 0) :
base_type(p_nd, p_begin_nd, p_end_nd, p_metadata)
248 {
return reference(base_type::m_p_value); }
254 if (base_type::m_p_begin_value == base_type::m_p_value)
255 return (
this_type(base_type::m_p_begin_value, base_type::m_p_begin_value, base_type::m_p_begin_value));
257 const_metadata_pointer p_begin_metadata =
258 base_type::m_p_metadata - (base_type::m_p_value - base_type::m_p_begin_value);
260 return (
this_type(base_type::mid_pointer(base_type::m_p_begin_value, base_type::m_p_value),
261 base_type::m_p_begin_value,
262 base_type::m_p_value,
263 base_type::mid_pointer(p_begin_metadata, base_type::m_p_metadata)));
270 if (base_type::m_p_value == base_type::m_p_end_value)
271 return this_type(base_type::m_p_end_value, base_type::m_p_end_value,
272 base_type::m_p_end_value);
274 const_metadata_pointer p_end_metadata =
275 base_type::m_p_metadata + (base_type::m_p_end_value - base_type::m_p_value);
277 return (
this_type(base_type::mid_pointer(base_type::m_p_value + 1, base_type::m_p_end_value),
278 base_type::m_p_value + 1,
279 base_type::m_p_end_value,(base_type::m_p_metadata == 0)?
280 0 : base_type::mid_pointer(base_type::m_p_metadata + 1, p_end_metadata)));
285 #undef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC
286 #undef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
A trivial iterator tag. Signifies that the iterators has none of std::iterators's movement abilities...
ov_tree_node_it_ get_l_child() const
Returns the node reference associated with the left node.
reference operator*() const
Access.
this_type get_l_child() const
Returns the node iterator associated with the left node.
void trivial_iterator_difference_type
Prohibit moving trivial iterators.
this_type get_r_child() const
Returns the node iterator associated with the right node.
ov_tree_node_it_ get_r_child() const
Returns the node reference associated with the right node.