MySQL 9.6.0
Source Code Documentation
interval_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_PREDICATES_H
25#define MYSQL_SETS_INTERVAL_PREDICATES_H
26
27/// @file
28/// Experimental API header
29
30#include "mysql/sets/boundary_set_meta.h" // Is_boundary_set_over_traits
31#include "mysql/sets/interval.h" // Interval
32
33/// @addtogroup GroupLibsMysqlSets
34/// @{
35
36namespace mysql::sets {
37
38/// Return true if the element is contained in the Interval.
39///
40/// Complexity: Constant.
41template <Is_bounded_set_traits Set_traits_t>
42[[nodiscard]] constexpr bool contains_element(
44 const typename Set_traits_t::Element_t &element) {
45 return Set_traits_t::ge(element, interval.start()) &&
46 Set_traits_t::lt(element, interval.exclusive_end());
47}
48
49/// Return true if the left Interval is a subset of or equal to the right
50/// Interval.
51///
52/// Complexity: Constant.
53template <Is_bounded_set_traits Set_traits_t>
54[[nodiscard]] constexpr bool is_subset(
55 const Interval<Set_traits_t> &interval1,
56 const Interval<Set_traits_t> &interval2) {
57 return Set_traits_t::ge(interval1.start(), interval2.start()) &&
58 Set_traits_t::le(interval1.exclusive_end(), interval2.exclusive_end());
59}
60
61/// Return true if the two Interval objects intersect (overlap).
62///
63/// Complexity: Constant.
64template <Is_bounded_set_traits Set_traits_t>
65[[nodiscard]] constexpr bool is_intersecting(
66 const Interval<Set_traits_t> &interval1,
67 const Interval<Set_traits_t> &interval2) {
68 return Set_traits_t::gt(interval1.exclusive_end(), interval2.start()) &&
69 Set_traits_t::lt(interval1.start(), interval2.exclusive_end());
70}
71
72} // namespace mysql::sets
73
74// addtogroup GroupLibsMysqlSets
75/// @}
76
77#endif // ifndef MYSQL_SETS_INTERVAL_PREDICATES_H
Experimental API header.
Holds the start boundary and endpoint boundary of an interval.
Definition: interval.h:178
constexpr const Element_t & exclusive_end() const
Return const reference to the exclusive endpoint of the interval.
Definition: interval.h:110
constexpr const Element_t & start() const
Return const reference to the starting point of the interval (inclusive).
Definition: interval.h:107
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