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
impl StandardGraph
Sourcepub fn add_node(&mut self, subject: Subject) -> &mut Self
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).
Sourcepub fn add_relationship(
&mut self,
subject: Subject,
source: &Subject,
target: &Subject,
) -> &mut Self
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.
Sourcepub fn add_walk(
&mut self,
subject: Subject,
relationships: &[Subject],
) -> &mut Self
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.
Sourcepub fn add_annotation(
&mut self,
subject: Subject,
element: &Subject,
) -> &mut Self
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.
Sourcepub fn add_pattern(&mut self, pattern: Pattern<Subject>) -> &mut Self
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.
Sourcepub fn add_patterns(
&mut self,
patterns: impl IntoIterator<Item = Pattern<Subject>>,
) -> &mut Self
pub fn add_patterns( &mut self, patterns: impl IntoIterator<Item = Pattern<Subject>>, ) -> &mut Self
Adds multiple patterns, classifying each by shape.
Sourcepub fn from_patterns(
patterns: impl IntoIterator<Item = Pattern<Subject>>,
) -> Self
pub fn from_patterns( patterns: impl IntoIterator<Item = Pattern<Subject>>, ) -> Self
Creates a StandardGraph from an iterator of patterns.
Sourcepub fn from_pattern_graph(graph: PatternGraph<(), Subject>) -> Self
pub fn from_pattern_graph(graph: PatternGraph<(), Subject>) -> Self
Creates a StandardGraph by wrapping an existing PatternGraph directly.
Sourcepub fn node(&self, id: &Symbol) -> Option<&Pattern<Subject>>
pub fn node(&self, id: &Symbol) -> Option<&Pattern<Subject>>
Returns the node with the given identity.
Sourcepub fn relationship(&self, id: &Symbol) -> Option<&Pattern<Subject>>
pub fn relationship(&self, id: &Symbol) -> Option<&Pattern<Subject>>
Returns the relationship with the given identity.
Sourcepub fn walk(&self, id: &Symbol) -> Option<&Pattern<Subject>>
pub fn walk(&self, id: &Symbol) -> Option<&Pattern<Subject>>
Returns the walk with the given identity.
Sourcepub fn annotation(&self, id: &Symbol) -> Option<&Pattern<Subject>>
pub fn annotation(&self, id: &Symbol) -> Option<&Pattern<Subject>>
Returns the annotation with the given identity.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn relationship_count(&self) -> usize
pub fn relationship_count(&self) -> usize
Returns the number of relationships.
Sourcepub fn walk_count(&self) -> usize
pub fn walk_count(&self) -> usize
Returns the number of walks.
Sourcepub fn annotation_count(&self) -> usize
pub fn annotation_count(&self) -> usize
Returns the number of annotations.
Sourcepub fn has_conflicts(&self) -> bool
pub fn has_conflicts(&self) -> bool
Returns true if any reconciliation conflicts have been recorded.
Sourcepub fn conflicts(&self) -> &HashMap<Symbol, Vec<Pattern<Subject>>>
pub fn conflicts(&self) -> &HashMap<Symbol, Vec<Pattern<Subject>>>
Returns the conflict map (identity → conflicting patterns).
Sourcepub fn other(&self) -> &HashMap<Symbol, ((), Pattern<Subject>)>
pub fn other(&self) -> &HashMap<Symbol, ((), Pattern<Subject>)>
Returns the “other” bucket (unclassifiable patterns).
Sourcepub fn nodes(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
pub fn nodes(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
Iterates over all nodes.
Sourcepub fn relationships(
&self,
) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
pub fn relationships( &self, ) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
Iterates over all relationships.
Sourcepub fn walks(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
pub fn walks(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
Iterates over all walks.
Sourcepub fn annotations(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
pub fn annotations(&self) -> impl Iterator<Item = (&Symbol, &Pattern<Subject>)>
Iterates over all annotations.
Sourcepub fn source(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>
pub fn source(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>
Returns the source node of a relationship.
Sourcepub fn target(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>
pub fn target(&self, rel_id: &Symbol) -> Option<&Pattern<Subject>>
Returns the target node of a relationship.
Sourcepub fn neighbors(&self, node_id: &Symbol) -> Vec<&Pattern<Subject>>
pub fn neighbors(&self, node_id: &Symbol) -> Vec<&Pattern<Subject>>
Returns all neighbor nodes of the given node (both directions).
Sourcepub fn degree(&self, node_id: &Symbol) -> usize
pub fn degree(&self, node_id: &Symbol) -> usize
Returns the degree of a node (number of incident relationships, both directions).
Sourcepub fn as_pattern_graph(&self) -> &PatternGraph<(), Subject>
pub fn as_pattern_graph(&self) -> &PatternGraph<(), Subject>
Returns a reference to the inner PatternGraph.
Sourcepub fn into_pattern_graph(self) -> PatternGraph<(), Subject>
pub fn into_pattern_graph(self) -> PatternGraph<(), Subject>
Consumes the StandardGraph and returns the inner PatternGraph.
Sourcepub fn as_query(&self) -> GraphQuery<Subject>
pub fn as_query(&self) -> GraphQuery<Subject>
Creates a GraphQuery from this graph.
Sourcepub fn as_snapshot(&self) -> GraphView<(), Subject>
pub fn as_snapshot(&self) -> GraphView<(), Subject>
Creates a GraphView snapshot from this graph.