pub struct RewriteRule {
pub pattern: SqliteGraph,
pub replacement: SqliteGraph,
pub interface: Vec<(usize, usize)>,
}Expand description
A rewrite rule for DPO-style graph transformation.
A rewrite rule specifies how to transform a graph by replacing matched pattern subgraphs with replacement subgraphs.
§Interface Nodes
The interface field maps pattern node indices to replacement node
indices. These nodes are preserved during the rewrite and serve as
connection points between the deleted pattern and inserted replacement.
For example, to replace A -> B -> C with A -> D -> C:
- Pattern nodes: [A, B, C] at indices [0, 1, 2]
- Replacement nodes: [A’, D, C’] at indices [0, 1, 2]
- Interface: [(0, 0), (2, 2)] means A and C are preserved
§Example
use sqlitegraph::{algo::RewriteRule, SqliteGraph};
// Replace chain A->B->C with A->D (simplify through B)
let rule = RewriteRule {
pattern: pattern_graph, // A -> B -> C
replacement: replacement_graph, // A' -> D
interface: vec![(0, 0), (2, 0)], // A->A', C->D (merge C into D)
};Fields§
§pattern: SqliteGraphPattern graph to search for in the target graph.
replacement: SqliteGraphReplacement graph to insert in place of matched patterns.
interface: Vec<(usize, usize)>Interface mapping: (pattern_node_index, replacement_node_index).
Interface nodes are preserved during the rewrite and serve as connection points between pattern and replacement. Each pair maps a node index in the pattern to a node index in the replacement.
Implementations§
Source§impl RewriteRule
impl RewriteRule
Sourcepub fn interface_size(&self) -> usize
pub fn interface_size(&self) -> usize
Returns the number of interface nodes.
Auto Trait Implementations§
impl !Freeze for RewriteRule
impl !RefUnwindSafe for RewriteRule
impl !Send for RewriteRule
impl !Sync for RewriteRule
impl Unpin for RewriteRule
impl !UnwindSafe for RewriteRule
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