Skip to main content

ISONGraph

Struct ISONGraph 

Source
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: String

Graph name

§directed: bool

Whether edges are directed

Implementations§

Source§

impl ISONGraph

Source

pub fn new(name: impl Into<String>) -> Self

Create a new graph

Source

pub fn undirected(name: impl Into<String>) -> Self

Create an undirected graph

Source

pub fn add_node( &mut self, node_type: &str, node_id: &str, properties: Vec<(&str, Value)>, ) -> Result<&Node>

Source

pub fn get_node(&self, node_type: &str, node_id: &str) -> Result<&Node>

Get a node by type and ID

Source

pub fn get_node_by_id(&self, node_id: &NodeId) -> Result<&Node>

Get a node by NodeId

Source

pub fn has_node(&self, node_type: &str, node_id: &str) -> bool

Check if node exists

Source

pub fn remove_node(&mut self, node_type: &str, node_id: &str) -> Result<()>

Remove a node and all its edges

Source

pub fn update_node( &mut self, node_type: &str, node_id: &str, properties: Vec<(&str, Value)>, ) -> Result<()>

Update node properties

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node>

Iterate over all nodes

Source

pub fn nodes_of_type(&self, node_type: &str) -> impl Iterator<Item = &Node>

Iterate over nodes of a specific type

Source

pub fn node_count(&self) -> usize

Count all nodes

Source

pub fn node_count_of_type(&self, node_type: &str) -> usize

Count nodes of a specific type

Source

pub fn node_types(&self) -> Vec<&String>

Get all node types

Source

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

Source

pub fn remove_edge( &mut self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> Result<()>

Remove an edge

Source

pub fn has_edge( &self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> bool

Check if edge exists

Source

pub fn edge_count(&self) -> usize

Count all edges

Source

pub fn edge_count_of_type(&self, rel_type: &str) -> usize

Count edges of a specific type

Source

pub fn edge_types(&self) -> Vec<&String>

Get all edge types

Source

pub fn edges_of_type(&self, rel_type: &str) -> impl Iterator<Item = &Edge>

Get all edges of a specific type

Source

pub fn has_cycle(&self, rel_type: Option<&str>) -> bool

Check if the graph has a cycle for edges of a specific type

Source

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.

Source

pub fn multi_hop( &self, start: &NodeRef<'_>, rel_type: Option<&str>, hops: usize, direction: Direction, ) -> Vec<NodeId>

Get nodes N hops away

Source

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

Source

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

Source

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

Source

pub fn in_degree(&self, node_ref: &NodeRef<'_>) -> usize

Count incoming edges for a node

Source

pub fn out_degree(&self, node_ref: &NodeRef<'_>) -> usize

Count outgoing edges for a node

Source

pub fn degree(&self, node_ref: &NodeRef<'_>) -> usize

Total degree for a node

Source

pub fn is_connected(&self) -> bool

Check if graph is connected

Source

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.

Source

pub fn to_isonl(&self) -> String

Serialize graph to canonical ISONL. Row order matches [to_ison].

Source

pub fn from_ison(text: &str, name: Option<&str>) -> Result<Self>

Parse a graph from ISON.

Source

pub fn from_isonl(text: &str, name: Option<&str>) -> Result<Self>

Parse a graph from ISONL.

Source

pub fn save<P: AsRef<StdPath>>( &self, path: P, format: Option<&str>, ) -> Result<()>

Source

pub fn load<P: AsRef<StdPath>>(path: P, format: Option<&str>) -> Result<Self>

Load graph from file

Source

pub fn get_edge( &self, rel_type: &str, source: (&str, &str), target: (&str, &str), ) -> Result<&Edge>

Get an edge by its components

Source

pub fn connected_components(&self) -> Vec<HashSet<NodeId>>

Get all connected components

Source

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

Source

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

Source

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)

Source

pub fn start(&self, node_ref: &NodeRef<'_>) -> GraphTraversal<'_>

Start a fluent traversal from a node

Trait Implementations§

Source§

impl Debug for ISONGraph

Source§

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

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

impl Default for ISONGraph

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.