CRDTORMapHandler<K, V> class

CRDT OR-Map

Description

A CRDTORMap is a map data structure that uses the Observed-Removed Map (OR-Map) algorithm to resolve conflicts.

Algorithm

Adding or updating a key-value pair produces a unique tag for the pair. Removing a key consists in tomb-stoning all tags for that key. A key is considered present iff it has at least one tag not tomb-stoned.

More detail about OR-Set (the foundation) can be found in this paper

Example

final doc = CRDTDocument();
final map = CRDTORMapHandler<String, int>(doc, 'map');
map.put('a', 1);
map.put('b', 2);
map.put('a', 10); // Update value for key 'a'
map.remove('b');
print(map.value); // Prints {'a': 10}
Inheritance

Constructors

CRDTORMapHandler(BaseCRDTDocument doc, String _id, {ValueCodec<K>? keyCodec, ValueCodec<V>? valueCodec})
Creates a new CRDT OR-MapHandler with the given document and ID

Properties

cachedState ORMapState<K, V>?
Returns the cached state
no setterinherited
deleteType OperationType
Cached delete type instances for this handler, used in operations.
latefinalinherited
doc BaseCRDTDocument
The document that owns this handler
finalinherited
entries Iterable<MapEntry<K, V>>
Returns the current entries in the map.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
The unique identifier for this consumer
no setteroverride
insertType OperationType
Cached insert type instances for this handler, used in operations.
latefinalinherited
keys Iterable<K>
Returns the current keys in the map.
no setter
operationFactory OperationFactory
The factory function that creates an operation from a payload
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updateType OperationType
Cached update type instances for this handler, used in operations.
latefinalinherited
useIncrementalCacheUpdate bool
Whether to use incremental cache update
getter/setter pairinherited
value Map<K, V>
Returns the current map value computed from changes and snapshot.
no setter
values Iterable<V>
Returns the current values in the map.
no setter

Methods

compound(Operation accumulator, Operation current) Operation?
During transaction consecutive operations can be compounded.
inherited
containsKey(K key) bool
Returns whether the map contains key.
getSnapshotState() Uint8List
Returns the current state for snapshotting as a binary blob.
override
incrementCachedState({required Operation operation, required ORMapState<K, V> state}) ORMapState<K, V>?
When the document receives an operation and a change is applied anyone using CacheableStateProvider is allowed to increment the cached state.
override
invalidateCache() → void
Invalidates the cached state
inherited
lastSnapshot() Uint8List?
Returns the last snapshot bytes for this consumer (the value previously produced by getSnapshotState) or null if no snapshot is available.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
operations() List<Operation>
Returns the Operations required by this consumer to compute its state.
inherited
put(K key, V value) → void
Puts value for key in the map, producing a unique tag.
remove(K key) → void
Removes key from the map by tomb-stoning all observed tags for that key.
snapshotVersionVector() VersionVector?
Returns the version vector of the last snapshot for this consumer.
inherited
toString() String
A string representation of this object.
inherited
updateCachedState(ORMapState<K, V> newState) → void
Updates the cached state
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](K key) → V?
Returns the value for key, or null if not present.