pub struct NodeSecondaryIndex { /* private fields */ }Expand description
Inverted secondary indexes on graph nodes.
by_type:LabelId → set of node ids— keyed by the registry-assigned identifier so user-defined labels participate in the same fast path the legacy enum used to enjoy.by_label:label string → set of node ids(display label, not category)label_bloom: fast negative filter over distinct display labels
Implementations§
Source§impl NodeSecondaryIndex
impl NodeSecondaryIndex
Sourcepub fn new(expected_labels: usize) -> NodeSecondaryIndex
pub fn new(expected_labels: usize) -> NodeSecondaryIndex
Create an empty index sized for expected_labels distinct label
values (used to size the bloom filter).
Sourcepub fn insert(&self, node_id: &str, label_id: LabelId, label: &str)
pub fn insert(&self, node_id: &str, label_id: LabelId, label: &str)
Record (label_id, label, node_id) in both inverted maps.
Safe to call concurrently — each map takes its own write lock. Duplicate inserts are idempotent (sets).
Sourcepub fn remove(&self, node_id: &str, label_id: LabelId, label: &str)
pub fn remove(&self, node_id: &str, label_id: LabelId, label: &str)
Remove a node from both inverted maps. Does not rebuild the bloom (bloom filters don’t support removal — stale positives are harmless).
Sourcepub fn nodes_by_type(&self, label_id: LabelId) -> Vec<String>
pub fn nodes_by_type(&self, label_id: LabelId) -> Vec<String>
Return all node ids of a given label. O(1) lookup + clone.
Sourcepub fn nodes_by_label(&self, label: &str) -> Vec<String>
pub fn nodes_by_label(&self, label: &str) -> Vec<String>
Return all node ids with a given label. Uses the bloom as a pre-check
— callers get an immediate empty Vec for definitely-absent labels.
Sourcepub fn count_by_type(&self, label_id: LabelId) -> usize
pub fn count_by_type(&self, label_id: LabelId) -> usize
Cardinality of a label bucket (fast stat for the planner).
Sourcepub fn label_id_counts(&self) -> Vec<(LabelId, u64)>
pub fn label_id_counts(&self) -> Vec<(LabelId, u64)>
Snapshot (label_id, cardinality) for every populated bucket. Cheap
enough for stats() to call on demand instead of a full
iter_nodes() scan.
Sourcepub fn distinct_labels(&self) -> usize
pub fn distinct_labels(&self) -> usize
Number of distinct labels tracked.
Sourcepub fn distinct_types(&self) -> usize
pub fn distinct_types(&self) -> usize
Number of distinct node types tracked.
Source§impl NodeSecondaryIndex
impl NodeSecondaryIndex
Sourcepub fn may_contain_label(&self, label: &str) -> bool
pub fn may_contain_label(&self, label: &str) -> bool
Public fast-path for label membership. Returns false iff the bloom
proves the label was never inserted.
Trait Implementations§
Source§impl Default for NodeSecondaryIndex
impl Default for NodeSecondaryIndex
Source§fn default() -> NodeSecondaryIndex
fn default() -> NodeSecondaryIndex
Source§impl HasBloom for NodeSecondaryIndex
HasBloom impl pushes the label bloom through the shared trait so the
unified query planner can consult it uniformly.
impl HasBloom for NodeSecondaryIndex
HasBloom impl pushes the label bloom through the shared trait so the
unified query planner can consult it uniformly.
Note: this returns None because the underlying bloom is behind a
RwLock. See NodeSecondaryIndex::may_contain_label for the actual
fast-path. The impl exists so call-sites that only know dyn HasBloom
can still reach the index via IndexBase::definitely_absent.
Source§fn bloom_segment(&self) -> Option<&BloomSegment>
fn bloom_segment(&self) -> Option<&BloomSegment>
Source§fn definitely_absent(&self, key: &[u8]) -> bool
fn definitely_absent(&self, key: &[u8]) -> bool
true iff the bloom is present and
reports the key as absent.Source§impl IndexBase for NodeSecondaryIndex
impl IndexBase for NodeSecondaryIndex
Source§fn stats(&self) -> IndexStats
fn stats(&self) -> IndexStats
Source§fn bloom(&self) -> Option<&BloomFilter>
fn bloom(&self) -> Option<&BloomFilter>
Source§fn definitely_absent(&self, key_bytes: &[u8]) -> bool
fn definitely_absent(&self, key_bytes: &[u8]) -> bool
true iff the key is guaranteed to be absent from this
index. Default implementation consults IndexBase::bloom and falls
back to false when no bloom is available (meaning “don’t know —
caller must probe”). Read moreAuto Trait Implementations§
impl !Freeze for NodeSecondaryIndex
impl RefUnwindSafe for NodeSecondaryIndex
impl Send for NodeSecondaryIndex
impl Sync for NodeSecondaryIndex
impl Unpin for NodeSecondaryIndex
impl UnsafeUnpin for NodeSecondaryIndex
impl UnwindSafe for NodeSecondaryIndex
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> 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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request