pub struct RunEndBuffer<E: ArrowNativeType> { /* private fields */ }
Expand description
A slice-able buffer of monotonically increasing, positive integers used to store run-ends
§Logical vs Physical
A RunEndBuffer
is used to encode runs of the same value, the index of each run is
called the physical index. The logical index is then the corresponding index in the logical
run-encoded array, i.e. a single run of length 3
, would have the logical indices 0..3
.
Each value in RunEndBuffer::values
is the cumulative length of all runs in the
logical array, up to that physical index.
Consider a RunEndBuffer
containing [3, 4, 6]
. The maximum physical index is 2
,
as there are 3
values, and the maximum logical index is 5
, as the maximum run end
is 6
. The physical indices are therefore [0, 0, 0, 1, 2, 2]
┌─────────┐ ┌─────────┐ ┌─────────┐
│ 3 │ │ 0 │ ─┬──────▶ │ 0 │
├─────────┤ ├─────────┤ │ ├─────────┤
│ 4 │ │ 1 │ ─┤ ┌────▶ │ 1 │
├─────────┤ ├─────────┤ │ │ ├─────────┤
│ 6 │ │ 2 │ ─┘ │ ┌──▶ │ 2 │
└─────────┘ ├─────────┤ │ │ └─────────┘
run ends │ 3 │ ───┘ │ physical indices
├─────────┤ │
│ 4 │ ─────┤
├─────────┤ │
│ 5 │ ─────┘
└─────────┘
logical indices
§Slicing
In order to provide zero-copy slicing, this container stores a separate offset and length
For example, a RunEndBuffer
containing values [3, 6, 8]
with offset and length 4
would
describe the physical indices 1, 1, 2, 2
For example, a RunEndBuffer
containing values [6, 8, 9]
with offset 2
and length 5
would describe the physical indices 0, 0, 0, 0, 1
Implementations§
Source§impl<E> RunEndBuffer<E>where
E: ArrowNativeType,
impl<E> RunEndBuffer<E>where
E: ArrowNativeType,
Sourcepub fn new(run_ends: ScalarBuffer<E>, offset: usize, len: usize) -> Self
pub fn new(run_ends: ScalarBuffer<E>, offset: usize, len: usize) -> Self
Create a new RunEndBuffer
from a ScalarBuffer
, an offset
and len
§Panics
buffer
does not contain strictly increasing values greater than zero- the last value of
buffer
is less thanoffset + len
Sourcepub unsafe fn new_unchecked(
run_ends: ScalarBuffer<E>,
offset: usize,
len: usize,
) -> Self
pub unsafe fn new_unchecked( run_ends: ScalarBuffer<E>, offset: usize, len: usize, ) -> Self
Create a new RunEndBuffer
from an ScalarBuffer
, an offset
and len
§Safety
buffer
must contain strictly increasing values greater than zero- The last value of
buffer
must be greater than or equal tooffset + len
Sourcepub fn offset(&self) -> usize
pub fn offset(&self) -> usize
Returns the logical offset into the run-ends stored by this buffer
Sourcepub fn values(&self) -> &[E]
pub fn values(&self) -> &[E]
Returns the values of this RunEndBuffer
not including any offset
Sourcepub fn get_physical_index(&self, logical_index: usize) -> usize
pub fn get_physical_index(&self, logical_index: usize) -> usize
Performs a binary search to find the physical index for the given logical index
The result is arbitrary if logical_index >= self.len()
Sourcepub fn get_start_physical_index(&self) -> usize
pub fn get_start_physical_index(&self) -> usize
Returns the physical index at which the logical array starts
Sourcepub fn get_end_physical_index(&self) -> usize
pub fn get_end_physical_index(&self) -> usize
Returns the physical index at which the logical array ends
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
Slices this RunEndBuffer
by the provided offset
and length
Sourcepub fn inner(&self) -> &ScalarBuffer<E>
pub fn inner(&self) -> &ScalarBuffer<E>
Returns the inner ScalarBuffer
Sourcepub fn into_inner(self) -> ScalarBuffer<E>
pub fn into_inner(self) -> ScalarBuffer<E>
Returns the inner ScalarBuffer
, consuming self
Trait Implementations§
Source§impl<E: Clone + ArrowNativeType> Clone for RunEndBuffer<E>
impl<E: Clone + ArrowNativeType> Clone for RunEndBuffer<E>
Source§fn clone(&self) -> RunEndBuffer<E>
fn clone(&self) -> RunEndBuffer<E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more