Struct garage_table::crdt::Map

source ·
pub struct Map<K, V> { /* private fields */ }
Expand description

Simple CRDT Map

This types defines a CRDT for a map from keys to values. Values are CRDT types which can have their own updating logic.

Internally, the map is stored as a vector of keys and values, sorted by ascending key order. This is why the key type K must implement Ord (and also to ensure a unique serialization, such that two values can be compared for equality based on their hashes). As a consequence, insertions take O(n) time. This means that Map should be used for reasonably small maps. However, note that even if we were using a more efficient data structure such as a BTreeMap, the serialization cost O(n) would still have to be paid at each modification, so we are actually not losing anything here.

Implementations§

source§

impl<K, V> Map<K, V>
where K: Clone + Ord, V: Clone + Crdt,

source

pub fn new() -> Map<K, V>

Create a new empty map CRDT

source

pub fn put_mutator(k: K, v: V) -> Map<K, V>

Returns a map that contains a single mapping from the specified key to the specified value. This can be used to build a delta-mutator: when merged with another map, the value will be added or CRDT-merged if a previous value already exists.

source

pub fn put(&mut self, k: K, v: V)

Add a value to the map

source

pub fn clear(&mut self)

Removes all values from the map

source

pub fn get(&self, k: &K) -> Option<&V>

Get a reference to the value assigned to a key

source

pub fn items(&self) -> &[(K, V)]

Gets a reference to all of the items, as a slice. Usefull to iterate on all map values.

source

pub fn len(&self) -> usize

Returns the number of items in the map

source

pub fn is_empty(&self) -> bool

Returns true if the map is empty

Trait Implementations§

source§

impl<K, V> Clone for Map<K, V>
where K: Clone, V: Clone,

source§

fn clone(&self) -> Map<K, V>

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<K, V> Crdt for Map<K, V>
where K: Clone + Ord, V: Clone + Crdt,

source§

fn merge(&mut self, other: &Map<K, V>)

Merge the two datastructures according to the CRDT rules. self is modified to contain the merged CRDT value. other is not modified. Read more
source§

impl<K, V> Debug for Map<K, V>
where K: Debug, V: Debug,

source§

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

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

impl<K, V> Default for Map<K, V>
where K: Clone + Ord, V: Clone + Crdt,

source§

fn default() -> Map<K, V>

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

impl<'de, K, V> Deserialize<'de> for Map<K, V>
where K: Deserialize<'de>, V: Deserialize<'de>,

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Map<K, V>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl<K, V> FromIterator<(K, V)> for Map<K, V>
where K: Clone + Ord, V: Clone + Crdt,

A crdt map can be created from an iterator of key-value pairs. Note that all keys in the iterator must be distinct: this function will throw a panic if it is not the case.

source§

fn from_iter<T>(iter: T) -> Map<K, V>
where T: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl<K, V> PartialEq for Map<K, V>
where K: PartialEq, V: PartialEq,

source§

fn eq(&self, other: &Map<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Serialize for Map<K, V>
where K: Serialize, V: Serialize,

source§

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

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

impl<K, V> Eq for Map<K, V>
where K: Eq, V: Eq,

source§

impl<K, V> StructuralPartialEq for Map<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>

§

impl<K, V> RefUnwindSafe for Map<K, V>

§

impl<K, V> Send for Map<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Map<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Map<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Map<K, V>
where K: UnwindSafe, V: 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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