pub enum EncodedColumn<T> {
Plain(Vec<T>),
Constant {
value: T,
len: u32,
},
RunLength {
values: Vec<T>,
run_ends: Vec<u32>,
},
BitPacked {
data: Vec<u8>,
width: u8,
len: u32,
},
Delta {
first: T,
deltas: Vec<i32>,
checkpoints: Vec<i64>,
},
}Expand description
One column of a chunk, in whichever physical form fits its data.
§Examples
use molframe_core::column::EncodedColumn;
let repeated = EncodedColumn::encode(&[7u32; 4096]);
assert!(repeated.is_constant());
assert_eq!(repeated.get(4095), Some(7));
let varied = EncodedColumn::encode(&[1u32, 9, 3, 9]);
assert_eq!(varied.get(2), Some(3));
assert_eq!(varied.len(), 4);Variants§
Plain(Vec<T>)
Values as they are. The only form a kernel reads directly.
Constant
One value for the whole column.
RunLength
Values with the position each run ends at.
Fields
BitPacked
Narrow integers at a fixed bit width.
Delta
A first value and the difference to each successive one.
Fields
first: TThe value at position zero.
checkpoints: Vec<i64>The absolute value at every DELTA_CHECKPOINT_STRIDE-th position.
Without these, reading position p sums p deltas, so walking a
column by index costs O(n^2). Entry k holds the value at
position (k + 1) * DELTA_CHECKPOINT_STRIDE, which bounds any read
to one stride of additions. At four bytes per delta and eight per
checkpoint the table adds about three percent to the encoding.
Implementations§
Source§impl<T: ColumnValue> EncodedColumn<T>
impl<T: ColumnValue> EncodedColumn<T>
Sourcepub const fn is_constant(&self) -> bool
pub const fn is_constant(&self) -> bool
Returns true when the column is one repeated value.
Sourcepub fn as_slice(&self) -> Option<&[T]>
pub fn as_slice(&self) -> Option<&[T]>
The values as a slice, when they are stored literally.
A kernel that needs a slice asks for one and takes the other path when it is refused; nothing forces a column into plain form behind the caller’s back.
Sourcepub fn get(&self, position: u32) -> Option<T>
pub fn get(&self, position: u32) -> Option<T>
The value at position, or None if it is past the end.
Sourcepub fn iter(&self) -> ColumnIter<'_, T> ⓘ
pub fn iter(&self) -> ColumnIter<'_, T> ⓘ
Every value in order.
Reading sequentially through a delta or run-length column this way is linear overall, where repeated random access would not be.
Sourcepub fn encode(values: &[T]) -> Self
pub fn encode(values: &[T]) -> Self
Chooses an encoding for values by what they contain.
The rules, in order: one repeated value becomes constant; few runs become run-length; small non-negative integers become bit-packed when that is genuinely narrower; a near-monotonic integer sequence becomes deltas; anything else stays plain.
Trait Implementations§
Source§impl<T: Clone> Clone for EncodedColumn<T>
impl<T: Clone> Clone for EncodedColumn<T>
Source§impl<T: Debug> Debug for EncodedColumn<T>
impl<T: Debug> Debug for EncodedColumn<T>
Source§impl<'a, T: ColumnValue> IntoIterator for &'a EncodedColumn<T>
impl<'a, T: ColumnValue> IntoIterator for &'a EncodedColumn<T>
Source§impl<T: PartialEq> PartialEq for EncodedColumn<T>
impl<T: PartialEq> PartialEq for EncodedColumn<T>
impl<T: PartialEq> StructuralPartialEq for EncodedColumn<T>
Auto Trait Implementations§
impl<T> Freeze for EncodedColumn<T>
impl<T> RefUnwindSafe for EncodedColumn<T>
impl<T> Send for EncodedColumn<T>
impl<T> Sync for EncodedColumn<T>
impl<T> Unpin for EncodedColumn<T>
impl<T> UnsafeUnpin for EncodedColumn<T>
impl<T> UnwindSafe for EncodedColumn<T>
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
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> ⓘ
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> ⓘ
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