pub struct BidirectionalIndex { /* private fields */ }Expand description
Bidirectional index for fast entity-chunk lookups
This structure maintains two indexes:
- Entity → Chunks: Given an entity, find all chunks it appears in
- Chunk → Entities: Given a chunk, find all entities it contains
Implementations§
Source§impl BidirectionalIndex
impl BidirectionalIndex
Sourcepub fn from_entities(entities: &[Entity]) -> Self
pub fn from_entities(entities: &[Entity]) -> Self
Create a bidirectional index from a collection of entities
This is useful for building the index from extracted entities
Sourcepub fn add_mapping(&mut self, entity_id: &EntityId, chunk_id: &ChunkId)
pub fn add_mapping(&mut self, entity_id: &EntityId, chunk_id: &ChunkId)
Add a mapping between an entity and a chunk
This is idempotent - adding the same mapping multiple times has no effect
Sourcepub fn add_entity_mappings(
&mut self,
entity_id: &EntityId,
chunk_ids: &[ChunkId],
)
pub fn add_entity_mappings( &mut self, entity_id: &EntityId, chunk_ids: &[ChunkId], )
Add multiple mappings for an entity
Sourcepub fn add_chunk_mappings(
&mut self,
chunk_id: &ChunkId,
entity_ids: &[EntityId],
)
pub fn add_chunk_mappings( &mut self, chunk_id: &ChunkId, entity_ids: &[EntityId], )
Add multiple mappings for a chunk
Sourcepub fn remove_mapping(
&mut self,
entity_id: &EntityId,
chunk_id: &ChunkId,
) -> bool
pub fn remove_mapping( &mut self, entity_id: &EntityId, chunk_id: &ChunkId, ) -> bool
Remove a specific mapping between an entity and a chunk
Returns true if the mapping existed and was removed
Sourcepub fn remove_entity(&mut self, entity_id: &EntityId) -> usize
pub fn remove_entity(&mut self, entity_id: &EntityId) -> usize
Remove all mappings for an entity
Returns the number of mappings removed
Sourcepub fn remove_chunk(&mut self, chunk_id: &ChunkId) -> usize
pub fn remove_chunk(&mut self, chunk_id: &ChunkId) -> usize
Remove all mappings for a chunk
Returns the number of mappings removed
Sourcepub fn get_chunks_for_entity(&self, entity_id: &EntityId) -> Vec<ChunkId>
pub fn get_chunks_for_entity(&self, entity_id: &EntityId) -> Vec<ChunkId>
Get all chunks that contain a specific entity
Returns an empty vector if the entity is not found
Sourcepub fn get_entities_for_chunk(&self, chunk_id: &ChunkId) -> Vec<EntityId>
pub fn get_entities_for_chunk(&self, chunk_id: &ChunkId) -> Vec<EntityId>
Get all entities in a specific chunk
Returns an empty vector if the chunk is not found
Sourcepub fn has_mapping(&self, entity_id: &EntityId, chunk_id: &ChunkId) -> bool
pub fn has_mapping(&self, entity_id: &EntityId, chunk_id: &ChunkId) -> bool
Check if a specific entity-chunk mapping exists
Sourcepub fn get_entity_chunk_count(&self, entity_id: &EntityId) -> usize
pub fn get_entity_chunk_count(&self, entity_id: &EntityId) -> usize
Get the number of chunks an entity appears in
Sourcepub fn get_chunk_entity_count(&self, chunk_id: &ChunkId) -> usize
pub fn get_chunk_entity_count(&self, chunk_id: &ChunkId) -> usize
Get the number of entities in a chunk
Sourcepub fn get_all_entities(&self) -> Vec<EntityId>
pub fn get_all_entities(&self) -> Vec<EntityId>
Get all entity IDs in the index
Sourcepub fn get_all_chunks(&self) -> Vec<ChunkId>
pub fn get_all_chunks(&self) -> Vec<ChunkId>
Get all chunk IDs in the index
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Get the total number of unique entities
Sourcepub fn chunk_count(&self) -> usize
pub fn chunk_count(&self) -> usize
Get the total number of unique chunks
Sourcepub fn mapping_count(&self) -> usize
pub fn mapping_count(&self) -> usize
Get the total number of entity-chunk mappings
Sourcepub fn get_co_occurring_entities(
&self,
entity_id: &EntityId,
) -> HashMap<EntityId, usize>
pub fn get_co_occurring_entities( &self, entity_id: &EntityId, ) -> HashMap<EntityId, usize>
Get co-occurring entities for a given entity
Returns entities that appear in the same chunks, along with their co-occurrence count
Sourcepub fn get_common_entities(
&self,
min_chunk_count: usize,
) -> Vec<(EntityId, usize)>
pub fn get_common_entities( &self, min_chunk_count: usize, ) -> Vec<(EntityId, usize)>
Get entities that appear in multiple chunks (common entities)
Returns entities sorted by the number of chunks they appear in (descending)
Sourcepub fn get_dense_chunks(&self, min_entity_count: usize) -> Vec<(ChunkId, usize)>
pub fn get_dense_chunks(&self, min_entity_count: usize) -> Vec<(ChunkId, usize)>
Get chunks that contain multiple entities (dense chunks)
Returns chunks sorted by the number of entities they contain (descending)
Sourcepub fn merge(&mut self, other: &BidirectionalIndex)
pub fn merge(&mut self, other: &BidirectionalIndex)
Merge another index into this one
Useful for combining indices from multiple documents
Sourcepub fn get_statistics(&self) -> IndexStatistics
pub fn get_statistics(&self) -> IndexStatistics
Get statistics about the index
Trait Implementations§
Source§impl Clone for BidirectionalIndex
impl Clone for BidirectionalIndex
Source§fn clone(&self) -> BidirectionalIndex
fn clone(&self) -> BidirectionalIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BidirectionalIndex
impl Debug for BidirectionalIndex
Source§impl Default for BidirectionalIndex
impl Default for BidirectionalIndex
Source§impl<'de> Deserialize<'de> for BidirectionalIndex
impl<'de> Deserialize<'de> for BidirectionalIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for BidirectionalIndex
impl RefUnwindSafe for BidirectionalIndex
impl Send for BidirectionalIndex
impl Sync for BidirectionalIndex
impl Unpin for BidirectionalIndex
impl UnsafeUnpin for BidirectionalIndex
impl UnwindSafe for BidirectionalIndex
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> 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