GCounter class

CRDT types for conflict-free distributed data. Supports counters, sets, maps, and registers with automatic conflict resolution. G-Counter (Grow-only counter) - can only increment. Each node maintains its own count. The total value is the sum of all node counts. Merge takes the maximum per node.

Constructors

GCounter(String nodeId)
Create a G-Counter for the given nodeId, starting at 0.

Properties

hashCode int
The hash code for this object.
no setterinherited
nodeId String
The identifier for this node.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value int
The current total value (sum of all node counts).
no setter

Methods

countFor(String nodeId) int
Get the count for a specific node.
increment([int amount = 1]) → void
Increment this node's counter by amount (default 1).
merge(GCounter other) GCounter
Merge with another G-Counter by taking the max per node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Serialize to a JSON-serializable map.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

fromJson(Map<String, dynamic> json) GCounter
Deserialize from a JSON map.