CRDTORMapHandler<K, V> class
base
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
-
- Object
- Handler<
ORMapState< K, V> > - CRDTORMapHandler
- Mixed-in types
-
- RebuiltIdentities<
OperationId> - DeltaProvider<
Map< K, V> , MapDelta<K, V> >
- RebuiltIdentities<
- Implementers
Constructors
-
CRDTORMapHandler(BaseCRDTDocument doc, String id, {required String handlerType, ValueCodec<
K> ? keyCodec, ValueCodec<V> ? valueCodec}) - Creates a new CRDT OR-MapHandler with the given document and ID
-
CRDTORMapHandler.fromSpec(BaseCRDTDocument doc, String _id, {required HandlerSpec<
Handler> spec, ValueCodec<K> ? keyCodec, ValueCodec<V> ? valueCodec}) -
Builds this handler from
spec.
Properties
-
cachedState
→ ORMapState<
K, V> ? -
The cached state if it still matches the document's current version,
otherwise
null(forcing the host to recompute).no setterinherited - deleteType → OperationType
-
Cached delete type instance for this handler, used in operations.
no setterinherited
- deltaSeq → int
-
The point the stream has reached, without reading value.
no setterinherited
- doc → BaseCRDTDocument
-
The document that owns this handler
finalinherited
-
entries
→ Iterable<
MapEntry< K, V> > -
Returns the current entries in the map.
no setter
- handlerType → String
-
The name of this kind on the wire: it travels in every operation
envelope and in every HandlerRef, so every peer has to spell it the
same way. Make it a constant of your own.
no setterinherited
- hasDeltaListeners → bool
-
Whether anyone is watching this consumer's deltas.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasRebuiltIdentities → bool
-
Whether anything has been rebuilt, so a caller can skip the work.
no setterinherited
- id → String
-
The unique identifier for
thisconsumerno setteroverride - insertType → OperationType
-
The stamp of a
putis the tag it stores for the written value.latefinal - invertible → bool
-
The stamp of a
putis the tag it wrote, so an undo takes back that one tag and the entry that held the key before wins again on its own.no setteroverride - isDeleted → bool
-
Whether this handler was deleted; see BaseCRDTDocument.deleteHandler.
no setterinherited
-
keys
→ Iterable<
K> -
Returns the current keys in the map.
no setter
- minReadableSnapshotBlobVersion → int
-
The oldest blob version this build still reads.
no setteroverride
- moveType → OperationType
-
Cached move type instance for this handler, used in operations.
no setterinherited
- operationDecoders → OperationDecoders
-
The decoders this handler owns, keyed by OperationEnvelope.kind.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- snapshotBlobVersion → int
-
The version of the blob getSnapshotState writes.
no setteroverride
- stateIsOrderIndependent → bool
-
Whether the state is the same whatever the order causally ready
operations are applied in.
no setteroverride
- updateType → OperationType
-
Cached update type instance for this handler, used in operations.
no setterinherited
- useIncrementalCacheUpdate ↔ bool
-
If
false, every applied operation invalidates the cache instead of invoking incrementCachedState. Hosts that have no cheap incremental path may set this tofalseto skip the hook entirely; the defaulttruelets each operation try the incremental path first.getter/setter pairinherited -
value
→ Map<
K, V> -
The current map.
no setteroverride
-
values
→ Iterable<
V> -
Returns the current values in the map.
no setter
Methods
-
applyDelta(
Map< K, V> base, MapDelta<K, V> delta) → Map<K, V> -
The value
basebecomes oncedeltais applied.override -
chainOf(
OperationId key) → List< OperationId> -
keyfollowed by everything that has stood for it, oldest first.inherited -
clearRebuiltIdentities(
) → void -
Forgets every link.
inherited
-
commitRestores(
Object inverse, List< OperationId> now) → void -
Links what
inverserestores tonow, the identities it really got.inherited -
compound(
Operation accumulator, Operation current) → Operation? -
accumulatorandcurrentfused into one operation, ornullwhen they cannot be.inherited -
containsKey(
K key) → bool -
Returns whether the map contains
key. -
copyValue(
Map< K, V> value) → Map<K, V> -
A copy of
valuethat the caller owns; readSynced goes through it.inherited -
expandChains(
Iterable< OperationId> keys) → List<OperationId> ? -
keysplus everything that has stood for them, oldest first.inherited -
getSnapshotState(
) → Uint8List -
Returns the current state for snapshotting as a binary blob.
override
-
incrementCachedState(
{required Operation operation, required ORMapState< K, V> state, DeltaSink<Object?> ? sink}) → ORMapState<K, V> ? -
Applies
operationtostateand returns the resulting state, ornullto opt out of incremental updates (the cache will be invalidated and recomputed on the next read).override -
invalidateCache(
) → void -
Drops the cached state. The framework calls this automatically when
the consumer's state is no longer guaranteed to match the document
(e.g. external changes imported, snapshot merged, history pruned).
inherited
-
invert(
Operation operation) → List< Operation> -
The operations that undo
operation, against the state as it is beforeoperationis applied. Empty when there is nothing to undo.override -
lastSnapshot(
) → Uint8List? -
Returns the last snapshot bytes for this consumer (the value previously
produced by getSnapshotState) or
nullif no snapshot is available.inherited -
latestOf(
OperationId key) → OperationId -
What stands for
keynow: the last link of its chain, orkeyitself.inherited -
latestOfAll(
Iterable< OperationId> keys) → List<OperationId> ? -
keyseach mapped to what stands for it now.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
noteRebuilt(
OperationId was, OperationId now) → void -
Records that
wasnow stands asnow.inherited -
noteRestores(
Object inverse, List< OperationId> was) → void -
Records that
inverseputswasback, under identities it does not have yet.inherited -
operations(
) → List< Operation> -
Returns the Operations required by this consumer to compute its state.
inherited
-
prepareInverse(
Operation operation) → Operation -
operation, an inverse built by invert, made ready to be written now.override -
put(
K key, V value) → void -
Puts
valueforkeyin the map, under a tag of its own. -
readSnapshotHeader(
Uint8List bytes) → ({int offset, int version}) -
The version at the head of
bytes, and the offset of what follows it.inherited -
readSynced(
) → DeltaSyncPoint< Map< K, V> > -
The current value together with the point of the stream it reflects.
inherited
-
remove(
K key) → void -
Removes
keyfrom the map by tomb-stoning all observed tags for that key. -
snapshotHeader(
) → BytesBuilder -
A builder holding the head of this handler's snapshot blob.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateCachedState(
ORMapState< K, V> newState) → void -
Replaces the cached state with
newState, valid until the document next drops it. Call this after a full recompute.inherited -
watch(
) → Stream< HandlerUpdate< MapDelta< >K, V> > -
The stream of what happened to this handler, opening with
HandlerReset(ResetCause.initial).inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
K key) → V? -
Returns the value for
key, or null if not present.
Static Methods
-
spec<
K, V> (String type, {ValueCodec< K> ? keyCodec, ValueCodec<V> ? valueCodec}) → HandlerSpec<CRDTORMapHandler< K, V> > -
The kind this handler is, under
type.