pub struct SortedRun<K, V> { /* private fields */ }Expand description
An immutable sorted segment of key-value pairs
Used by the Balanced policy for LSM-style scan optimization. Each run is sorted by key, enabling efficient k-way merge.
§Key Range Metadata
Each run stores min_key and max_key bounds for O(1) overlap checking.
This enables prefix scan pruning: runs that don’t overlap the prefix
range can be skipped entirely.
Implementations§
Source§impl<K: Ord + Clone, V: Clone> SortedRun<K, V>
impl<K: Ord + Clone, V: Clone> SortedRun<K, V>
Sourcepub fn from_unsorted(entries: Vec<(K, V)>, level: usize) -> Self
pub fn from_unsorted(entries: Vec<(K, V)>, level: usize) -> Self
Create a new sorted run from unsorted entries
Sourcepub fn from_sorted(entries: Vec<(K, V)>, level: usize) -> Self
pub fn from_sorted(entries: Vec<(K, V)>, level: usize) -> Self
Create from already-sorted entries
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get size in bytes
Sourcepub fn range_from<'a>(&'a self, start: &K) -> impl Iterator<Item = &'a (K, V)>
pub fn range_from<'a>(&'a self, start: &K) -> impl Iterator<Item = &'a (K, V)>
Range scan from start key
Sourcepub fn range<'a>(
&'a self,
start: &K,
end: &K,
) -> impl Iterator<Item = &'a (K, V)>
pub fn range<'a>( &'a self, start: &K, end: &K, ) -> impl Iterator<Item = &'a (K, V)>
Range scan with bounds
Sourcepub fn entries(&self) -> &[(K, V)]
pub fn entries(&self) -> &[(K, V)]
Direct access to underlying entries for O(1) indexing
Required for efficient k-way merge. Without this accessor,
callers are forced to use iter().nth() which is O(n) per call.
Sourcepub fn overlaps_prefix(&self, prefix: &K) -> bool
pub fn overlaps_prefix(&self, prefix: &K) -> bool
Check if this run might contain keys with the given prefix.
Uses stored min_key and max_key bounds for O(1) overlap check.
Returns true if the run may contain matching keys (conservative).
Returns false only if we can prove no keys match.
§Prefix Overlap Logic
For a run with [min_key, max_key] to overlap prefix range [prefix, prefix++):
- If max_key < prefix → run is entirely before prefix → no overlap
- If min_key starts with prefix OR min_key < prefix and max_key >= prefix → overlap
We use a conservative check: return true unless max_key < prefix.
Sourcepub fn overlaps_range(&self, start: &K, end: &K) -> bool
pub fn overlaps_range(&self, start: &K, end: &K) -> bool
Check if this run might contain keys in the given range.
Uses stored min_key and max_key bounds for O(1) overlap check.
Returns true if the run may contain matching keys (conservative).
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for SortedRun<K, V>where
K: Freeze,
impl<K, V> RefUnwindSafe for SortedRun<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SortedRun<K, V>
impl<K, V> Sync for SortedRun<K, V>
impl<K, V> Unpin for SortedRun<K, V>
impl<K, V> UnsafeUnpin for SortedRun<K, V>where
K: UnsafeUnpin,
impl<K, V> UnwindSafe for SortedRun<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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