Pixie
Loading...
Searching...
No Matches
pixie::PermutationBase< Impl, Index > Class Template Reference

CRTP contract for exclusively owned permutations of [0,size()). More...

#include <permutation.h>

Inheritance diagram for pixie::PermutationBase< Impl, Index >:
pixie::Permutation< Index, StorageBits, Fanout, Layout >

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.
 

Detailed Description

template<class Impl, class Index = std::uint64_t>
class pixie::PermutationBase< Impl, Index >

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.

Template Parameters
ImplConcrete owning implementation.
IndexUnsigned integer other than bool with at most 64 value bits.

Member Typedef Documentation

◆ const_reference

template<class Impl, class Index = std::uint64_t>
using pixie::PermutationBase< Impl, Index >::const_reference = Index

Immutable read result.

Returned by value, never writable.

◆ size_type

template<class Impl, class Index = std::uint64_t>
using pixie::PermutationBase< Impl, Index >::size_type = std::size_t

Count and position type.

Full unsigned size_t range.

◆ value_type

template<class Impl, class Index = std::uint64_t>
using pixie::PermutationBase< Impl, Index >::value_type = Index

Stored index type.

Independent of the count width.

Member Function Documentation

◆ empty()

template<class Impl, class Index = std::uint64_t>
bool pixie::PermutationBase< Impl, Index >::empty ( ) const
inlinenoexcept

Test emptiness.

Equivalent to size()==0; canonical empty owns no heap storage.

Returns
Whether no entries remain.

◆ identity()

template<class Impl, class Index = std::uint64_t>
static Impl pixie::PermutationBase< Impl, Index >::identity ( size_type n)
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.

Parameters
nNumber of entries, represented independently of Index.
Returns
Exclusive owner of the identity permutation.
Exceptions
std::length_errorIf n exceeds the index domain.
std::bad_allocIf construction allocation fails.

◆ insert_at()

template<class Impl, class Index = std::uint64_t>
void pixie::PermutationBase< Impl, Index >::insert_at ( size_type position)
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.

Parameters
positionInsertion position in [0,size()].
Exceptions
std::out_of_rangeIf position > size().
std::length_errorIf the new size exceeds the index domain.
std::bad_allocIf preflight allocation fails.

◆ memory_usage_bytes()

template<class Impl, class Index = std::uint64_t>
size_type pixie::PermutationBase< Impl, Index >::memory_usage_bytes ( ) const
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.

Returns
Total requested live bytes including this owner exactly once.

◆ merge()

template<class Impl, class Index = std::uint64_t>
void pixie::PermutationBase< Impl, Index >::merge ( Impl & donor)
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.

Parameters
donorOwner of the permutation to append and rebase.
Exceptions
std::length_errorIf the combined count or index domain overflows.
std::bad_allocIf preflight allocation fails.

◆ operator[]()

template<class Impl, class Index = std::uint64_t>
const_reference pixie::PermutationBase< Impl, Index >::operator[] ( size_type position) const
inline

Read a checked zero-based index by value.

value_at_impl(position) includes pending biases without pushing tags or otherwise modifying storage. No sentinel value is used.

Parameters
positionPosition in [0,size()).
Returns
Logical index in [0,size()).
Exceptions
std::out_of_rangeIf position >= size().

◆ rotate_left()

template<class Impl, class Index = std::uint64_t>
void pixie::PermutationBase< Impl, Index >::rotate_left ( size_type left,
size_type right,
size_type distance )
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.

Parameters
leftInclusive start.
rightExclusive end, at most size().
distanceLeft rotation distance in entries.
Exceptions
std::out_of_rangeIf left > right or right > size().
std::bad_allocIf preflight allocation fails.

◆ size()

template<class Impl, class Index = std::uint64_t>
size_type pixie::PermutationBase< Impl, Index >::size ( ) const
inlinenoexcept

Return the logical index count.

size_impl() returns the count without allocation or mutation.

Returns
Number of entries, in [0,SIZE_MAX].

The documentation for this class was generated from the following file: