Skip to main content

TwoPTwoPGraph

Struct TwoPTwoPGraph 

Source
pub struct TwoPTwoPGraph<VA, VR, EA, ER, I>{ /* private fields */ }
Expand description

An op-based 2P2P-Graph CRDT.

Maintains four sets corresponding to the paper’s payload:

  • V_A — vertices added
  • V_R — vertices removed
  • E_A — edges added
  • E_R — edges removed

Generic parameters:

  • VA / VR — vertex add / remove operation types
  • EA / ER — edge add / remove operation types
  • I — the shared identifier type

Implementations§

Source§

impl<VA, VR, EA, ER, I> TwoPTwoPGraph<VA, VR, EA, ER, I>

Source

pub fn new() -> Self

Creates an empty graph with all four sets initialized to ∅.

Source

pub fn lookup_vertex(&self, vertex_id: &I) -> bool

Returns true if the vertex is in V_A \ V_R (added and not removed).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn apply_downstream( &mut self, op: UpdateOperation<VA, VR, EA, ER>, ) -> Result<(), TwoPTwoPGraphError<I>>

Applies an operation received from a remote replica (downstream).

Source

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

Source

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

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 references w.
  • Downstream: checks that the corresponding addVertex(w) has been delivered.
Source

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

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.

Source

pub fn vertex_count(&self) -> usize

Returns the number of active vertices (V_A \ V_R).

Source

pub fn edge_count(&self) -> usize

Returns the number of active edges (E_A \ E_R).

Source

pub fn is_empty(&self) -> bool

Returns true if the graph has no active vertices and no active edges.

Source

pub fn vertices(&self) -> impl Iterator<Item = &VA>

Returns an iterator over all active (non-removed) vertex-add operations.

Source

pub fn edges(&self) -> impl Iterator<Item = &EA>

Returns an iterator over all active (non-removed) edge-add operations.

Trait Implementations§

Source§

impl<VA, VR, EA, ER, I> Clone for TwoPTwoPGraph<VA, VR, EA, ER, I>

Source§

fn clone(&self) -> TwoPTwoPGraph<VA, VR, EA, ER, I>

Returns a duplicate 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<VA, VR, EA, ER, I> Debug for TwoPTwoPGraph<VA, VR, EA, ER, I>

Source§

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

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

impl<VA, VR, EA, ER, I> Default for TwoPTwoPGraph<VA, VR, EA, ER, I>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<VA, VR, EA, ER, I> Freeze for TwoPTwoPGraph<VA, VR, EA, ER, I>

§

impl<VA, VR, EA, ER, I> RefUnwindSafe for TwoPTwoPGraph<VA, VR, EA, ER, I>

§

impl<VA, VR, EA, ER, I> Send for TwoPTwoPGraph<VA, VR, EA, ER, I>
where I: Send, VA: Send, VR: Send, EA: Send, ER: Send,

§

impl<VA, VR, EA, ER, I> Sync for TwoPTwoPGraph<VA, VR, EA, ER, I>
where I: Sync, VA: Sync, VR: Sync, EA: Sync, ER: Sync,

§

impl<VA, VR, EA, ER, I> Unpin for TwoPTwoPGraph<VA, VR, EA, ER, I>
where I: Unpin, VA: Unpin, VR: Unpin, EA: Unpin, ER: Unpin,

§

impl<VA, VR, EA, ER, I> UnsafeUnpin for TwoPTwoPGraph<VA, VR, EA, ER, I>

§

impl<VA, VR, EA, ER, I> UnwindSafe for TwoPTwoPGraph<VA, VR, EA, ER, I>
where I: UnwindSafe, VA: UnwindSafe, VR: UnwindSafe, EA: UnwindSafe, ER: 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.