Trait constriction::BitArray
source · pub unsafe trait BitArray: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul + LowerHex + UpperHex + Binary + Default + Copy + Display + Debug + Eq + Hash + 'static {
type NonZero: NonZeroBitArray<Base = Self>;
const BITS: usize = _;
// Provided methods
fn into_nonzero(self) -> Option<Self::NonZero> { ... }
unsafe fn into_nonzero_unchecked(self) -> Self::NonZero { ... }
}
Expand description
A trait for bit strings of fixed (and usually small) length.
Short fixed-length bit strings are fundamental building blocks of efficient entropy coding algorithms. They are currently used for the following purposes:
- to represent the smallest unit of compressed data (see
stream::Code::Word
); - to represent probabilities in fixed point arithmetic (see
stream::model::EntropyModel::Probability
); and - the internal state of entropy coders (see
stream::Code::State
) is typically comprised of one or moreBitArray
s, although this is not a requirement.
This trait is implemented on all primitive unsigned integer types. It is not recommended
to implement this trait for custom types since coders will assume, for performance
considerations, that BitArray
s can be represented and manipulated efficiently in
hardware.
Safety
This trait is marked unsafe
so that entropy coders may rely on the assumption that all
BitArray
s have precisely the same behavior as builtin unsigned integer types, and that
BitArray::BITS
has the correct value.
Required Associated Types§
type NonZero: NonZeroBitArray<Base = Self>
Provided Associated Constants§
sourceconst BITS: usize = _
const BITS: usize = _
The (fixed) length of the BitArray
in bits.
Defaults to 8 * core::mem::size_of::<Self>()
, which is suitable for all
primitive unsigned integers.
This could arguably be called LEN
instead, but that may be confusing since
“lengths” are typically not measured in bits in the Rust ecosystem.
Provided Methods§
fn into_nonzero(self) -> Option<Self::NonZero>
sourceunsafe fn into_nonzero_unchecked(self) -> Self::NonZero
unsafe fn into_nonzero_unchecked(self) -> Self::NonZero
Safety
The provided value must be nonzero.