Raxol.Swarm.CRDT.LWWRegister (Raxol v2.3.0)

View Source

Last-Writer-Wins Register CRDT.

Each value is tagged with a timestamp. On merge, the entry with the highest timestamp wins. Ties are broken by lexicographic node name.

Timestamps use microseconds for ordering precision. Other swarm modules use milliseconds for intervals/thresholds -- do not compare across units.

Summary

Functions

Merges two registers. Keeps the one with the highest timestamp. Ties broken by lexicographic node name comparison.

Creates a new register with the given value.

Updates the register value, advancing the timestamp.

Returns the current value.

Types

t()

@type t() :: %Raxol.Swarm.CRDT.LWWRegister{
  node: node(),
  timestamp: integer(),
  value: term()
}

Functions

merge(a, b)

@spec merge(t(), t()) :: t()

Merges two registers. Keeps the one with the highest timestamp. Ties broken by lexicographic node name comparison.

new(value, node \\ Node.self())

@spec new(term(), node()) :: t()

Creates a new register with the given value.

update(reg, value)

@spec update(t(), term()) :: t()

Updates the register value, advancing the timestamp.

value(lww_register)

@spec value(t()) :: term()

Returns the current value.