pub struct List<T, A: Ord> { /* private fields */ }
Expand description
As described in the module documentation:
A List is a CRDT for storing sequences of data (Strings, ordered lists). It provides an efficient view of the stored sequence, with fast index, insertion and deletion operations.
Implementations§
source§impl<T, A: Ord + Clone> List<T, A>
impl<T, A: Ord + Clone> List<T, A>
sourcepub fn insert_index(&self, ix: usize, val: T, actor: A) -> Op<T, A>
pub fn insert_index(&self, ix: usize, val: T, actor: A) -> Op<T, A>
Generate an op to insert the given element at the given index.
If ix
is greater than the length of the List then it is appended to the end.
sourcepub fn append(&self, c: T, actor: A) -> Op<T, A>
pub fn append(&self, c: T, actor: A) -> Op<T, A>
Create an op to insert an element at the end of the sequence.
sourcepub fn delete_index(&self, ix: usize, actor: A) -> Option<Op<T, A>>
pub fn delete_index(&self, ix: usize, actor: A) -> Option<Op<T, A>>
Create an op to delete the element at the given index.
Returns None if ix
is out of bounds, i.e. ix > self.len()
.
sourcepub fn read<'a, C: FromIterator<&'a T>>(&'a self) -> C
pub fn read<'a, C: FromIterator<&'a T>>(&'a self) -> C
Read the List into a container of your choice
use crdts::{List, CmRDT};
let mut list = List::new();
list.apply(list.append('a', 'A'));
list.apply(list.append('b', 'A'));
list.apply(list.append('c', 'A'));
assert_eq!(list.read::<String>(), "abc");
sourcepub fn read_into<C: FromIterator<T>>(self) -> C
pub fn read_into<C: FromIterator<T>>(self) -> C
Read the List into a container of your choice, consuming it.
use crdts::{List, CmRDT};
let mut list = List::new();
list.apply(list.append(1, 'A'));
list.apply(list.append(2, 'A'));
list.apply(list.append(3, 'A'));
assert_eq!(list.read_into::<Vec<_>>(), vec![1, 2, 3]);
sourcepub fn iter_entries(&self) -> impl Iterator<Item = (&Identifier<OrdDot<A>>, &T)>
pub fn iter_entries(&self) -> impl Iterator<Item = (&Identifier<OrdDot<A>>, &T)>
Get each elements identifier and value from the List.
sourcepub fn position(&self, ix: usize) -> Option<&T>
pub fn position(&self, ix: usize) -> Option<&T>
Get an element at a position in the sequence represented by the List.
sourcepub fn position_entry(&self, id: &Identifier<OrdDot<A>>) -> Option<usize>
pub fn position_entry(&self, id: &Identifier<OrdDot<A>>) -> Option<usize>
Find an identifer by an index.
sourcepub fn get(&self, id: &Identifier<OrdDot<A>>) -> Option<&T>
pub fn get(&self, id: &Identifier<OrdDot<A>>) -> Option<&T>
Finds an element by its Identifier.
sourcepub fn first_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>
pub fn first_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>
Get the first Entry of the sequence represented by the List.
sourcepub fn last_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>
pub fn last_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>
Get the last Entry of the sequence represented by the List.
Trait Implementations§
source§impl<T, A: Ord + Clone + Debug> CmRDT for List<T, A>
impl<T, A: Ord + Clone + Debug> CmRDT for List<T, A>
source§fn apply(&mut self, op: Self::Op)
fn apply(&mut self, op: Self::Op)
Apply an operation to an List instance.
If the operation is an insert and the identifier is already present in the List instance the result is a no-op
If the operation is a delete and the identifier is not present in the List instance the result is a no-op
§type Op = Op<T, A>
type Op = Op<T, A>
§type Validation = DotRange<A>
type Validation = DotRange<A>
validate_op
.