persistenttree

package
v0.6.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package persistenttree provides an immutable ordered map with structural sharing: an update returns a new tree sharing every untouched subtree with the old one, so both remain valid and comparable. Delta hashing over shared subtrees lets a caller find what changed between two versions without walking either in full.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change[V any] struct {
	Key           string
	Before        V
	After         V
	BeforePresent bool
	AfterPresent  bool
}

Change describes one key whose presence or immutable value differs.

type Entry

type Entry[V any] struct {
	Key   string
	Value V
}

Entry is an immutable-key input to the bulk tree constructors.

func NewEntry

func NewEntry[V any](key []byte, value V) Entry[V]

NewEntry owns key before returning it as an immutable string.

type Node

type Node[V any] struct {
	// contains filtered or unexported fields
}

Node is an opaque immutable snapshot used for identity and reads.

func (*Node[V]) Get

func (n *Node[V]) Get(key []byte) (V, bool)

Get returns the value stored for key.

func (*Node[V]) Maximum

func (n *Node[V]) Maximum() (key string, value V, ok bool)

Maximum returns the last visible key and value in byte order.

func (*Node[V]) Minimum

func (n *Node[V]) Minimum() (key string, value V, ok bool)

Minimum returns the first visible key and value in byte order.

func (*Node[V]) Walk

func (n *Node[V]) Walk(visit func(string, V) bool) bool

Walk visits visible entries in byte order until visit returns true.

func (*Node[V]) WalkChanges

func (n *Node[V]) WalkChanges(previous *Node[V], equal func(V, V) bool, visit func(Change[V]) bool) bool

WalkChanges skips shared subtrees and visits differences in unspecified order. equal compares immutable values; returning true from visit stops the walk.

func (*Node[V]) WalkPrefix

func (n *Node[V]) WalkPrefix(prefix []byte, visit func(string, V) bool) bool

WalkPrefix visits matching entries in byte order until visit returns true.

type Tree

type Tree[V any] struct {
	// contains filtered or unexported fields
}

Tree is an immutable ordered map.

func New

func New[V any]() *Tree[V]

New returns an empty tree.

func NewFrom

func NewFrom[V any](entries []Entry[V]) (*Tree[V], error)

NewFrom builds a frozen tree without retaining or reordering entries.

func NewFromSorted

func NewFromSorted[V any](entries []Entry[V]) (*Tree[V], error)

NewFromSorted builds a frozen tree from strictly ordered entries.

func (*Tree[V]) Delete

func (t *Tree[V]) Delete(key []byte) (*Tree[V], V, bool)

Delete returns a tree without key and leaves the source tree unchanged.

func (*Tree[V]) Insert

func (t *Tree[V]) Insert(key []byte, value V) (*Tree[V], V, bool)

Insert returns a tree containing key and leaves the source tree unchanged.

func (*Tree[V]) Len

func (t *Tree[V]) Len() int

Len returns the number of visible entries.

func (*Tree[V]) Root

func (t *Tree[V]) Root() *Node[V]

Root returns the opaque immutable snapshot used for reads.

func (*Tree[V]) Txn

func (t *Tree[V]) Txn() *Txn[V]

Txn starts a persistent update.

type Txn

type Txn[V any] struct {
	// contains filtered or unexported fields
}

Txn accumulates persistent updates without mutating its source tree.

func (*Txn[V]) Commit

func (t *Txn[V]) Commit() *Tree[V]

Commit returns the transaction's immutable snapshot.

func (*Txn[V]) Delete

func (t *Txn[V]) Delete(key []byte) (V, bool)

Delete removes key from the transaction.

func (*Txn[V]) Get

func (t *Txn[V]) Get(key []byte) (V, bool)

Get returns the value stored for key in the transaction snapshot.

func (*Txn[V]) Insert

func (t *Txn[V]) Insert(key []byte, value V) (V, bool)

Insert adds or replaces key in the transaction.

func (*Txn[V]) Root

func (t *Txn[V]) Root() *Node[V]

Root returns the transaction's current opaque immutable snapshot.

Jump to

Keyboard shortcuts

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