Pixie
Loading...
Searching...
No Matches
pixie::SlidingWindowStorage Class Reference

Owning fixed-capacity storage over a monotonically positioned window. More...

#include <sliding_window.h>

Inheritance diagram for pixie::SlidingWindowStorage:
pixie::StorageBase< SlidingWindowStorage > pixie::SerializationBase< SlidingWindowStorage >

Public Member Functions

 SlidingWindowStorage (std::size_t capacity_bytes)
 Construct an empty window with immutable byte capacity.
 
 SlidingWindowStorage (const SlidingWindowStorage &)=default
 
 SlidingWindowStorage (SlidingWindowStorage &&other) noexcept
 Transfer the fixed backing allocation.
 
SlidingWindowStorageoperator= (const SlidingWindowStorage &)=delete
 
SlidingWindowStorageoperator= (SlidingWindowStorage &&)=delete
 
std::size_t capacity_bytes () const
 Return the immutable logical ring capacity in bytes.
 
std::size_t size_bytes_impl () const
 Return the number of bytes currently retained.
 
position_type begin_position_impl () const
 Return the oldest retained logical byte position.
 
position_type end_position_impl () const
 Return the position one past the newest retained byte.
 
std::size_t allocated_bytes_impl () const
 Return the bytes in the fixed backing allocation.
 
void extend (std::size_t count_bytes)
 Advance the logical end by a number of bytes.
 
void prepare_segments_impl (position_type position, std::size_t count_bytes)
 Extend through a requested future writable range when necessary.
 
SplitSpan< std::byte > segments_impl (position_type position, std::size_t count_bytes)
 Return a retained logical range as writable physical segments.
 
SplitSpan< const std::byte > segments_impl (position_type position, std::size_t count_bytes) const
 Return a retained logical range as read-only physical segments.
 
- Public Member Functions inherited from pixie::StorageBase< SlidingWindowStorage >
std::size_t size_bytes () const
 Return the logical exposed storage size in bytes.
 
std::size_t size_bits () const
 Return the exposed storage size in bits.
 
bool empty () const
 Check whether the storage is empty.
 
position_type begin_position () const
 Return the first logical byte position currently exposed.
 
position_type end_position () const
 Return the position one past the last logical byte exposed.
 
bool contains (position_type position, std::size_t count_bytes) const
 Return whether a complete logical range is currently exposed.
 
std::span< const std::byte > as_bytes () const
 Return a contiguous read-only view of all logical exposed bytes.
 
SplitSpan< std::byte > segments ()
 Return all logical bytes as one or two writable physical spans.
 
SplitSpan< const std::byte > segments () const
 Return all logical bytes as one or two physical spans.
 
SplitSpan< std::byte > segments (position_type position, std::size_t count_bytes)
 Return a checked writable logical byte range as one or two spans.
 
SplitSpan< const std::byte > segments (position_type position, std::size_t count_bytes) const
 Return a checked logical byte range as one or two physical spans.
 
std::span< const std::uint16_t > as_words16 () const
 Return a read-only view as 16-bit words.
 
std::span< const std::uint64_t > as_words64 () const
 Return a read-only view as 64-bit words.
 
auto view () const
 Return a non-owning read-only view of all exposed bytes.
 
auto view (std::size_t offset_bytes, std::size_t count_bytes) const
 Return a non-owning read-only byte subrange.
 
void serialize_impl (BinaryWriter &writer) const
 Serialize the exposed bytes with a 64-bit little-endian size prefix.
 
void resize (std::size_t size_bits)
 Resize mutable storage to hold at least size_bits bits.
 
auto writable_bytes ()
 Return writable storage bytes.
 
auto writable_words16 ()
 Return writable storage as 16-bit words.
 
auto writable_words64 ()
 Return writable storage as 64-bit words.
 
std::size_t allocated_bytes () const
 Return bytes reserved by an owning storage implementation.
 
void shrink_to_fit ()
 Request release of unused reserved storage.
 
- Public Member Functions inherited from pixie::SerializationBase< SlidingWindowStorage >
void serialize (BinaryWriter &writer) const
 Serialize this value through its concrete implementation.
 

Additional Inherited Members

- Public Types inherited from pixie::StorageBase< SlidingWindowStorage >
using position_type
 Monotonic logical byte position used to address storage ranges.
 
- Static Public Member Functions inherited from pixie::SerializationBase< SlidingWindowStorage >
static SlidingWindowStorage deserialize (BinaryReader &reader, Context &&... context)
 Restore exactly Derived and advance reader on success.
 
static SlidingWindowStorage deserialize (std::span< const std::byte > &data, Context &&... context)
 Restore exactly Derived and advance a mutable byte span.
 

Detailed Description

Owning fixed-capacity storage over a monotonically positioned window.

The complete backing ring is allocated during construction and is never resized. Extending advances end_position() and evicts the oldest bytes as necessary without initializing the newly exposed storage. Mutable and const access use absolute logical positions and return at most two physical spans. Requesting a future mutable range extends the window through that range automatically; the caller remains responsible for assigning its contents.

Segments remain valid while their complete logical range remains inside the working window. Moving or destroying the storage invalidates all segments.

Member Function Documentation

◆ extend()

void pixie::SlidingWindowStorage::extend ( std::size_t count_bytes)
inline

Advance the logical end by a number of bytes.

Newly exposed bytes are not initialized. Advancing beyond the capacity evicts the oldest logical bytes while retaining the fixed backing allocation.

Exceptions
std::length_errorif the logical position would overflow or if a nonzero extension is requested for a zero-capacity window.

◆ prepare_segments_impl()

void pixie::SlidingWindowStorage::prepare_segments_impl ( position_type position,
std::size_t count_bytes )
inline

Extend through a requested future writable range when necessary.

Exceptions
std::out_of_rangeif the requested range cannot fit in the window.
std::length_errorif the requested logical range overflows.

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