![]() |
Pixie
|
CRTP contract for exclusively owned permutations of [0,size()). More...
#include <permutation.h>
Public Types | |
| using | value_type = Index |
| Stored index type. | |
| using | const_reference = Index |
| Immutable read result. | |
| using | size_type = std::size_t |
| Count and position type. | |
Public Member Functions | |
| size_type | size () const noexcept |
| Return the logical index count. | |
| bool | empty () const noexcept |
| Test emptiness. | |
| const_reference | operator[] (size_type position) const |
| Read a checked zero-based index by value. | |
| void | insert_at (size_type position) |
| Insert the next identity value at a zero-based position. | |
| void | rotate_left (size_type left, size_type right, size_type distance) |
| Rotate [left,right) left, preserving outside indices. | |
| void | merge (Impl &donor) |
| Append donor indices plus the old receiver size and consume donor. | |
| size_type | memory_usage_bytes () const noexcept |
| Explicitly account for requested live storage. | |
Static Public Member Functions | |
| static Impl | identity (size_type n) |
| Construct an owning identity permutation. | |
CRTP contract for exclusively owned permutations of [0,size()).
Construction is identity-only; reads are checked and immutable. Rotation preserves the bijection and merge rebases the consumed donor. Implementations provide identity_impl(n), size_impl(), value_at_impl(i), insert_at_impl(position), rotate_left_impl(left,right,distance), merge_impl(donor), and memory_usage_bytes_impl() with the corresponding facade semantics below. size_impl() and memory_usage_bytes_impl() must be noexcept; the other extension points propagate the documented exceptions. Validation belongs to the implementation, not a second facade check. No virtual dispatch. Required signatures are static Impl identity_impl(size_type), size_type size_impl() const noexcept, Index value_at_impl(size_type) const, void insert_at_impl(size_type), void rotate_left_impl(size_type,size_type, size_type), void merge_impl(Impl&), and size_type memory_usage_bytes_impl() const noexcept. Private extension points grant friendship to this base. Concrete owners default-construct canonical empty and are move-only with nonthrowing move and destruction; moves leave the source canonical empty and self-move is a no-op.
| Impl | Concrete owning implementation. |
| Index | Unsigned integer other than bool with at most 64 value bits. |
| using pixie::PermutationBase< Impl, Index >::const_reference = Index |
Immutable read result.
Returned by value, never writable.
| using pixie::PermutationBase< Impl, Index >::size_type = std::size_t |
Count and position type.
Full unsigned size_t range.
| using pixie::PermutationBase< Impl, Index >::value_type = Index |
Stored index type.
Independent of the count width.
|
inlinenoexcept |
Test emptiness.
Equivalent to size()==0; canonical empty owns no heap storage.
|
inlinestatic |
Construct an owning identity permutation.
identity_impl(n) returns Impl containing 0 through n-1, reclaiming all acquired storage on failure. The domain is min(SIZE_MAX,max(Index)+1), interpreted mathematically; fixed-width indices never widen.
| n | Number of entries, represented independently of Index. |
| std::length_error | If n exceeds the index domain. |
| std::bad_alloc | If construction allocation fails. |
|
inline |
Insert the next identity value at a zero-based position.
insert_at_impl(position) inserts the value size() at position, shifting existing entries at or after position one to the right. The result remains a valid permutation of [0,size()+1). Allocation failure leaves all contents and pending biases unchanged.
| position | Insertion position in [0,size()]. |
| std::out_of_range | If position > size(). |
| std::length_error | If the new size exceeds the index domain. |
| std::bad_alloc | If preflight allocation fails. |
|
inlinenoexcept |
Explicitly account for requested live storage.
memory_usage_bytes_impl() traverses allocations in linear time, without allocating or throwing. Includes the facade, alignment, metadata, and unused payload capacity; saturates at SIZE_MAX. Excludes allocator overhead, RSS, stack scratch, and construction/preflight peaks. Concrete memory_usage() supplies a structured breakdown, not a second total.
|
inline |
Append donor indices plus the old receiver size and consume donor.
merge_impl accepts only the same concrete configuration. Self merge and empty donor are no-ops; success leaves donor canonical empty. Size checks and allocating preflight precede rebasing or ownership edits; either failure leaves both participants unchanged.
| donor | Owner of the permutation to append and rebase. |
| std::length_error | If the combined count or index domain overflows. |
| std::bad_alloc | If preflight allocation fails. |
|
inline |
|
inline |
Rotate [left,right) left, preserving outside indices.
rotate_left_impl validates even at zero distance. Empty intervals are no-ops; otherwise distance is reduced modulo right-left. Allocation failure leaves all contents and pending biases unchanged.
| left | Inclusive start. |
| right | Exclusive end, at most size(). |
| distance | Left rotation distance in entries. |
| std::out_of_range | If left > right or right > size(). |
| std::bad_alloc | If preflight allocation fails. |
|
inlinenoexcept |
Return the logical index count.
size_impl() returns the count without allocation or mutation.