24#ifndef MYSQL_SETS_THROWING_BOUNDARY_CONTAINER_H
25#define MYSQL_SETS_THROWING_BOUNDARY_CONTAINER_H
63template <Is_boundary_storage Storage_tp>
65 Boundary_container<Storage_tp>, Storage_tp> {
69 static_assert(std::bidirectional_iterator<Iterator_t>);
94 :
Base_t(memory_resource) {}
118 template <Is_boundary_iterator_over_type<Element_t> First_iterator_t>
120 const First_iterator_t &first,
121 const std::sentinel_for<First_iterator_t>
auto &last,
123 :
Base_t(first, last, memory_resource) {}
129 template <Is_boundary_iterator_over_type<Element_t> First_iterator_t>
131 const First_iterator_t &first,
132 const std::sentinel_for<First_iterator_t>
auto &last)
147 template <Is_boundary_set_over_traits_unqualified<Set_traits_t> Source_t>
212 inplace_union_or_subtract<Binary_operation::op_union, Hint_guaranteed::yes>(
213 hint,
start, exclusive_end);
239 inplace_union_or_subtract<Binary_operation::op_union, Hint_guaranteed::no>(
240 cursor,
start, exclusive_end);
277 template <Is_boundary_set_over_traits_unqualified<Set_traits_t> Input_set_t>
279 inplace_op<Binary_operation::op_union>(
280 std::forward<Input_set_t>(input_set));
348 template <Is_boundary_set_over_traits_unqualified<Set_traits_t> Input_set_t>
350 inplace_op<Binary_operation::op_subtraction>(
351 std::forward<Input_set_t>(input_set));
365 const Element_t &exclusive_end)
noexcept {
366 if (Set_traits_t::lt(exclusive_end, Set_traits_t::max_exclusive()))
368 if (Set_traits_t::gt(
start, Set_traits_t::min()))
387 template <Is_boundary_set_over_traits_unqualified<Set_traits_t> Input_set_t>
389 inplace_op<Binary_operation::op_intersection>(
390 std::forward<Input_set_t>(input_set));
405 return Storage_t::upper_bound_dispatch(
self.
storage(), hint, element);
420 return Storage_t::lower_bound_dispatch(
self.
storage(), hint, element);
444 if (mysql::sets::detail::handle_inplace_op_trivial_cases<operation>(
445 *
this, std::forward<Source_t>(
source)))
464 auto prefer_full_copy = [&
self, &
source] {
470 auto insert_end =
source.upper_bound(
self.
back());
475 auto first_element_moved =
self.upper_bound(
source.front());
478 auto max_elements_moved_per_insertion =
485 auto expected_elements_moved_per_insertion =
486 max_elements_moved_per_insertion >> 1;
489 return max_elements_inserted * expected_elements_moved_per_insertion >
493 if (prefer_full_copy()) {
509 auto &read_source = [&]() ->
auto & {
521 constexpr bool types_allow_donation =
523 bool can_donate =
false;
524 if constexpr (types_allow_donation) {
531 auto cursor = this->
begin();
533 auto it = interval_set_view.begin();
534 while (it != interval_set_view.end()) {
541 if constexpr (types_allow_donation) {
544 cursor, iv.start(), iv.exclusive_end(), &
source);
550 cursor, iv.start(), iv.exclusive_end(), &
source);
556 if (cursor == this->
end())
return;
608 Source_t *
source =
nullptr) {
609 assert(Set_traits_t::lt(
start, exclusive_end));
611 assert(cursor == this->
begin() ||
612 Set_traits_t::lt(*std::ranges::prev(cursor),
start));
614 if (cursor != this->
begin() &&
615 Set_traits_t::ge(*std::ranges::prev(cursor),
start)) {
616 cursor = this->
begin();
634 if (
left.is_endpoint() == is_union) {
638 if (
right.is_endpoint() == is_union) {
657 storage().update_point(std::ranges::prev(cursor), exclusive_end);
663 if (
right.is_endpoint() == is_union) {
673 cursor =
storage().update_point(std::ranges::prev(cursor),
start);
685 cursor =
storage().update_point(std::ranges::prev(cursor, 2),
start);
686 cursor =
storage().update_point(cursor, exclusive_end);
Polymorphism-free memory resource class with custom allocator and deallocator functions.
Definition: memory_resource.h:88
CRTP base class (mixin) to define a wrapper around a container.
Definition: basic_container_wrapper.h:59
auto begin() noexcept
Definition: basic_container_wrapper.h:164
auto end() noexcept
Definition: basic_container_wrapper.h:167
auto & wrapped() &noexcept
Definition: basic_container_wrapper.h:183
auto get_allocator() const noexcept
Return the allocator used by the wrapped object.
Definition: basic_container_wrapper.h:159
constexpr decltype(auto) back() const
Return the last element. Enabled if we have bidirectional iterators.
Definition: collection_interface.h:161
CRTP base class/mixin, used to implement Boundary Sets that are container wrappers.
Definition: boundary_set_interface.h:128
Definition: basic_set_container_wrapper.h:47
void assign(Source_t &&source)
Enable move-assign from any Basic_set_container_wrapper for a compatible set type (not necessarily fo...
Definition: basic_set_container_wrapper.h:67
View that provides and Interval set from an underlying Boundary set.
Definition: interval_set_interface.h:132
constexpr Iterator_t lower_bound(const Iterator_t &hint, const Element_t &element)
Return the lower bound for element, using an iterator hint known to be less than or equal to the corr...
Definition: upper_lower_bound_interface.h:219
constexpr Iterator_t upper_bound(const Iterator_t &hint, const Element_t &element)
Return the upper bound for element, using an iterator hint known to be less than or equal to the corr...
Definition: upper_lower_bound_interface.h:284
Iterator_tp Iterator_t
Definition: boundary_set_interface.h:75
Set_traits_tp Set_traits_t
Definition: boundary_set_interface.h:78
typename Set_traits_tp::Element_t Element_t
Definition: boundary_set_interface.h:79
Const_iterator_tp Const_iterator_t
Definition: boundary_set_interface.h:76
Container that stores boundaries.
Definition: boundary_container.h:65
void inplace_union(const Element_t &start, const Element_t &exclusive_end)
Insert the given interval (inplace union).
Definition: boundary_container.h:210
Boundary_container(const Is_boundary_set_over_traits< Set_traits_t > auto &source)
Construct from any other Boundary_set over the same Set traits.
Definition: boundary_container.h:109
void inplace_op(Source_t &&source)
Worker for either in-place union or in-place subtraction, adding or removing all intervals from anoth...
Definition: boundary_container.h:443
Boundary_container(const Is_boundary_set_over_traits< Set_traits_t > auto &source, const Memory_resource_t &memory_resource)
Construct from any other Boundary_set over the same Set traits.
Definition: boundary_container.h:100
typename Storage_t::Allocator_t Allocator_t
Definition: boundary_container.h:76
void inplace_intersect(const Element_t &start, const Element_t &exclusive_end) noexcept
In-place intersect this container with the given interval.
Definition: boundary_container.h:364
Storage_t & storage() noexcept
Return a const reference to the underlying storage.
Definition: boundary_container.h:161
void inplace_subtract(Input_set_t &&input_set)
In-place subtract intervals of the given container from this container.
Definition: boundary_container.h:349
static auto lower_bound_impl(mysql::meta::Is_same_ignore_const< This_t > auto &self, const auto &hint, const Element_t &element) noexcept
Return iterator to the leftmost boundary at or after hint that is greater than or equal to the given ...
Definition: boundary_container.h:417
Boundary_container() noexcept=default
Default constructor.
static auto upper_bound_impl(mysql::meta::Is_same_ignore_const< This_t > auto &self, const auto &hint, const Element_t &element) noexcept
Return iterator to the leftmost boundary at or after hint that is greater than the given element.
Definition: boundary_container.h:402
void inplace_subtract(Iterator_t &cursor, const Element_t &start, const Element_t &exclusive_end)
Subtract the given interval, reading and updating the given cursor.
Definition: boundary_container.h:326
Storage_tp Storage_t
Definition: boundary_container.h:67
Can_donate
Indicates to a function that it may steal elements from a source object, rather than allocate new ele...
Definition: boundary_container.h:427
void remove(const Element_t &element)
Remove the given element (inplace subtraction).
Definition: boundary_container.h:187
Boundary_container< Storage_t > This_t
Definition: boundary_container.h:77
void inplace_union(Input_set_t &&input_set)
In-place insert the intervals of the given set into this container (inplace union).
Definition: boundary_container.h:278
void insert(const Element_t &element)
Insert the given element (inplace union).
Definition: boundary_container.h:173
Hint_guaranteed
Whether a hint parameter is guaranteed to satisfy the precondition that of being a lower bound.
Definition: boundary_container.h:195
void inplace_subtract(const Element_t &start, const Element_t &exclusive_end)
Subtract the given interval.
Definition: boundary_container.h:299
void inplace_intersect(Input_set_t &&input_set)
In-place intersect this container with intervals of the given container.
Definition: boundary_container.h:388
const Storage_t & storage() const noexcept
Return a const reference to the underlying storage.
Definition: boundary_container.h:156
void assign(Source_t &&source)
Definition: boundary_container.h:151
static constexpr bool has_fast_insertion
Definition: boundary_container.h:80
This_t & operator=(const Is_boundary_set_over_traits< Set_traits_t > auto &source)
Assign from any other Boundary_set over the same Set traits.
Definition: boundary_container.h:139
Boundary_container(const First_iterator_t &first, const std::sentinel_for< First_iterator_t > auto &last)
Construct from iterators.
Definition: boundary_container.h:130
void inplace_union_or_subtract(Iterator_t &cursor, const Element_t &start, const Element_t &exclusive_end, Source_t *source=nullptr)
Either add or remove the interval, reading and updating the given cursor.
Definition: boundary_container.h:606
Boundary_container(const First_iterator_t &first, const std::sentinel_for< First_iterator_t > auto &last, const Memory_resource_t &memory_resource)
Construct from iterators.
Definition: boundary_container.h:119
void inplace_union(Iterator_t &cursor, const Element_t &start, const Element_t &exclusive_end)
Insert the given interval (inplace union), reading and updating the given cursor.
Definition: boundary_container.h:237
True if the iterator is declared to meet LegacyBidirectionalIterator requirements.
Definition: meta.h:83
True if move-semantics has been declared as enabled for inplace_union/inplace_intersect/inplace_subtr...
Definition: meta.h:114
True if move-semantics has been declared as enabled for full-set-copy operations for the given operan...
Definition: meta.h:90
Definition: boundary_set_meta.h:239
True if Test is an interval set over the given Set traits.
Definition: boundary_set_meta.h:217
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
Class that wraps resources in a polymorphic manner.
Definition: atomics_array.h:39
bool distance(const dd::Spatial_reference_system *srs, const Geometry *g1, const Geometry *g2, double *distance, bool *is_null) noexcept
Computes the distance between two geometries.
Definition: distance.cc:40
void right(std::string *to_trim)
Definition: trim.h:41
void left(std::string *to_trim)
Definition: trim.h:35
decltype(auto) get_memory_resource_or_default(const auto &object)
Return object.get_memory_resource(), if that function exists.
Definition: memory_resource.h:145
std::remove_cvref_t< decltype(std::declval< const Range_t >().begin())> Range_const_iterator_type
Gives the const_iterator type, deduced from the begin() const member.
Definition: meta.h:47
std::remove_cvref_t< decltype(std::declval< Range_t >().begin())> Range_iterator_type
Gives the iterator type, deduced from the begin() member.
Definition: meta.h:42
Binary_operation
Identifies the type of a binary operation.
Definition: binary_operation.h:37
auto make_complement_view(const Source_t &source)
Return the Complement_view over the argument.
Definition: base_complement_view.h:53
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Definition: instrumented_condition_variable.h:32
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42