Pixie
Loading...
Searching...
No Matches
permutation.h
Go to the documentation of this file.
1#pragma once
2
9
11
12#include <cstddef>
13#include <cstdint>
14#include <limits>
15#include <type_traits>
16
17namespace pixie {
40template <class Impl, class Index = std::uint64_t>
42 static_assert(std::is_integral_v<Index> && std::is_unsigned_v<Index> &&
43 !std::is_same_v<Index, bool> &&
44 std::numeric_limits<Index>::digits <= 64);
45
46 public:
48 using value_type = Index;
51 using const_reference = Index;
53 using size_type = std::size_t;
54
65 static Impl identity(size_type n) { return Impl::identity_impl(n); }
71 size_type size() const noexcept { return impl().size_impl(); }
77 bool empty() const noexcept { return size() == 0; }
87 return impl().value_at_impl(position);
88 }
89
100 void insert_at(size_type position) { impl().insert_at_impl(position); }
112 void rotate_left(size_type left, size_type right, size_type distance) {
113 impl().rotate_left_impl(left, right, distance);
114 }
115
125 void merge(Impl& donor) { impl().merge_impl(donor); }
135 size_type memory_usage_bytes() const noexcept {
136 return impl().memory_usage_bytes_impl();
137 }
138
139 private:
140 Impl& impl() noexcept { return static_cast<Impl&>(*this); }
141 const Impl& impl() const noexcept { return static_cast<const Impl&>(*this); }
142};
143} // namespace pixie
CRTP contract for exclusively owned permutations of [0,size()).
Definition permutation.h:41
Index value_type
Stored index type.
Definition permutation.h:48
const_reference operator[](size_type position) const
Read a checked zero-based index by value.
Definition permutation.h:86
std::size_t size_type
Count and position type.
Definition permutation.h:53
static Impl identity(size_type n)
Construct an owning identity permutation.
Definition permutation.h:65
void merge(Impl &donor)
Append donor indices plus the old receiver size and consume donor.
Definition permutation.h:125
bool empty() const noexcept
Test emptiness.
Definition permutation.h:77
void insert_at(size_type position)
Insert the next identity value at a zero-based position.
Definition permutation.h:100
size_type memory_usage_bytes() const noexcept
Explicitly account for requested live storage.
Definition permutation.h:135
Index const_reference
Immutable read result.
Definition permutation.h:51
void rotate_left(size_type left, size_type right, size_type distance)
Rotate [left,right) left, preserving outside indices.
Definition permutation.h:112
size_type size() const noexcept
Return the logical index count.
Definition permutation.h:71
Shared compile-time sequence tuning options.