tree

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tree implements an observed-remove rooted tree CRDT.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidReplicaID = errors.New("tree: invalid replica ID")
	ErrNilTree          = errors.New("tree: nil OR-Tree")
	ErrUnknownParent    = errors.New("tree: unknown live parent")
	ErrUnknownNode      = errors.New("tree: unknown live node")
	ErrInvalidDelta     = errors.New("tree: invalid delta")
	ErrIncompleteState  = errors.New("tree: incomplete OR-Tree state")
	ErrNodeConflict     = errors.New("tree: conflicting node identity")
)

Functions

This section is empty.

Types

type Delta

type Delta struct {
	// contains filtered or unexported fields
}

func UnmarshalDelta

func UnmarshalDelta(data []byte) (Delta, error)

func UnmarshalDeltaWithLimits

func UnmarshalDeltaWithLimits(data []byte, limits frame.DecoderLimits) (Delta, error)

func (Delta) MarshalBinary

func (d Delta) MarshalBinary() ([]byte, error)

func (Delta) Merge

func (d Delta) Merge(other Delta) (Delta, error)

type Node

type Node struct {
	ID     NodeID
	Parent NodeID
	Value  []byte
}

Node is an immutable visible tree node. Value is always caller-owned.

type NodeID

type NodeID = crdt.Tag

NodeID is an immutable node-instance identity. The zero ID is the synthetic root.

type ORTree

type ORTree struct {
	// contains filtered or unexported fields
}

ORTree supports add and observed-remove. Moving a node is deliberately not an in-place operation: remove it and add a new instance under the new parent.

func New

func New(replicaID string) (*ORTree, error)

func NewFromClock

func NewFromClock(state clock.State) (*ORTree, error)

func NewFromSnapshot

func NewFromSnapshot(saved snapshot.Snapshot) (*ORTree, error)

func (*ORTree) Add

func (t *ORTree) Add(parent NodeID, value []byte) (NodeID, Delta, error)

func (*ORTree) ApplyDelta

func (t *ORTree) ApplyDelta(delta Delta) error

func (*ORTree) ClockState

func (t *ORTree) ClockState() clock.State

func (*ORTree) MarshalBinary

func (t *ORTree) MarshalBinary() ([]byte, error)

MarshalBinary returns a deterministic, bounded framed OR-Tree state.

func (*ORTree) MarshalBinaryWithClockState

func (t *ORTree) MarshalBinaryWithClockState() ([]byte, clock.State, error)

func (*ORTree) Merge

func (t *ORTree) Merge(other *ORTree) error

func (*ORTree) Nodes

func (t *ORTree) Nodes() []Node

Nodes returns visible, root-reachable nodes in canonical preorder.

func (*ORTree) Remove

func (t *ORTree) Remove(id NodeID) (Delta, error)

func (*ORTree) SnapshotCurrentState

func (t *ORTree) SnapshotCurrentState() (snapshot.Snapshot, error)

func (*ORTree) State

func (t *ORTree) State() crdt.StateSnapshot

func (*ORTree) UnmarshalBinary

func (t *ORTree) UnmarshalBinary(data []byte) error

UnmarshalBinary validates the full state before atomically replacing t. Complete states additionally require every non-root parent to be present.

func (*ORTree) UnmarshalBinaryWithLimits

func (t *ORTree) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL