MySQL 9.6.0
Source Code Documentation
nested_set_subtraction_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_SUBTRACTION_VIEW_H
25#define MYSQL_SETS_NESTED_SET_SUBTRACTION_VIEW_H
26
27/// @file
28/// Experimental API header
29
30#include "mysql/sets/base_binary_operation_views.h" // Subtraction_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 difference 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 Subtraction_view<Source1_tp, Source2_tp>
48 : public detail::Nested_set_binary_operation_view_interface<
49 Subtraction_view<Source1_tp, Source2_tp>, Source1_tp, Source2_tp,
50 Binary_operation::op_subtraction> {
52 Subtraction_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 Subtraction_view over the given sources.
68 ///
69 /// @param source1 The first source.
70 ///
71 /// @param source2 The second source.
72 Subtraction_view(const Source1_t &source1, const Source2_t &source2) noexcept
73 : Base_t(source1, source2) {}
74
75 /// Construct a new Subtraction_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 Subtraction_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 return make_iterator(this->m_source1.begin(), this->m_source2.begin());
89 }
90
91 /// @return iterator to sentinel value pair.
92 [[nodiscard]] auto end() const noexcept {
93 return make_iterator(this->m_source1.end(), this->m_source2.end());
94 }
95
96 /// Return iterator to the given key, or end() if not found.
97 [[nodiscard]] auto find(const Key_t &key) const noexcept {
98 auto it1 = this->m_source1.find(key);
99 if (it1 == this->m_source1.end()) return end();
100 auto it2 = this->m_source2.find(key);
101 if (it2 != this->m_source2.end() && is_subset(it1->second, it2->second))
102 return end();
103 return make_iterator(it1, it2);
104 }
105
106 /// Return iterator to the given key, or end() if not found, using the given
107 /// iterator cursor as a hint.
108 ///
109 /// @param[in,out] cursor Hint for the position. The behavior is undefined if
110 /// this is greater than the lower bound for the key. It will be updated to
111 /// the upper bound for the key.
112 ///
113 /// @param key Key to search for.
114 ///
115 /// @return Iterator to the key, or end if not found.
116 [[nodiscard]] auto find(Iterator_t &cursor, const Key_t &key) const noexcept {
117 auto it1 = this->m_source1.find(cursor.iterator1(), key);
118 if (it1 == this->m_source1.end()) return end();
119 auto it2 = this->m_source2.find(cursor.iterator2(), key);
120 if (it2 != this->m_source2.end() && is_subset(it1->second, it2->second))
121 return end();
122 return make_iterator(it1, it2);
123 }
124}; // class Subtraction_view
125
126} // namespace mysql::sets
127
128// addtogroup GroupLibsMysqlSets
129/// @}
130
131#endif // ifndef MYSQL_SETS_NESTED_SET_SUBTRACTION_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 one set minus another other set.
Definition: boundary_set_subtraction_view.h:51
Subtraction_view(const Source1_t *source1, const Source2_t *source2) noexcept
Construct a new Subtraction_view over the given sources.
Definition: nested_set_subtraction_view.h:83
auto end() const noexcept
Definition: nested_set_subtraction_view.h:92
auto begin() const noexcept
Definition: nested_set_subtraction_view.h:87
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_subtraction_view.h:116
auto find(const Key_t &key) const noexcept
Return iterator to the given key, or end() if not found.
Definition: nested_set_subtraction_view.h:97
Primary template for views over subtractions of two sets operations.
Definition: base_binary_operation_views.h:68
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_subset(const Interval< Set_traits_t > &interval1, const Is_boundary_set_over_traits< Set_traits_t > auto &set2)
Return true if the left Interval is a subset of or equal to the right Boundary_set.
Definition: boundary_set_predicates.h:58
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.