pub struct TwoPTwoPGraph<VA, VR, EA, ER, I>where
VA: Clone + TwoPTwoPAddVertex<I>,
VR: Clone + TwoPTwoPRemoveVertex<I>,
EA: Clone + TwoPTwoPAddEdge<I>,
ER: Clone + TwoPTwoPRemoveEdge<I>,
I: Eq + Hash + Debug + Clone,{ /* private fields */ }Expand description
An op-based 2P2P-Graph CRDT.
Maintains four sets corresponding to the paper’s payload:
V_A— vertices addedV_R— vertices removedE_A— edges addedE_R— edges removed
Generic parameters:
VA/VR— vertex add / remove operation typesEA/ER— edge add / remove operation typesI— the shared identifier type
Implementations§
Source§impl<VA, VR, EA, ER, I> TwoPTwoPGraph<VA, VR, EA, ER, I>where
VA: Clone + TwoPTwoPAddVertex<I>,
VR: Clone + TwoPTwoPRemoveVertex<I>,
EA: Clone + TwoPTwoPAddEdge<I>,
ER: Clone + TwoPTwoPRemoveEdge<I>,
I: Eq + Hash + Debug + Clone,
impl<VA, VR, EA, ER, I> TwoPTwoPGraph<VA, VR, EA, ER, I>where
VA: Clone + TwoPTwoPAddVertex<I>,
VR: Clone + TwoPTwoPRemoveVertex<I>,
EA: Clone + TwoPTwoPAddEdge<I>,
ER: Clone + TwoPTwoPRemoveEdge<I>,
I: Eq + Hash + Debug + Clone,
Sourcepub fn lookup_vertex(&self, vertex_id: &I) -> bool
pub fn lookup_vertex(&self, vertex_id: &I) -> bool
Returns true if the vertex is in V_A \ V_R (added and not removed).
Sourcepub fn get_edge_added_from_remove_edge(&self, remove_edge: &ER) -> Option<&EA>
pub fn get_edge_added_from_remove_edge(&self, remove_edge: &ER) -> Option<&EA>
Returns the edge-add operation referenced by a given edge-remove operation, if present.
Sourcepub fn lookup_from_remove_edge(&self, remove_edge: &ER) -> bool
pub fn lookup_from_remove_edge(&self, remove_edge: &ER) -> bool
Returns true if the edge referenced by remove_edge exists in E_A \ E_R
and both of its endpoint vertices are currently in V_A \ V_R.
Sourcepub fn update_operation(
&mut self,
update_operation: UpdateOperation<VA, VR, EA, ER>,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn update_operation( &mut self, update_operation: UpdateOperation<VA, VR, EA, ER>, ) -> Result<(), TwoPTwoPGraphError<I>>
Convenience method that calls prepare and discards the returned operation.
Sourcepub fn prepare(
&mut self,
op: UpdateOperation<VA, VR, EA, ER>,
) -> Result<UpdateOperation<VA, VR, EA, ER>, TwoPTwoPGraphError<I>>
pub fn prepare( &mut self, op: UpdateOperation<VA, VR, EA, ER>, ) -> Result<UpdateOperation<VA, VR, EA, ER>, TwoPTwoPGraphError<I>>
Executes atSource precondition checks and applies the downstream effect locally. Returns the operation to broadcast to other replicas.
Sourcepub fn apply_downstream(
&mut self,
op: UpdateOperation<VA, VR, EA, ER>,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn apply_downstream( &mut self, op: UpdateOperation<VA, VR, EA, ER>, ) -> Result<(), TwoPTwoPGraphError<I>>
Applies an operation received from a remote replica (downstream).
Sourcepub fn add_vertex(
&mut self,
vertex: VA,
_update_type: UpdateType,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn add_vertex( &mut self, vertex: VA, _update_type: UpdateType, ) -> Result<(), TwoPTwoPGraphError<I>>
Adds a vertex to V_A. Fails if a vertex with the same ID already exists.
Both AtSource and Downstream behave identically (no preconditions per the paper).
Sourcepub fn add_edge(
&mut self,
edge: EA,
update_type: UpdateType,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn add_edge( &mut self, edge: EA, update_type: UpdateType, ) -> Result<(), TwoPTwoPGraphError<I>>
Adds an edge to E_A.
- AtSource: checks
lookup(source) ∧ lookup(target). - Downstream: skips vertex existence checks (per the paper).
Sourcepub fn remove_vertex(
&mut self,
vertex: VR,
update_type: UpdateType,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn remove_vertex( &mut self, vertex: VR, update_type: UpdateType, ) -> Result<(), TwoPTwoPGraphError<I>>
Adds a vertex-remove to V_R.
- AtSource: checks
lookup(w)and that no active edge referencesw. - Downstream: checks that the corresponding
addVertex(w)has been delivered.
Sourcepub fn remove_edge(
&mut self,
remove_edge: ER,
update_type: UpdateType,
) -> Result<(), TwoPTwoPGraphError<I>>
pub fn remove_edge( &mut self, remove_edge: ER, update_type: UpdateType, ) -> Result<(), TwoPTwoPGraphError<I>>
Adds an edge-remove to E_R.
- AtSource: checks
lookup((u,v)). - Downstream: checks that the corresponding
addEdge(u,v)has been delivered.
Sourcepub fn generate_petgraph(&self) -> DiGraph<VA, EA>
pub fn generate_petgraph(&self) -> DiGraph<VA, EA>
Converts the current CRDT state into a petgraph::graph::DiGraph.
Only vertices in V_A \ V_R and edges in E_A \ E_R (whose endpoints
are present) are included in the resulting directed graph.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Returns the number of active vertices (V_A \ V_R).
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of active edges (E_A \ E_R).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the graph has no active vertices and no active edges.
Trait Implementations§
Source§impl<VA, VR, EA, ER, I> Clone for TwoPTwoPGraph<VA, VR, EA, ER, I>where
VA: Clone + TwoPTwoPAddVertex<I> + Clone,
VR: Clone + TwoPTwoPRemoveVertex<I> + Clone,
EA: Clone + TwoPTwoPAddEdge<I> + Clone,
ER: Clone + TwoPTwoPRemoveEdge<I> + Clone,
I: Eq + Hash + Debug + Clone + Clone,
impl<VA, VR, EA, ER, I> Clone for TwoPTwoPGraph<VA, VR, EA, ER, I>where
VA: Clone + TwoPTwoPAddVertex<I> + Clone,
VR: Clone + TwoPTwoPRemoveVertex<I> + Clone,
EA: Clone + TwoPTwoPAddEdge<I> + Clone,
ER: Clone + TwoPTwoPRemoveEdge<I> + Clone,
I: Eq + Hash + Debug + Clone + Clone,
Source§fn clone(&self) -> TwoPTwoPGraph<VA, VR, EA, ER, I>
fn clone(&self) -> TwoPTwoPGraph<VA, VR, EA, ER, I>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more