pub struct TimeIndex { /* private fields */ }Expand description
Sorted time-range index for fast segment pruning.
Entries are kept in a BTreeSet ordered by (min_ts, segment_id) for
O(log N) insert and remove. Range queries use a BTree range scan.
Thread-safe via Arc<RwLock<>>.
§Complexity
segments_for_range: O(log N + K) where K is the number of matching segmentsadd_segment: O(log N) insertremove_segment: O(log N) remove
Implementations§
Source§impl TimeIndex
impl TimeIndex
Sourcepub fn segments_for_range(
&self,
start_ts: Timestamp,
end_ts: Timestamp,
) -> Vec<SegmentId>
pub fn segments_for_range( &self, start_ts: Timestamp, end_ts: Timestamp, ) -> Vec<SegmentId>
Find all segments whose time range overlaps [start_ts, end_ts].
Uses a BTree range scan: iterates entries with min_ts <= end_ts
and filters by max_ts >= start_ts. Entries with min_ts > end_ts
are skipped entirely via the range upper bound.
There is deliberately no bounded variant. One existed —
segments_for_range_limited, documented for “pagination or preview
queries” — whose only caller passed usize::MAX. Dropping segments
from a scan is not pagination: it returns an arbitrary subset of the
rows with no error and no way for the caller to tell.
Sourcepub fn add_segment(&self, entry: TimeIndexEntry)
pub fn add_segment(&self, entry: TimeIndexEntry)
Add a segment to the index.
Acquires locks in canonical order (entries → meta)
to prevent deadlocks with remove_segment().
Sourcepub fn remove_segment(&self, segment_id: SegmentId) -> bool
pub fn remove_segment(&self, segment_id: SegmentId) -> bool
Remove a segment from the index by its ID.
Acquires locks in canonical order (entries → meta),
matching add_segment(), to prevent deadlocks. Both structures
are updated atomically under their respective write locks.
Returns true if the segment was found and removed.
Sourcepub fn all_entries(&self) -> Vec<TimeIndexEntry>
pub fn all_entries(&self) -> Vec<TimeIndexEntry>
Returns all entries sorted by (min_ts, segment_id) (for serialization/persistence).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TimeIndex
impl !UnwindSafe for TimeIndex
impl Freeze for TimeIndex
impl Send for TimeIndex
impl Sync for TimeIndex
impl Unpin for TimeIndex
impl UnsafeUnpin for TimeIndex
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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