gotrope

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: GPL-3.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gotrope implements a Rope data structure.

Index

Constants

View Source
const MaxIndent = 64

Variables

View Source
var EOS = streams.EOS

EOS is the End-Of-Stream

Functions

func Copy

func Copy[Ref any](ctx context.Context, b *Builder[Ref], it *Iterator[Ref]) error

func PathCompare

func PathCompare(a, b Path) int

func Walk

func Walk[Ref any](ctx context.Context, s Storage[Ref], root Root[Ref], w Walker[Ref]) error

Types

type Builder

type Builder[Ref any] struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder[Ref any](s WriteStorage[Ref], meanSize, maxSize int, seed *[16]byte) *Builder[Ref]

func (*Builder[R]) Append

func (b *Builder[R]) Append(ctx context.Context, indent uint8, data []byte) error

func (*Builder[Ref]) Finish

func (b *Builder[Ref]) Finish(ctx context.Context) (*Root[Ref], error)

type Entry

type Entry struct {
	Path  Path
	Value []byte
}

Entry is a single entry in the Rope

func ListEntries

func ListEntries[Ref any](ctx context.Context, s Storage[Ref], offset Weight, ref Ref) (ret []Entry, _ error)

ListEntries lists the entries in the node referenced by idx.

type Index

type Index[Ref any] struct {
	Ref Ref
	// Adding Weight to an offset is the same as adding everything reachable from Ref to the offset.
	Weight Weight
}

Index is a reference to a node and the sum of the change in path that would occur from concatenation the index.

func ListIndexes

func ListIndexes[Ref any](ctx context.Context, s Storage[Ref], ref Ref) (ret []Index[Ref], _ error)

ListIndexes lists the indexes in the node referenced by idx.

type IndexCallback

type IndexCallback[Ref any] func(context.Context, Index[Ref]) error

type Iterator

type Iterator[Ref any] struct {
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator[Ref any](s Storage[Ref], root Root[Ref], span Span) *Iterator[Ref]

func (*Iterator[Ref]) Next

func (it *Iterator[Ref]) Next(ctx context.Context, ent *Entry) error

func (*Iterator[Ref]) Peek

func (it *Iterator[Ref]) Peek(ctx context.Context, ent *Entry) error

func (*Iterator[Ref]) Seek

func (it *Iterator[Ref]) Seek(ctx context.Context, gteq Path) error

type Path

type Path []uint64

func (*Path) Add

func (p *Path) Add(left, right Weight)

type Root

type Root[Ref any] struct {
	Ref    Ref    `json:"ref"`
	Depth  uint8  `json:"depth"`
	Weight Weight `json:"weight"`
}

Root is a root of a Rope

type Span

type Span = state.Span[Path]

func PointSpan

func PointSpan(x Path) Span

func TotalSpan

func TotalSpan() Span

type Storage

type Storage[R any] interface {
	Get(ctx context.Context, ref R, buf []byte) (int, error)
	MaxSize() int
	MarshalRef(R) []byte
	ParseRef([]byte) (R, error)
}

func NewStorage

func NewStorage(s stores.RO) Storage[blobcache.CID]

type StreamEntry

type StreamEntry struct {
	Value  []byte
	Weight Weight
}

type StreamReader

type StreamReader[Ref any] struct {
	// contains filtered or unexported fields
}

func NewStreamReader

func NewStreamReader[Ref any](s Storage[Ref], getNext func(context.Context) (*Ref, error)) *StreamReader[Ref]

func (*StreamReader[Ref]) Buffered

func (sr *StreamReader[Ref]) Buffered() int

func (*StreamReader[Ref]) Next

func (sr *StreamReader[Ref]) Next(ctx context.Context, ent *StreamEntry) error

func (*StreamReader[Ref]) Peek

func (sr *StreamReader[Ref]) Peek(ctx context.Context, ent *StreamEntry) error

type StreamWriter

type StreamWriter[Ref any] struct {
	// contains filtered or unexported fields
}

func NewStreamWriter

func NewStreamWriter[Ref any](s WriteStorage[Ref], meanSize, maxSize int, seed *[16]byte, cb IndexCallback[Ref]) *StreamWriter[Ref]

func (*StreamWriter[Ref]) Append

func (sw *StreamWriter[Ref]) Append(ctx context.Context, se StreamEntry) error

func (*StreamWriter[Ref]) Buffered

func (sw *StreamWriter[Ref]) Buffered() int

func (*StreamWriter[Ref]) Flush

func (sw *StreamWriter[Ref]) Flush(ctx context.Context) error

type Walker

type Walker[Ref any] struct {
	// If Before returns false, the descendents are skipped.
	Before func(Ref) bool
	// ForEach is called for each entry
	ForEach func(Entry) error
	// After is called on a node after it's descendants have been completed.
	After func(Ref) error
}

type Weight

type Weight []uint64

func (*Weight) Add

func (w *Weight) Add(left, right Weight)

Add sets w to be equal to left + right left or right may be w. Add is not commutative

func (Weight) Clone

func (w Weight) Clone() Weight

func (*Weight) Set

func (w *Weight) Set(x Weight)

type WriteStorage

type WriteStorage[R any] interface {
	Storage[R]
	Post(ctx context.Context, data []byte) (R, error)
}

func NewWriteStorage

func NewWriteStorage(s stores.RW) WriteStorage[blobcache.CID]

Jump to

Keyboard shortcuts

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