Skip to main content

StandardGraph

Struct StandardGraph 

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

A concrete, ergonomic graph type wrapping PatternGraph<(), Subject>.

StandardGraph eliminates the type parameters and classifier/policy boilerplate needed when working with PatternGraph directly. It provides fluent construction methods and graph-native queries.

§Examples

use pattern_core::graph::StandardGraph;
use pattern_core::subject::Subject;

let mut g = StandardGraph::new();
let alice = Subject::build("alice").label("Person").done();
let bob   = Subject::build("bob").label("Person").done();
g.add_node(alice.clone());
g.add_node(bob.clone());
g.add_relationship(Subject::build("r1").label("KNOWS").done(), &alice, &bob);
assert_eq!(g.node_count(), 2);
assert_eq!(g.relationship_count(), 1);

Implementations§

Source§

impl StandardGraph

Source

pub fn new() -> Self

Creates an empty StandardGraph.

Source

pub fn add_node(&mut self, subject: Subject) -> &mut Self

Adds a node to the graph.

The subject becomes an atomic pattern (no elements). If a node with the same identity already exists, it is replaced (last-write-wins).

Source

pub fn add_relationship( &mut self, subject: Subject, source: &Subject, target: &Subject, ) -> &mut Self

Adds a relationship to the graph.

Creates a 2-element pattern with the source and target nodes as elements. If the source or target nodes don’t exist yet, minimal placeholder nodes are created automatically.

Pass the actual Subject objects for source and target when you have them; use Subject::from_id("id") as a lightweight reference when you only have an identity string.

Source

pub fn add_walk( &mut self, subject: Subject, relationships: &[Subject], ) -> &mut Self

Adds a walk to the graph.

Creates an N-element pattern where each element is a relationship pattern. If referenced relationships don’t exist, minimal placeholders are created.

Pass the actual Subject objects for relationships when you have them; use Subject::from_id("id") as a lightweight reference when you only have an identity string.

Source

pub fn add_annotation( &mut self, subject: Subject, element: &Subject, ) -> &mut Self

Adds an annotation to the graph.

Creates a 1-element pattern wrapping the referenced element. If the referenced element doesn’t exist, a minimal placeholder node is created.

Pass the actual Subject when you have it; use Subject::from_id("id") as a lightweight reference when you only have an identity string.

Source

pub fn add_pattern(&mut self, pattern: Pattern<Subject>) -> &mut Self

Adds a single pattern, classifying it by shape and inserting into the appropriate bucket.

Source

pub fn add_patterns( &mut self, patterns: impl IntoIterator<Item = Pattern<Subject>>, ) -> &mut Self

Adds multiple patterns, classifying each by shape.

Source

pub fn from_patterns( patterns: impl IntoIterator<Item = Pattern<Subject>>, ) -> Self

Creates a StandardGraph from an iterator of patterns.

Source

pub fn from_pattern_graph(graph: PatternGraph<(), Subject>) -> Self

Creates a StandardGraph by wrapping an existing PatternGraph directly.

Source

pub fn node(&self, id: &Symbol) -> Option<&Pattern<Subject>>

Returns the node with the given identity.

Source

pub fn relationship(&self, id: &Symbol) -> Option<&Pattern<Subject>>

Returns the relationship with the given identity.

Source

pub fn walk(&self, id: &Symbol) -> Option<&Pattern<Subject>>

Returns the walk with the given identity.

Source

pub fn annotation(&self, id: &Symbol) -> Option<&Pattern<Subject>>

Returns the annotation with the given identity.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes.

Source

pub fn relationship_count(&self) -> usize

Returns the number of relationships.

Source

pub fn walk_count(&self) -> usize

Returns the number of walks.

Source

pub fn annotation_count(&self) -> usize

Returns the number of annotations.

Source

pub fn is_empty(&self) -> bool

Returns true if the graph has no elements in any bucket.

Source

pub fn has_conflicts(&self) -> bool

Returns true if any reconciliation conflicts have been recorded.

Source

pub fn conflicts(&self) -> &HashMap<Symbol, Vec<Pattern<Subject>>>

Returns the conflict map (identity → conflicting patterns).

Source

pub fn other(&self) -> &HashMap<Symbol, ((), Pattern<Subject>)>

Returns the “other” bucket (unclassifiable patterns).

Source

pub fn nodes(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>

Iterates over all nodes.

Source

pub fn relationships( &self, ) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>

Iterates over all relationships.

Source

pub fn walks(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>

Iterates over all walks.

Source

pub fn annotations(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>

Iterates over all annotations.

Source

pub fn source(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>

Returns the source node of a relationship.

Source

pub fn target(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>

Returns the target node of a relationship.

Source

pub fn neighbors(&self, node_id: &Symbol) -> Vec<&Pattern<Subject>>

Returns all neighbor nodes of the given node (both directions).

Source

pub fn degree(&self, node_id: &Symbol) -> usize

Returns the degree of a node (number of incident relationships, both directions).

Source

pub fn as_pattern_graph(&self) -> &PatternGraph<(), Subject>

Returns a reference to the inner PatternGraph.

Source

pub fn into_pattern_graph(self) -> PatternGraph<(), Subject>

Consumes the StandardGraph and returns the inner PatternGraph.

Source

pub fn as_query(&self) -> GraphQuery<Subject>

Creates a GraphQuery from this graph.

Source

pub fn as_snapshot(&self) -> GraphView<(), Subject>

Creates a GraphView snapshot from this graph.

Trait Implementations§

Source§

impl Default for StandardGraph

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 = 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.