MySQL 9.6.0
Source Code Documentation
nested_set_intersection_view.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_INTERSECTION_VIEW_H
25#define MYSQL_SETS_NESTED_SET_INTERSECTION_VIEW_H
26
27/// @file
28/// Experimental API header
29
30#include "mysql/sets/base_binary_operation_views.h" // Intersection_view
31#include "mysql/sets/nested_set_binary_operation_view_interface.h" // Nested_set_binary_operation_view_interface
32#include "mysql/sets/nested_set_meta.h" // Is_nested_set
33#include "mysql/sets/set_categories_and_traits.h" // Is_compatible_set
34
35/// @addtogroup GroupLibsMysqlSets
36/// @{
37
38namespace mysql::sets {
39
40/// View over the intersection of two nested sets.
41///
42/// @tparam Source1_tp The first source.
43///
44/// @tparam Source2_tp The second source.
45template <Is_nested_set Source1_tp, Is_nested_set Source2_tp>
46 requires Is_compatible_set<Source1_tp, Source2_tp>
47class Intersection_view<Source1_tp, Source2_tp>
48 : public detail::Nested_set_binary_operation_view_interface<
49 Intersection_view<Source1_tp, Source2_tp>, Source1_tp, Source2_tp,
50 Binary_operation::op_intersection> {
52 Intersection_view<Source1_tp, Source2_tp>, Source1_tp, Source2_tp,
54 using Base_t::m_source1;
55 using Base_t::m_source2;
56 using Base_t::make_iterator;
57
58 public:
59 using typename Base_t::Iterator_t;
60 using typename Base_t::Key_t;
61 using typename Base_t::Source1_t;
62 using typename Base_t::Source2_t;
64
66
67 /// Construct a new Intersection_view over the given sources.
68 ///
69 /// @param source1 The first source.
70 ///
71 /// @param source2 The second source.
72 Intersection_view(const Source1_t &source1, const Source2_t &source2) noexcept
73 : Base_t(source1, source2) {}
74
75 /// Construct a new Intersection_view over the given sources.
76 ///
77 /// Use this constructor if one of the sources may be empty and you do not
78 /// have an object representing it; then pass nullptr for that source.
79 ///
80 /// @param source1 The first source, or nullptr for empty set.
81 ///
82 /// @param source2 The second source, or nullptr for empty set.
83 Intersection_view(const Source1_t *source1, const Source2_t *source2) noexcept
84 : Base_t(source1, source2) {}
85
86 /// @return iterator to the first value pair.
87 [[nodiscard]] auto begin() const noexcept {
88 auto it1 = this->m_source1.begin();
89 if (it1 == this->m_source1.end()) return end();
90 return make_iterator(it1, this->m_source2.begin());
91 }
92
93 /// @return iterator to sentinel value pair.
94 [[nodiscard]] auto end() const noexcept {
95 return make_iterator(this->m_source1.end(), this->m_source2.end());
96 }
97
98 /// Return iterator to the given key, or end() if not found.
99 [[nodiscard]] auto find(const Key_t &key) const noexcept {
100 auto it1 = this->m_source1.find(key);
101 if (it1 == this->m_source1.end()) return end();
102 auto it2 = this->m_source2.find(key);
103 if (it2 == this->m_source2.end()) return end();
104 if (is_disjoint(it1->second, it2->second)) return end();
105 return make_iterator(it1, it2);
106 }
107
108 /// Return iterator to the given key, or end() if not found, using the given
109 /// iterator cursor as a hint.
110 ///
111 /// @param[in,out] cursor Hint for the position. The behavior is undefined if
112 /// this is greater than the lower bound for the key. It will be updated to
113 /// the upper bound for the key.
114 ///
115 /// @param key Key to search for.
116 ///
117 /// @return Iterator to the key, or end if not found.
118 [[nodiscard]] auto find(Iterator_t &cursor, const Key_t &key) const noexcept {
119 auto it1 = this->m_source1.find(cursor.iterator1(), key);
120 if (it1 == this->m_source1.end()) return end();
121 auto it2 = this->m_source2.find(cursor.iterator2(), key);
122 if (it2 == this->m_source2.end()) return end();
123 if (is_disjoint(it1->second, it2->second)) return end();
124 return make_iterator(it1, it2);
125 }
126}; // class Intersection_view
127
128} // namespace mysql::sets
129
130// addtogroup GroupLibsMysqlSets
131/// @}
132
133#endif // ifndef MYSQL_SETS_NESTED_SET_INTERSECTION_VIEW_H
Experimental API header.
CRTP base class to provide members of a collection based on an implementation that provides begin/end...
Definition: collection_interface.h:90
Self_tp Self_t
Definition: collection_interface.h:91
View over the intersection of two boundary sets.
Definition: boundary_set_intersection_view.h:51
auto find(Iterator_t &cursor, const Key_t &key) const noexcept
Return iterator to the given key, or end() if not found, using the given iterator cursor as a hint.
Definition: nested_set_intersection_view.h:118
auto find(const Key_t &key) const noexcept
Return iterator to the given key, or end() if not found.
Definition: nested_set_intersection_view.h:99
Intersection_view(const Source1_t *source1, const Source2_t *source2) noexcept
Construct a new Intersection_view over the given sources.
Definition: nested_set_intersection_view.h:83
auto begin() const noexcept
Definition: nested_set_intersection_view.h:87
auto end() const noexcept
Definition: nested_set_intersection_view.h:94
Primary template for views over intersections of two sets operations.
Definition: base_binary_operation_views.h:61
Iterator_tp Iterator_t
Definition: boundary_set_interface.h:75
Common base class for all the view classes.
Definition: nested_set_binary_operation_view_interface.h:86
typename Key_traits_t::Element_t Key_t
Definition: nested_set_interface.h:71
Definition: gtid_set.h:183
constexpr bool is_disjoint(const auto &lhs, const auto &rhs)
Return true if the two objects are disjoint (have nothing in common).
Definition: common_predicates.h:119
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Experimental API header.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Experimental API header.