Skip to main content

BidirectionalIndex

Struct BidirectionalIndex 

Source
pub struct BidirectionalIndex { /* private fields */ }
Expand description

Bidirectional index for fast entity-chunk lookups

This structure maintains two indexes:

  1. Entity → Chunks: Given an entity, find all chunks it appears in
  2. Chunk → Entities: Given a chunk, find all entities it contains

Implementations§

Source§

impl BidirectionalIndex

Source

pub fn new() -> Self

Create a new empty bidirectional index

Source

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

Source

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

Source

pub fn add_entity_mappings( &mut self, entity_id: &EntityId, chunk_ids: &[ChunkId], )

Add multiple mappings for an entity

Source

pub fn add_chunk_mappings( &mut self, chunk_id: &ChunkId, entity_ids: &[EntityId], )

Add multiple mappings for a chunk

Source

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

Source

pub fn remove_entity(&mut self, entity_id: &EntityId) -> usize

Remove all mappings for an entity

Returns the number of mappings removed

Source

pub fn remove_chunk(&mut self, chunk_id: &ChunkId) -> usize

Remove all mappings for a chunk

Returns the number of mappings removed

Source

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

Source

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

Source

pub fn has_mapping(&self, entity_id: &EntityId, chunk_id: &ChunkId) -> bool

Check if a specific entity-chunk mapping exists

Source

pub fn get_entity_chunk_count(&self, entity_id: &EntityId) -> usize

Get the number of chunks an entity appears in

Source

pub fn get_chunk_entity_count(&self, chunk_id: &ChunkId) -> usize

Get the number of entities in a chunk

Source

pub fn get_all_entities(&self) -> Vec<EntityId>

Get all entity IDs in the index

Source

pub fn get_all_chunks(&self) -> Vec<ChunkId>

Get all chunk IDs in the index

Source

pub fn entity_count(&self) -> usize

Get the total number of unique entities

Source

pub fn chunk_count(&self) -> usize

Get the total number of unique chunks

Source

pub fn mapping_count(&self) -> usize

Get the total number of entity-chunk mappings

Source

pub fn is_empty(&self) -> bool

Check if the index is empty

Source

pub fn clear(&mut self)

Clear all mappings from the index

Source

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

Source

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)

Source

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)

Source

pub fn merge(&mut self, other: &BidirectionalIndex)

Merge another index into this one

Useful for combining indices from multiple documents

Source

pub fn get_statistics(&self) -> IndexStatistics

Get statistics about the index

Trait Implementations§

Source§

impl Clone for BidirectionalIndex

Source§

fn clone(&self) -> BidirectionalIndex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BidirectionalIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BidirectionalIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for BidirectionalIndex

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for BidirectionalIndex

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,