pub enum AdaptiveCodes {
U8(Vec<u8>),
U16(Vec<u16>),
U32(Vec<u32>),
U64(Vec<u64>),
}Expand description
Adaptive-width code storage. Promotes to a wider arm only when the current arm physically cannot hold the next code:
- U8 → U16 when inserting a code ≥ 256
- U16 → U32 when inserting a code ≥ 65 536
- U32 → U64 when inserting a code ≥ 2³²
Promotion preserves all existing codes bit-for-bit. The len() and
the sequence of values returned by iter() are invariant under
promotion.
Variants§
Implementations§
Source§impl AdaptiveCodes
impl AdaptiveCodes
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Pre-allocated empty U8-arm storage.
Sourcepub fn push(&mut self, code: u64)
pub fn push(&mut self, code: u64)
Append a code. Promotes the arm in-place if code does not fit.
Promotion is lazy: a U8 arm with codes [0, 1, 2] and an insert
of 255 stays U8; insert of 256 promotes to U16 with codes
[0, 1, 2, 256].
Sourcepub fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
pub fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
Iterate codes as u64 (the widest representation, lossless for all
arms).
Sourcepub fn width_bytes(&self) -> usize
pub fn width_bytes(&self) -> usize
Width in bytes per code (1, 2, 4, or 8). Useful for memory accounting and benchmarks.
Trait Implementations§
Source§impl Clone for AdaptiveCodes
impl Clone for AdaptiveCodes
Source§fn clone(&self) -> AdaptiveCodes
fn clone(&self) -> AdaptiveCodes
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AdaptiveCodes
impl Debug for AdaptiveCodes
Source§impl Default for AdaptiveCodes
impl Default for AdaptiveCodes
Source§impl PartialEq for AdaptiveCodes
impl PartialEq for AdaptiveCodes
Source§fn eq(&self, other: &AdaptiveCodes) -> bool
fn eq(&self, other: &AdaptiveCodes) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for AdaptiveCodes
impl StructuralPartialEq for AdaptiveCodes
Auto Trait Implementations§
impl Freeze for AdaptiveCodes
impl RefUnwindSafe for AdaptiveCodes
impl Send for AdaptiveCodes
impl Sync for AdaptiveCodes
impl Unpin for AdaptiveCodes
impl UnsafeUnpin for AdaptiveCodes
impl UnwindSafe for AdaptiveCodes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more