pub struct EntityGraph { /* private fields */ }Expand description
Core entity graph with bitmap tag indexing and bidirectional ref adjacency.
Implementations§
Source§impl EntityGraph
impl EntityGraph
Sourcepub fn with_namespace(ns: DefNamespace) -> Self
pub fn with_namespace(ns: DefNamespace) -> Self
Create an entity graph with an ontology namespace.
Sourcepub fn index_field(&mut self, field: &str)
pub fn index_field(&mut self, field: &str)
Register a field for B-Tree value indexing. Enables O(log N) range
queries (e.g. temp > 72) for this field. Must be called before
entities are added, or followed by rebuild_value_index for existing data.
Sourcepub fn rebuild_value_index(&mut self)
pub fn rebuild_value_index(&mut self)
Rebuild the value index for all indexed fields from the current entities.
Sourcepub fn value_index(&self) -> &ValueIndex
pub fn value_index(&self) -> &ValueIndex
Returns a reference to the value index (for use by the query planner).
Sourcepub fn track_column(&mut self, tag: &str)
pub fn track_column(&mut self, tag: &str)
Register a tag for columnar storage. Enables cache-friendly sequential
scans for this tag. Must be called before entities are added, or followed
by rebuild_columnar for existing data.
Sourcepub fn rebuild_columnar(&mut self)
pub fn rebuild_columnar(&mut self)
Rebuild all tracked columnar data from current entities.
Sourcepub fn columnar(&self) -> &ColumnarStore
pub fn columnar(&self) -> &ColumnarStore
Returns a reference to the columnar store for direct column scans.
Sourcepub fn add(&mut self, entity: HDict) -> Result<String, GraphError>
pub fn add(&mut self, entity: HDict) -> Result<String, GraphError>
Add an entity to the graph.
The entity must have an id tag that is a Ref. Returns the ref
value string on success.
Sourcepub fn update(
&mut self,
ref_val: &str,
changes: HDict,
) -> Result<(), GraphError>
pub fn update( &mut self, ref_val: &str, changes: HDict, ) -> Result<(), GraphError>
Update an existing entity by merging changes into it.
Tags in changes overwrite existing tags; Kind::Remove tags are
deleted. The id tag cannot be changed.
Sourcepub fn remove(&mut self, ref_val: &str) -> Result<HDict, GraphError>
pub fn remove(&mut self, ref_val: &str) -> Result<HDict, GraphError>
Remove an entity from the graph. Returns the removed entity.
Sourcepub fn read(&self, filter_expr: &str, limit: usize) -> Result<HGrid, GraphError>
pub fn read(&self, filter_expr: &str, limit: usize) -> Result<HGrid, GraphError>
Run a filter expression and return matching entities as a grid.
Sourcepub fn read_all(
&self,
filter_expr: &str,
limit: usize,
) -> Result<Vec<&HDict>, GraphError>
pub fn read_all( &self, filter_expr: &str, limit: usize, ) -> Result<Vec<&HDict>, GraphError>
Run a filter expression and return matching entities as references.
Sourcepub fn refs_from(&self, ref_val: &str, ref_type: Option<&str>) -> Vec<String>
pub fn refs_from(&self, ref_val: &str, ref_type: Option<&str>) -> Vec<String>
Get ref values that the given entity points to.
Sourcepub fn refs_to(&self, ref_val: &str, ref_type: Option<&str>) -> Vec<String>
pub fn refs_to(&self, ref_val: &str, ref_type: Option<&str>) -> Vec<String>
Get ref values of entities that point to the given entity.
Sourcepub fn rebuild_csr(&mut self)
pub fn rebuild_csr(&mut self)
Rebuild the CSR snapshot from the current adjacency. Should be called after a batch of mutations (e.g., import, sync).
Sourcepub fn csr_is_stale(&self) -> bool
pub fn csr_is_stale(&self) -> bool
Returns true if the CSR snapshot is stale (version mismatch).
Sourcepub fn all_edges(&self) -> Vec<(String, String, String)>
pub fn all_edges(&self) -> Vec<(String, String, String)>
Return all edges in the graph as (source_ref, ref_tag, target_ref) tuples.
Sourcepub fn neighbors(
&self,
ref_val: &str,
hops: usize,
ref_types: Option<&[&str]>,
) -> (Vec<&HDict>, Vec<(String, String, String)>)
pub fn neighbors( &self, ref_val: &str, hops: usize, ref_types: Option<&[&str]>, ) -> (Vec<&HDict>, Vec<(String, String, String)>)
BFS neighborhood: return entities and edges within hops of ref_val.
ref_types optionally restricts which ref tags are traversed.
Returns (entities, edges) where edges are (source, ref_tag, target).
Sourcepub fn shortest_path(&self, from: &str, to: &str) -> Vec<String>
pub fn shortest_path(&self, from: &str, to: &str) -> Vec<String>
BFS shortest path from from to to. Returns ordered ref_vals, or
empty vec if no path exists.
Sourcepub fn subtree(&self, root: &str, max_depth: usize) -> Vec<(&HDict, usize)>
pub fn subtree(&self, root: &str, max_depth: usize) -> Vec<(&HDict, usize)>
Return the subtree rooted at root up to max_depth levels.
Walks reverse refs (children referencing parent). Returns entities paired with their depth from root. Root is depth 0.
Sourcepub fn entities_fitting(&self, spec_name: &str) -> Vec<&HDict>
pub fn entities_fitting(&self, spec_name: &str) -> Vec<&HDict>
Find all entities that structurally fit a spec/type name.
Requires a namespace to be set. Returns empty if no namespace.
Sourcepub fn validate(&self) -> Vec<ValidationIssue>
pub fn validate(&self) -> Vec<ValidationIssue>
Validate all entities against the namespace and check for dangling refs.
Returns empty if no namespace is set and no dangling refs exist.
Sourcepub fn to_grid(&self, filter_expr: &str) -> Result<HGrid, GraphError>
pub fn to_grid(&self, filter_expr: &str) -> Result<HGrid, GraphError>
Convert matching entities to a grid.
If filter_expr is empty, exports all entities.
Otherwise, delegates to read.
Sourcepub fn from_grid(
grid: &HGrid,
namespace: Option<DefNamespace>,
) -> Result<Self, GraphError>
pub fn from_grid( grid: &HGrid, namespace: Option<DefNamespace>, ) -> Result<Self, GraphError>
Build an EntityGraph from a grid.
Rows without a valid id Ref tag are silently skipped.
Sourcepub fn changes_since(&self, version: u64) -> Vec<&GraphDiff>
pub fn changes_since(&self, version: u64) -> Vec<&GraphDiff>
Get changelog entries since a given version.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EntityGraph
impl !RefUnwindSafe for EntityGraph
impl Send for EntityGraph
impl Sync for EntityGraph
impl Unpin for EntityGraph
impl UnsafeUnpin for EntityGraph
impl UnwindSafe for EntityGraph
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> 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