pub struct ISONGraph {
pub name: String,
pub directed: bool,
/* private fields */
}Expand description
In-memory property graph store with ISON persistence.
Features:
- Property graph model (nodes and edges with properties)
- Multiple node types and relationship types
- O(1) node lookup by (type, id)
- Multi-hop traversal
- Shortest path finding (BFS)
- All paths finding (DFS)
- ISON/ISONL persistence
Fields§
§name: StringGraph name
directed: boolWhether edges are directed
Implementations§
Source§impl ISONGraph
impl ISONGraph
Sourcepub fn undirected(name: impl Into<String>) -> Self
pub fn undirected(name: impl Into<String>) -> Self
Create an undirected graph
pub fn add_node( &mut self, node_type: &str, node_id: &str, properties: Vec<(&str, Value)>, ) -> Result<&Node>
Sourcepub fn get_node(&self, node_type: &str, node_id: &str) -> Result<&Node>
pub fn get_node(&self, node_type: &str, node_id: &str) -> Result<&Node>
Get a node by type and ID
Sourcepub fn get_node_by_id(&self, node_id: &NodeId) -> Result<&Node>
pub fn get_node_by_id(&self, node_id: &NodeId) -> Result<&Node>
Get a node by NodeId
Sourcepub fn remove_node(&mut self, node_type: &str, node_id: &str) -> Result<()>
pub fn remove_node(&mut self, node_type: &str, node_id: &str) -> Result<()>
Remove a node and all its edges
Sourcepub fn update_node(
&mut self,
node_type: &str,
node_id: &str,
properties: Vec<(&str, Value)>,
) -> Result<()>
pub fn update_node( &mut self, node_type: &str, node_id: &str, properties: Vec<(&str, Value)>, ) -> Result<()>
Update node properties
Sourcepub fn nodes_of_type(&self, node_type: &str) -> impl Iterator<Item = &Node>
pub fn nodes_of_type(&self, node_type: &str) -> impl Iterator<Item = &Node>
Iterate over nodes of a specific type
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Count all nodes
Sourcepub fn node_count_of_type(&self, node_type: &str) -> usize
pub fn node_count_of_type(&self, node_type: &str) -> usize
Count nodes of a specific type
Sourcepub fn node_types(&self) -> Vec<&String>
pub fn node_types(&self) -> Vec<&String>
Get all node types
Sourcepub fn add_edge(
&mut self,
rel_type: &str,
source: (&str, &str),
target: (&str, &str),
properties: Vec<(&str, Value)>,
) -> Result<()>
pub fn add_edge( &mut self, rel_type: &str, source: (&str, &str), target: (&str, &str), properties: Vec<(&str, Value)>, ) -> Result<()>
Add an edge to the graph
Sourcepub fn remove_edge(
&mut self,
rel_type: &str,
source: (&str, &str),
target: (&str, &str),
) -> Result<()>
pub fn remove_edge( &mut self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> Result<()>
Remove an edge
Sourcepub fn has_edge(
&self,
rel_type: &str,
source: (&str, &str),
target: (&str, &str),
) -> bool
pub fn has_edge( &self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> bool
Check if edge exists
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Count all edges
Sourcepub fn edge_count_of_type(&self, rel_type: &str) -> usize
pub fn edge_count_of_type(&self, rel_type: &str) -> usize
Count edges of a specific type
Sourcepub fn edge_types(&self) -> Vec<&String>
pub fn edge_types(&self) -> Vec<&String>
Get all edge types
Sourcepub fn edges_of_type(&self, rel_type: &str) -> impl Iterator<Item = &Edge>
pub fn edges_of_type(&self, rel_type: &str) -> impl Iterator<Item = &Edge>
Get all edges of a specific type
Sourcepub fn has_cycle(&self, rel_type: Option<&str>) -> bool
pub fn has_cycle(&self, rel_type: Option<&str>) -> bool
Check if the graph has a cycle for edges of a specific type
Sourcepub fn neighbors(
&self,
node_ref: &NodeRef<'_>,
rel_type: Option<&str>,
direction: Direction,
) -> Vec<NodeId>
pub fn neighbors( &self, node_ref: &NodeRef<'_>, rel_type: Option<&str>, direction: Direction, ) -> Vec<NodeId>
Get neighboring nodes.
Results are deduplicated while preserving first-occurrence order:
a node connected through multiple edges (e.g. the forward and
auto-reverse edges of an undirected graph with Direction::Both)
appears only once.
Sourcepub fn multi_hop(
&self,
start: &NodeRef<'_>,
rel_type: Option<&str>,
hops: usize,
direction: Direction,
) -> Vec<NodeId>
pub fn multi_hop( &self, start: &NodeRef<'_>, rel_type: Option<&str>, hops: usize, direction: Direction, ) -> Vec<NodeId>
Get nodes N hops away
Sourcepub fn multi_hop_range(
&self,
start: &NodeRef<'_>,
rel_type: Option<&str>,
min_hops: usize,
max_hops: usize,
direction: Direction,
) -> Vec<NodeId>
pub fn multi_hop_range( &self, start: &NodeRef<'_>, rel_type: Option<&str>, min_hops: usize, max_hops: usize, direction: Direction, ) -> Vec<NodeId>
Get nodes within a range of hops
Sourcepub fn shortest_path(
&self,
start: &NodeRef<'_>,
end: &NodeRef<'_>,
rel_type: Option<&str>,
max_hops: usize,
direction: Direction,
) -> Option<Path>
pub fn shortest_path( &self, start: &NodeRef<'_>, end: &NodeRef<'_>, rel_type: Option<&str>, max_hops: usize, direction: Direction, ) -> Option<Path>
Find shortest path between two nodes using BFS
Sourcepub fn path_exists(
&self,
start: &NodeRef<'_>,
end: &NodeRef<'_>,
rel_type: Option<&str>,
max_hops: usize,
direction: Direction,
) -> bool
pub fn path_exists( &self, start: &NodeRef<'_>, end: &NodeRef<'_>, rel_type: Option<&str>, max_hops: usize, direction: Direction, ) -> bool
Check if a path exists between two nodes in the given direction
Sourcepub fn out_degree(&self, node_ref: &NodeRef<'_>) -> usize
pub fn out_degree(&self, node_ref: &NodeRef<'_>) -> usize
Count outgoing edges for a node
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if graph is connected
Sourcepub fn to_ison(&self) -> String
pub fn to_ison(&self) -> String
Serialize graph to canonical ISON (ISONCS).
Output is canonical: the same logical graph always serializes to the same bytes regardless of construction order. Block, row and column order are the canonical writer’s, not ISONGraph’s.
Sourcepub fn to_isonl(&self) -> String
pub fn to_isonl(&self) -> String
Serialize graph to canonical ISONL. Row order matches [to_ison].
pub fn save<P: AsRef<StdPath>>( &self, path: P, format: Option<&str>, ) -> Result<()>
Sourcepub fn load<P: AsRef<StdPath>>(path: P, format: Option<&str>) -> Result<Self>
pub fn load<P: AsRef<StdPath>>(path: P, format: Option<&str>) -> Result<Self>
Load graph from file
Sourcepub fn get_edge(
&self,
rel_type: &str,
source: (&str, &str),
target: (&str, &str),
) -> Result<&Edge>
pub fn get_edge( &self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> Result<&Edge>
Get an edge by its components
Sourcepub fn connected_components(&self) -> Vec<HashSet<NodeId>>
pub fn connected_components(&self) -> Vec<HashSet<NodeId>>
Get all connected components
Sourcepub fn all_paths(
&self,
start: &NodeRef<'_>,
end: &NodeRef<'_>,
rel_type: Option<&str>,
max_hops: usize,
direction: Direction,
) -> Vec<Path>
pub fn all_paths( &self, start: &NodeRef<'_>, end: &NodeRef<'_>, rel_type: Option<&str>, max_hops: usize, direction: Direction, ) -> Vec<Path>
Find all paths between two nodes using iterative DFS
Sourcepub fn traverse(
&self,
start: &NodeRef<'_>,
pattern: &[(String, Direction)],
filter_fn: Option<&dyn Fn(&Node) -> bool>,
) -> Vec<NodeId>
pub fn traverse( &self, start: &NodeRef<'_>, pattern: &[(String, Direction)], filter_fn: Option<&dyn Fn(&Node) -> bool>, ) -> Vec<NodeId>
Traverse graph following a pattern of relationship types
Sourcepub fn query(&self, pattern: &str) -> Result<Vec<NodeId>>
pub fn query(&self, pattern: &str) -> Result<Vec<NodeId>>
Execute a simple pattern query
Pattern syntax: :type:id -[:REL]-> * (single hop) :type:id -[:RELN]-> * (N hops) :type:id -[:REL1..3]-> * (1-3 hops range)
Sourcepub fn start(&self, node_ref: &NodeRef<'_>) -> GraphTraversal<'_>
pub fn start(&self, node_ref: &NodeRef<'_>) -> GraphTraversal<'_>
Start a fluent traversal from a node