Pixie
Loading...
Searching...
No Matches
rmq.h
Go to the documentation of this file.
1#pragma once
2
10
11#include <concepts>
12#include <cstddef>
13#include <limits>
14
15namespace pixie::rmq {
16
27template <class Impl, class Value>
28class RmqBase {
29 public:
33 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
34
40 std::size_t size() const { return impl().size_impl(); }
41
47 bool empty() const { return size() == 0; }
48
60 std::size_t arg_min(std::size_t left, std::size_t right) const {
61 return impl().arg_min_impl(left, right);
62 }
63
73 Value range_min(std::size_t left, std::size_t right) const {
74 const std::size_t position = arg_min(left, right);
75 if (position == npos) {
76 return Value{};
77 }
78 return impl().value_at_impl(position);
79 }
80
89 std::size_t memory_usage_bytes() const
90 requires requires(const Impl& concrete) {
91 {
92 concrete.memory_usage_bytes_impl()
93 } -> std::convertible_to<std::size_t>;
94 }
95 {
96 return impl().memory_usage_bytes_impl();
97 }
98
99 private:
105 const Impl& impl() const { return static_cast<const Impl&>(*this); }
106};
107
108} // namespace pixie::rmq
CRTP facade for static range-minimum-query indexes.
Definition rmq.h:28
Value range_min(std::size_t left, std::size_t right) const
Return the minimum value in [left, right).
Definition rmq.h:73
std::size_t size() const
Number of indexed values.
Definition rmq.h:40
std::size_t memory_usage_bytes() const
Return owned auxiliary memory usage in bytes when implemented.
Definition rmq.h:89
std::size_t arg_min(std::size_t left, std::size_t right) const
Return the first minimum position in [left, right).
Definition rmq.h:60
static constexpr std::size_t npos
Sentinel returned when no valid query answer exists.
Definition rmq.h:33
bool empty() const
Whether the indexed array is empty.
Definition rmq.h:47
Definition rmq.h:15