pub struct GraphDiff<Id: Hash + Eq + Copy, T: Default + AddAssign, W = f32> { /* private fields */ }
Expand description
A differential between two graphs.
Contains a diff for the nodes and edges of a graph. Each diff contains new or updated items and items that are marked for deletion. The diff will always be internally consistent if the safe, public methods are used.
GraphDiff
requires two generic types:
Id
is the type used to index nodes in the graph. It requires standard trait bounds for index types.T
is the type used to represent node property updates. It requiresDefault
used when adding a new node to the diff andAddAssign
to combine updates.
GraphDiff
s support composition with AddAssign
:
use drisk_api::GraphDiff;
let mut diff1: GraphDiff<u32, u32> = GraphDiff::default();
let diff2: GraphDiff<u32, u32> = GraphDiff::default();
// `diff1` will contain all nodes and edges from `diff2`.
// If a node or edge is updated in both, the updates will be combined.
// Updates to the same properties from `diff2` will overwrite updates from `diff1`.
// If a node is deleted in `diff2`, it will be deleted in the combined diff.
diff1 += diff2;
Implementations§
Source§impl<Id: Hash + Eq + Copy, T: Default + AddAssign, W: Copy + PartialEq> GraphDiff<Id, T, W>
impl<Id: Hash + Eq + Copy, T: Default + AddAssign, W: Copy + PartialEq> GraphDiff<Id, T, W>
pub fn new() -> GraphDiff<Id, T>
Sourcepub fn from_diffs(
nodes: NodeDiff<Id, T>,
edges: EdgeDiff<Id, W>,
) -> GraphDiff<Id, T, W>
pub fn from_diffs( nodes: NodeDiff<Id, T>, edges: EdgeDiff<Id, W>, ) -> GraphDiff<Id, T, W>
Initialse diff from a NodeDiff and an EdgeDiff
Sourcepub fn new_or_updated_nodes(&self) -> &HashMap<Id, T>
pub fn new_or_updated_nodes(&self) -> &HashMap<Id, T>
Get a reference to the new or updated nodes.
Sourcepub fn deleted_nodes(&self) -> &HashSet<Id>
pub fn deleted_nodes(&self) -> &HashSet<Id>
Get a reference to the deleted nodes.
Sourcepub fn new_or_updated_edges(&self) -> &HashMap<Id, HashMap<Id, W>>
pub fn new_or_updated_edges(&self) -> &HashMap<Id, HashMap<Id, W>>
Get a reference to the new or updated edges.
Sourcepub fn deleted_edges(&self) -> &HashMap<Id, HashSet<Id>>
pub fn deleted_edges(&self) -> &HashMap<Id, HashSet<Id>>
Get a reference to the deleted edges.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the diff contains no nodes or edges (new, updated or deleted).
Sourcepub fn add_node(&mut self, node_id: &Id)
pub fn add_node(&mut self, node_id: &Id)
Add a new node to the diff. If previously marked as deleted, it will be overwritten.
Sourcepub fn add_or_update_node(&mut self, node_id: &Id, update: T)
pub fn add_or_update_node(&mut self, node_id: &Id, update: T)
Add or update a node in the diff with an update. If previously marked as deleted, it will be overwritten
Sourcepub fn get_or_create_mut_node_update(&mut self, node_id: &Id) -> &mut T
pub fn get_or_create_mut_node_update(&mut self, node_id: &Id) -> &mut T
Get a mutable reference to a node update in the diff. If the node is not present, it will be added with an empty update.
Sourcepub fn set_node_update(&mut self, node_id: &Id, update: T)
pub fn set_node_update(&mut self, node_id: &Id, update: T)
Use with caution: overwrites the node update to whatever you provide.
Sourcepub fn delete_node(&mut self, node_id: Id)
pub fn delete_node(&mut self, node_id: Id)
Add a new node to be deleted to the diff.
If present the node will be removed from new_or_updated
.
It further updates the edge diff to make sure an edge
deletion is recorded for all edges connecting to the node.
Sourcepub fn add_edge(
&mut self,
from: &Id,
to: &Id,
weight: W,
) -> Result<(), Box<dyn Error>>
pub fn add_edge( &mut self, from: &Id, to: &Id, weight: W, ) -> Result<(), Box<dyn Error>>
Add a new edge to the diff. If previously marked as deleted, it will be overwritten If either the from or to nodes are marked as deleted, it will error.
Sourcepub fn add_edges(
&mut self,
edges: &HashMap<Id, HashMap<Id, W>>,
) -> Result<(), Box<dyn Error>>
pub fn add_edges( &mut self, edges: &HashMap<Id, HashMap<Id, W>>, ) -> Result<(), Box<dyn Error>>
Add edges in batch to the dif.
Sourcepub fn delete_edges(
&mut self,
edges: &HashMap<Id, HashSet<Id>>,
) -> Result<(), Box<dyn Error>>
pub fn delete_edges( &mut self, edges: &HashMap<Id, HashSet<Id>>, ) -> Result<(), Box<dyn Error>>
Delete edges in batch from the diff.
Sourcepub unsafe fn add_edges_unchecked(
&mut self,
edges: HashMap<Id, HashMap<Id, W>>,
) -> Result<(), Box<dyn Error>>
pub unsafe fn add_edges_unchecked( &mut self, edges: HashMap<Id, HashMap<Id, W>>, ) -> Result<(), Box<dyn Error>>
§Safety
Does not check that the node IDs are valid (i.e. not marked as deleted).
Sourcepub fn delete_edge(&mut self, from: &Id, to: &Id)
pub fn delete_edge(&mut self, from: &Id, to: &Id)
Add a new edge to be deleted to the diff.
If present, the edge is removed from new_or_updated
.
Trait Implementations§
Source§impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign<EdgeDiff<Id>> for GraphDiff<Id, T>
impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign<EdgeDiff<Id>> for GraphDiff<Id, T>
Source§fn add_assign(&mut self, edges: EdgeDiff<Id>)
fn add_assign(&mut self, edges: EdgeDiff<Id>)
+=
operation. Read moreSource§impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign<NodeDiff<Id, T>> for GraphDiff<Id, T>
impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign<NodeDiff<Id, T>> for GraphDiff<Id, T>
Source§fn add_assign(&mut self, nodes: NodeDiff<Id, T>)
fn add_assign(&mut self, nodes: NodeDiff<Id, T>)
+=
operation. Read moreSource§impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign for GraphDiff<Id, T>
impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign for GraphDiff<Id, T>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read more