pub struct StorageBlockIndex {
pub entries: HashMap<String, IndexEntry>,
pub index: HashMap<IndexKey, Vec<String>>,
}Expand description
Secondary index over stored blocks that accelerates queries by content type, size range, creation time, and custom tags without scanning all blocks.
§Indexing strategy
Every IndexEntry inserted into the index is registered under four
categories of IndexKey:
ContentType(content_type)— one key per entry.SizeBucket(size_bytes / 1_MiB)— coarse size bucket (1 MiB granularity).DayBucket(created_at_secs / 86_400)— coarse day bucket.Tag(tag)for each tag string inentry.tags.
The inverted index maps each IndexKey to the list of CID strings that
carry that key, enabling fast set-based retrieval without a full scan.
Fields§
§entries: HashMap<String, IndexEntry>Primary storage: maps CID to its full IndexEntry.
index: HashMap<IndexKey, Vec<String>>Inverted index: maps an IndexKey to the CIDs that belong to it.
Implementations§
Source§impl StorageBlockIndex
impl StorageBlockIndex
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty StorageBlockIndex.
Sourcepub fn insert(&mut self, entry: IndexEntry)
pub fn insert(&mut self, entry: IndexEntry)
Insert (or replace) an entry in the index.
If a previous entry exists for the same CID it is removed first so the inverted index does not accumulate stale pointers.
Sourcepub fn remove(&mut self, cid: &str) -> bool
pub fn remove(&mut self, cid: &str) -> bool
Remove an entry by CID from both the primary store and all index buckets.
Returns true when the entry existed and was removed, false otherwise.
Sourcepub fn query<'a>(&'a self, q: &IndexQuery) -> Vec<&'a IndexEntry>
pub fn query<'a>(&'a self, q: &IndexQuery) -> Vec<&'a IndexEntry>
Query the index with an IndexQuery filter.
The implementation performs a full scan of the primary entry map and
applies each active filter in turn. Results are sorted by
created_at_secs descending (newest first).
Sourcepub fn entries_for_key<'a>(&'a self, key: &IndexKey) -> Vec<&'a IndexEntry>
pub fn entries_for_key<'a>(&'a self, key: &IndexKey) -> Vec<&'a IndexEntry>
Look up all entries that are indexed under the given IndexKey.
Returns entries sorted by CID string for deterministic ordering.
Sourcepub fn stats(&self) -> IndexStats
pub fn stats(&self) -> IndexStats
Compute aggregate statistics over all indexed entries.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageBlockIndex
impl RefUnwindSafe for StorageBlockIndex
impl Send for StorageBlockIndex
impl Sync for StorageBlockIndex
impl Unpin for StorageBlockIndex
impl UnsafeUnpin for StorageBlockIndex
impl UnwindSafe for StorageBlockIndex
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