Documentation
¶
Overview ¶
Package text implements a state-based Replicated Growable Array (RGA).
Positions are stable mutation tags, not offsets. Offsets are resolved only for a local edit, which makes duplicate and out-of-order deltas safe.
Index ¶
- Variables
- type Delta
- type Position
- type RGA
- func (r *RGA) ApplyDelta(delta Delta) error
- func (r *RGA) ClockState() clock.State
- func (r *RGA) Delete(offset, count int) (Delta, error)
- func (r *RGA) Insert(offset int, value string) (Delta, error)
- func (r *RGA) MarshalBinary() ([]byte, error)
- func (r *RGA) MarshalBinaryWithClockState() ([]byte, clock.State, error)
- func (r *RGA) Merge(other *RGA) error
- func (r *RGA) Positions() []Position
- func (r *RGA) Snapshot(frontier map[string]crdt.Tag) (snapshot.Snapshot, error)
- func (r *RGA) SnapshotCurrentState() (snapshot.Snapshot, error)
- func (r *RGA) State() crdt.StateSnapshot
- func (r *RGA) String() string
- func (r *RGA) UnmarshalBinary(data []byte) error
- func (r *RGA) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilText = errors.New("text: nil RGA") ErrInvalidReplicaID = errors.New("text: invalid replica ID") ErrInvalidText = errors.New("text: invalid UTF-8 text") ErrRange = errors.New("text: range outside visible text") ErrInvalidDelta = errors.New("text: invalid RGA delta") // ErrIncompleteState indicates a state snapshot contains an unresolved // parent reference. Deltas may be partial for out-of-order delivery, but a // recoverable state frame must include the complete parent closure. ErrIncompleteState = errors.New("text: incomplete RGA state") ErrTagConflict = errors.New("text: conflicting node for one tag") )
Functions ¶
This section is empty.
Types ¶
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
Delta is a joinable partial RGA state. Nodes and tombstones are deliberately opaque so a malformed delta cannot be assembled by direct field mutation.
func UnmarshalRGADelta ¶
UnmarshalRGADelta decodes one bounded canonical RGA delta frame.
func UnmarshalRGADeltaWithLimits ¶
func UnmarshalRGADeltaWithLimits(data []byte, limits frame.DecoderLimits) (Delta, error)
func (Delta) MarshalBinary ¶
MarshalBinary returns the canonical framed RGA delta.
type Position ¶
Position is a stable, opaque identifier for one Unicode scalar value. It remains valid after inserts before it and after it has been deleted.
type RGA ¶
type RGA struct {
// contains filtered or unexported fields
}
RGA is a collaborative text CRDT. A tombstone retained for a deleted position wins even if it arrives before the corresponding insertion.
func (*RGA) ApplyDelta ¶
func (*RGA) ClockState ¶
func (*RGA) Delete ¶
Delete marks count visible runes starting at offset as removed. The delta carries only tombstones; replicas that have not received the inserts yet retain those tombstones until the matching nodes arrive.
func (*RGA) Insert ¶
Insert inserts valid UTF-8 text before visible rune offset. It creates one node per Unicode scalar, so offset/count are rune based rather than byte based and can never split UTF-8.
func (*RGA) MarshalBinary ¶
MarshalBinary returns the canonical framed RGA state.
func (*RGA) MarshalBinaryWithClockState ¶
func (*RGA) State ¶
func (r *RGA) State() crdt.StateSnapshot
func (*RGA) UnmarshalBinary ¶
func (*RGA) UnmarshalBinaryWithLimits ¶
func (r *RGA) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error