MySQL 9.6.0
Source Code Documentation
nested_set_union_iterator.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_SETS_NESTED_SET_UNION_ITERATOR_H
25#define MYSQL_SETS_NESTED_SET_UNION_ITERATOR_H
26
27/// @file
28/// Experimental API header
29
30#include <cassert> // assert
31#include "mysql/sets/binary_operation.h" // Binary_operation
32#include "mysql/sets/nested_set_binary_operation_iterator_base.h" // Nested_set_binary_operation_iterator_base
33#include "mysql/sets/nested_set_meta.h" // Is_nested_set
34#include "mysql/sets/set_categories_and_traits.h" // Is_compatible_set
35
36/// @addtogroup GroupLibsMysqlSets
37/// @{
38
39namespace mysql::sets::detail {
40
41/// Iterator over the union of two sets.
42///
43/// @tparam Source1_tp The first source.
44///
45/// @tparam Source2_tp The second source.
46template <Is_nested_set Source1_tp, Is_nested_set Source2_tp>
47 requires Is_compatible_set<Source1_tp, Source2_tp>
50 Nested_set_union_iterator<Source1_tp, Source2_tp>, Source1_tp,
51 Source2_tp, Binary_operation::op_union> {
53 using Base_t =
56
57 public:
58 using typename Base_t::Iterator1_t;
59 using typename Base_t::Iterator2_t;
60 using typename Base_t::Key_traits_t;
61 using typename Base_t::Source1_t;
62 using typename Base_t::Source2_t;
63 using typename Base_t::Value_t;
64
66
67 // Construct from two sources and one iterator into each of them.
68 Nested_set_union_iterator(const Source1_t *source1, const Source2_t *source2,
71 : Base_t(source1, source2, iterator1, iterator2) {
73 }
74
75 /// @return The value that this iterator currently points to.
76 [[nodiscard]] auto get() const {
77 if (m_order < 0) return this->make_value1();
78 if (m_order > 0) return this->make_value2();
79 assert(m_order == 0);
80 return this->make_value();
81 }
82
83 /// Move to the next iterator position.
84 void next() {
85 if (m_order <= 0) ++this->m_iterator1;
86 if (m_order >= 0) ++this->m_iterator2;
88 }
89
90 /// @return true if this iterator equals other.
91 [[nodiscard]] bool is_equal(const Nested_set_union_iterator &other) const {
92 if (m_order <= 0)
93 return this->m_iterator1 == other.m_iterator1;
94 else
95 return this->m_iterator2 == other.m_iterator2;
96 }
97
98 private:
99 /// Store `less`, `equals`, or `greater` in `m_order`, according to how
100 /// `m_iterator1` compares to `m_iterator2`.
102 if (this->m_iterator2 == this->m_source2.end()) {
103 if (this->m_iterator1 == this->m_source1.end()) {
105 } else {
106 m_order = std::strong_ordering::less;
107 }
108 } else {
109 if (this->m_iterator1 == this->m_source1.end()) {
110 m_order = std::strong_ordering::greater;
111 } else {
113 this->m_iterator2->first);
114 }
115 }
116 }
117
118 /// The relative order of the two current iterator positions.
120}; // class Nested_set_union_iterator
121
122} // namespace mysql::sets::detail
123
124// addtogroup GroupLibsMysqlSets
125/// @}
126
127#endif // ifndef MYSQL_SETS_NESTED_SET_UNION_ITERATOR_H
Experimental API header.
Self_tp Self_t
Definition: iterator_interface.h:372
auto end() const
Return a valid end iterator, even if !has_object().
Definition: view_sources.h:273
Common base class for the forward iterators over union view, intersection view, and subtraction view ...
Definition: nested_set_binary_operation_iterator_base.h:54
Source2_tp Source2_t
Definition: nested_set_binary_operation_iterator_base.h:57
typename Source2_t::Const_iterator_t Iterator2_t
Definition: nested_set_binary_operation_iterator_base.h:63
typename Source1_tp::Key_traits_t Key_traits_t
Definition: nested_set_binary_operation_iterator_base.h:64
Value_t make_value2() const
Return the current value, computed as operation(nullptr, m_iterator2).
Definition: nested_set_binary_operation_iterator_base.h:124
std::pair< const Key_t, Mapped_t > Value_t
Definition: nested_set_binary_operation_iterator_base.h:69
Value_t make_value1() const
Return the current value, computed as operation(m_iterator1, nullptr).
Definition: nested_set_binary_operation_iterator_base.h:119
Source1_tp Source1_t
Definition: nested_set_binary_operation_iterator_base.h:56
const auto & iterator2() const
Return const reference to the current iterator into the second set.
Definition: nested_set_binary_operation_iterator_base.h:106
typename Source1_t::Const_iterator_t Iterator1_t
Definition: nested_set_binary_operation_iterator_base.h:62
Value_t make_value() const
Return the current value, computed as operation(m_iterator1, m_iterator2).
Definition: nested_set_binary_operation_iterator_base.h:113
const auto & iterator1() const
Return const reference to the current iterator into the first set.
Definition: nested_set_binary_operation_iterator_base.h:100
Iterator over the union of two sets.
Definition: nested_set_union_iterator.h:51
Source2_tp Source2_t
Definition: nested_set_binary_operation_iterator_base.h:57
bool is_equal(const Nested_set_union_iterator &other) const
Definition: nested_set_union_iterator.h:91
void compute_order()
Store less, equals, or greater in m_order, according to how m_iterator1 compares to m_iterator2.
Definition: nested_set_union_iterator.h:101
Nested_set_union_iterator(const Source1_t *source1, const Source2_t *source2, const Iterator1_t &iterator1, const Iterator2_t &iterator2)
Definition: nested_set_union_iterator.h:68
typename Source2_t::Const_iterator_t Iterator2_t
Definition: nested_set_binary_operation_iterator_base.h:63
void next()
Move to the next iterator position.
Definition: nested_set_union_iterator.h:84
Source1_tp Source1_t
Definition: nested_set_binary_operation_iterator_base.h:56
auto get() const
Definition: nested_set_union_iterator.h:76
Nested_set_union_iterator< Source1_tp, Source2_tp > Self_t
Definition: nested_set_union_iterator.h:52
typename Source1_t::Const_iterator_t Iterator1_t
Definition: nested_set_binary_operation_iterator_base.h:62
std::strong_ordering m_order
The relative order of the two current iterator positions.
Definition: nested_set_union_iterator.h:119
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1064
static bool equal(const Item *i1, const Item *i2, const Field *f2)
Definition: sql_select.cc:3935
Definition: aliases.h:97
Experimental API header.
Experimental API header.