Struct GraphDiff

Source
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 requires Default used when adding a new node to the diff and AddAssign to combine updates.

GraphDiffs 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>

Source

pub fn new() -> GraphDiff<Id, T>

Source

pub fn from_diffs( nodes: NodeDiff<Id, T>, edges: EdgeDiff<Id, W>, ) -> GraphDiff<Id, T, W>

Initialse diff from a NodeDiff and an EdgeDiff

Source

pub fn nodes(&self) -> &NodeDiff<Id, T>

Get a reference to the node diff.

Source

pub fn new_or_updated_nodes(&self) -> &HashMap<Id, T>

Get a reference to the new or updated nodes.

Source

pub fn deleted_nodes(&self) -> &HashSet<Id>

Get a reference to the deleted nodes.

Source

pub fn edges(&self) -> &EdgeDiff<Id, W>

Get a reference to the edge diff.

Source

pub fn new_or_updated_edges(&self) -> &HashMap<Id, HashMap<Id, W>>

Get a reference to the new or updated edges.

Source

pub fn deleted_edges(&self) -> &HashMap<Id, HashSet<Id>>

Get a reference to the deleted edges.

Source

pub fn is_empty(&self) -> bool

Returns true if the diff contains no nodes or edges (new, updated or deleted).

Source

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.

Source

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

Source

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.

Source

pub fn set_node_update(&mut self, node_id: &Id, update: T)

Use with caution: overwrites the node update to whatever you provide.

Source

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.

Source

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.

Source

pub fn add_edges( &mut self, edges: &HashMap<Id, HashMap<Id, W>>, ) -> Result<(), Box<dyn Error>>

Add edges in batch to the dif.

Source

pub fn delete_edges( &mut self, edges: &HashMap<Id, HashSet<Id>>, ) -> Result<(), Box<dyn Error>>

Delete edges in batch from the diff.

Source

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

Source

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.

Source

pub fn clear(&mut self)

Clear the diff of all nodes and edges.

Trait Implementations§

Source§

impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign<EdgeDiff<Id>> for GraphDiff<Id, T>

Source§

fn add_assign(&mut self, edges: EdgeDiff<Id>)

Performs the += operation. Read more
Source§

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>)

Performs the += operation. Read more
Source§

impl<Id: Hash + Eq + Copy, T: Default + AddAssign> AddAssign for GraphDiff<Id, T>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<Id: Clone + Hash + Eq + Copy, T: Clone + Default + AddAssign, W: Clone> Clone for GraphDiff<Id, T, W>

Source§

fn clone(&self) -> GraphDiff<Id, T, W>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Id: Debug + Hash + Eq + Copy, T: Debug + Default + AddAssign, W: Debug> Debug for GraphDiff<Id, T, W>

Source§

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

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

impl<Id: Hash + Eq + Copy, T: Default + AddAssign> Default for GraphDiff<Id, T>

Source§

fn default() -> GraphDiff<Id, T>

Returns the “default value” for a type. Read more
Source§

impl<'de, Id, T, W> Deserialize<'de> for GraphDiff<Id, T, W>
where Id: Deserialize<'de> + Hash + Eq + Copy, T: Deserialize<'de> + Default + AddAssign, W: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Id: PartialEq + Hash + Eq + Copy, T: PartialEq + Default + AddAssign, W: PartialEq> PartialEq for GraphDiff<Id, T, W>

Source§

fn eq(&self, other: &GraphDiff<Id, T, W>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Id, T, W> Serialize for GraphDiff<Id, T, W>
where Id: Serialize + Hash + Eq + Copy, T: Serialize + Default + AddAssign, W: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Id: Hash + Eq + Copy, T: Default + AddAssign, W> StructuralPartialEq for GraphDiff<Id, T, W>

Auto Trait Implementations§

§

impl<Id, T, W> Freeze for GraphDiff<Id, T, W>

§

impl<Id, T, W> RefUnwindSafe for GraphDiff<Id, T, W>

§

impl<Id, T, W> Send for GraphDiff<Id, T, W>
where Id: Send, T: Send, W: Send,

§

impl<Id, T, W> Sync for GraphDiff<Id, T, W>
where Id: Sync, T: Sync, W: Sync,

§

impl<Id, T, W> Unpin for GraphDiff<Id, T, W>
where Id: Unpin, T: Unpin, W: Unpin,

§

impl<Id, T, W> UnwindSafe for GraphDiff<Id, T, W>
where Id: UnwindSafe, T: UnwindSafe, W: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,