rope

package
v0.0.0-...-1704659 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIndent = 64

Variables

This section is empty.

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 cadata.Getter) Storage[cadata.ID]

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 cadata.Store) WriteStorage[cadata.ID]

Jump to

Keyboard shortcuts

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