Skip to main content

GSet

Struct GSet 

Source
pub struct GSet<T: Eq + Hash + Ord> {
    pub elements: Vec<T>,
    pub vclock: VectorClock,
}
Expand description

G-Set: A Grow-only Set CRDT.

A G-Set is a set that only supports element addition. Elements cannot be removed once added. This leads to simple merge semantics (set union).

§Key Properties

  • Grow-only: Elements can be added but never removed.
  • Merge Strategy: Set union.
  • Simplicity: Very low overhead and simple implementation.

§Algebraic Properties

  • Commutativity: Yes.
  • Associativity: Yes.
  • Idempotence: Yes.

§Example

use crdt_data_types::GSet;

let mut set1 = GSet::new();
set1.insert("node_a", "apple".to_string());

let mut set2 = GSet::new();
set2.insert("node_b", "banana".to_string());

set1.merge(&set2);
assert!(set1.contains(&"apple".to_string()));
assert!(set1.contains(&"banana".to_string()));

Fields§

§elements: Vec<T>

Internal storage for set elements.

§vclock: VectorClock

Vector clock for tracking causal history.

Implementations§

Source§

impl<T: Eq + Hash + Ord> GSet<T>

Source

pub fn new() -> Self

Creates a new, empty G-Set.

Source§

impl<T: Clone + Eq + Hash + Ord + Serialize + DeserializeOwned + Send + Sync + 'static> GSet<T>

Source

pub fn insert(&mut self, node_id: &str, element: T)

Adds an element to the set.

Source

pub fn contains(&self, element: &T) -> bool

Returns true if the set contains the element.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Iterator over the elements in the set.

Source

pub fn merge(&mut self, other: &Self)

Merges another G-Set into this one.

Trait Implementations§

Source§

impl<T: Clone + Eq + Hash + Ord> Clone for GSet<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Clone + Eq + Hash + Ord + Serialize + DeserializeOwned + Send + Sync + 'static> Crdt for GSet<T>

Source§

type Reader<'a> = GSetReader<'a, T>

Zero-copy reader type associated with this CRDT.
Source§

fn merge_from_readers(readers: &[Self::Reader<'_>]) -> Result<Self, CrdtError>

Merges N CRDTs from zero-copy readers into a single new CRDT instance. Read more
Source§

fn to_capnp_bytes(&self) -> Vec<u8> ⓘ

Serializes the CRDT to a byte buffer using Cap’n Proto. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the CRDT is in its default (empty) state.
Source§

fn validate(&self) -> Result<(), CrdtError>

Validates the internal consistency of the CRDT state. Read more
Source§

impl<T: Debug + Eq + Hash + Ord> Debug for GSet<T>

Source§

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

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

impl<T: Eq + Hash + Ord> Default for GSet<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for GSet<T>
where T: DeserializeOwned + Eq + Hash + Ord,

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<T: Eq + Eq + Hash + Ord> Eq for GSet<T>

Source§

impl<T: PartialEq + Eq + Hash + Ord> PartialEq for GSet<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> Serialize for GSet<T>
where T: Serialize + Eq + Hash + Ord,

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<T: PartialEq + Eq + Hash + Ord> StructuralPartialEq for GSet<T>

Auto Trait Implementations§

§

impl<T> Freeze for GSet<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for GSet<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for GSet<T>
where Vec<T>: Send,

§

impl<T> Sync for GSet<T>
where Vec<T>: Sync,

§

impl<T> Unpin for GSet<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for GSet<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for GSet<T>
where Vec<T>: 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.