MySQL 9.6.0
Source Code Documentation
interval_set_predicates.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_INTERVAL_SET_PREDICATES_H
25#define MYSQL_SETS_INTERVAL_SET_PREDICATES_H
26
27/// @file
28/// Experimental API header
29#include "mysql/sets/interval.h" // Interval
30#include "mysql/sets/interval_set_meta.h" // Is_interval_set
31#include "mysql/sets/set_categories_and_traits.h" // Is_compatible_set
32
33/// @addtogroup GroupLibsMysqlSets
34/// @{
35
36namespace mysql::sets {
37
38// ==== contains_element ====
39
40/// Return true if the element is contained in the Interval set.
41///
42/// Complexity: The time of one invocation of set.boundaries().upper_bound.
43template <Is_interval_set Interval_set_t>
44[[nodiscard]] constexpr bool contains_element(
45 const Interval_set_t &set,
46 const typename Interval_set_t::Element_t &element) {
47 return contains_element(set.boundaries(), element);
48}
49
50// ==== is_subset ====
51
52/// Return true if the left Interval is a subset of or equal to the right
53/// Interval set.
54///
55/// Complexity: The time of one invocation of set2.upper_bound.
56template <Is_bounded_set_traits Set_traits_t>
57[[nodiscard]] constexpr bool is_subset(
58 const Interval<Set_traits_t> &interval1,
60 return is_subset(interval1, set2.boundaries());
61}
62
63/// Return true if the left Interval set is a subset of or equal to the
64/// right Interval.
65///
66/// Complexity: Constant.
67template <Is_bounded_set_traits Set_traits_t>
68[[nodiscard]] constexpr bool is_subset(
70 const Interval<Set_traits_t> &interval2) {
71 return is_subset(set1.boundaries(), interval2);
72}
73
74/// Return true if the left Interval set is a subset of or equal to the
75/// right Interval set.
76///
77/// Complexity: The number of iterations is linear in the size of the smallest
78/// set. Each iteration requires an invocation of upper_bound in both sets.
79template <Is_interval_set Interval_set1_tp, Is_interval_set Interval_set2_tp>
80 requires Is_compatible_set<Interval_set1_tp, Interval_set2_tp>
81[[nodiscard]] constexpr bool is_subset(const Interval_set1_tp &set1,
82 const Interval_set2_tp &set2) {
83 return is_subset(set1.boundaries(), set2.boundaries());
84}
85
86// ==== is_intersecting ====
87
88/// Return true if the left Interval and the right Interval set
89/// intersect.
90///
91/// Complexity: The time of one invocation of set.upper_bound.
92template <Is_bounded_set_traits Set_traits_t>
93[[nodiscard]] constexpr bool is_intersecting(
96 return is_intersecting(interval, set.boundaries());
97}
98
99/// Return true if the left Interval set and the right Interval
100/// intersect.
101///
102/// Complexity: The time of one invocation of set.upper_bound.
103template <Is_bounded_set_traits Set_traits_t>
104[[nodiscard]] constexpr bool is_intersecting(
107 return is_intersecting(set.boundaries(), interval);
108}
109
110/// Return true if the two Interval sets intersect (overlap).
111///
112/// Complexity: The number of iterations is linear in the size of the smallest
113/// set. Each iteration requires an invocation of upper_bound in both sets.
114template <Is_interval_set Interval_set1_tp, Is_interval_set Interval_set2_tp>
115 requires Is_compatible_set<Interval_set1_tp, Interval_set2_tp>
116[[nodiscard]] constexpr bool is_intersecting(const Interval_set1_tp &set1,
117 const Interval_set2_tp &set2) {
118 return is_intersecting(set1.boundaries(), set2.boundaries());
119}
120
121} // namespace mysql::sets
122
123// addtogroup GroupLibsMysqlSets
124/// @}
125
126#endif // ifndef MYSQL_SETS_INTERVAL_SET_PREDICATES_H
Holds the start boundary and endpoint boundary of an interval.
Definition: interval.h:178
Definition: interval_set_meta.h:90
Experimental API header.
Experimental API header.
static int interval
Definition: mysqladmin.cc:72
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
bool contains_element(const mysql::gtids::Is_gtid_set auto &gtid_set, const mysql::gtids::Is_gtid auto &gtid) noexcept
contains_element for Gtid_sets, accepting a Gtid for the element.
Definition: gtid_set.h:186
constexpr bool is_intersecting(const Interval< Set_traits_t > &interval, const Is_boundary_set_over_traits< Set_traits_t > auto &set)
Return true if the left Interval and the right Boundary set intersect (overlap).
Definition: boundary_set_predicates.h:121
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2888
Experimental API header.