linerope

package
v0.0.0-...-7534ea8 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	SplitLen:       4096,
	JoinLen:        2048,
	RebalanceRatio: 1.2,
	LineSep:        []byte{'\n'},
}

Functions

This section is empty.

Types

type Node

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

A Node in the rope structure. If the kind is tLeaf, only the value and length are valid, and if the kind is tNode, only length, left, right are valid.

func Join

func Join(a, b *Node, more ...*Node) *Node

Join merges all the given ropes together into one rope.

func New

func New(b []byte) *Node

New returns a new rope node from the given byte slice. The underlying data is not copied so the user should ensure that it is okay to insert and delete from the input slice.

func NewWithOpts

func NewWithOpts(b []byte, opts Options) *Node

NewWithOpts constructs a rope with the given options.

func (*Node) At

func (n *Node) At(pos int) byte

At returns the element at the given position.

func (*Node) Each

func (n *Node) Each(fn func(n *Node))

Each applies the given function to every node in the rope.

func (*Node) EachLeaf

func (n *Node) EachLeaf(fn func(n *Node) bool) bool

EachLeaf applies the given function to every leaf node in order.

func (*Node) Insert

func (n *Node) Insert(pos int, value []byte)

Insert inserts the given value at pos.

func (*Node) LLen

func (n *Node) LLen() (lines, cols int)

LLen returns the line/col location one byte beyond the last position in the file.

func (*Node) Len

func (n *Node) Len() int

Len returns the number of elements stored in the rope.

func (*Node) LineColAt

func (n *Node) LineColAt(pos int) (line, col int)

LineColAt returns the line/col position of an absolute character offset.

func (*Node) NumLines

func (n *Node) NumLines() int

func (*Node) OffsetAt

func (n *Node) OffsetAt(line, col int) int

OffsetAt returns the absolute character offset of a line/col position.

func (*Node) ReadAt

func (n *Node) ReadAt(p []byte, off int64) (nread int, err error)

ReadAt implements the io.ReaderAt interface.

func (*Node) Rebalance

func (n *Node) Rebalance()

Rebalance finds unbalanced nodes and rebuilds them.

func (*Node) Rebuild

func (n *Node) Rebuild()

Rebuild rebuilds the entire rope structure, resulting in a balanced tree.

func (*Node) Remove

func (n *Node) Remove(start, end int)

Remove deletes the range [start:end) (exclusive bound) from the rope.

func (*Node) SliceLC

func (n *Node) SliceLC(startl, startc, endl, endc int) []byte

SliceLC is the same as Slice but uses line/col positions for start and end.

func (*Node) SplitAt

func (n *Node) SplitAt(i int) (*Node, *Node)

SplitAt splits the node at the given index and returns two new ropes corresponding to the left and right portions of the split.

func (*Node) Value

func (n *Node) Value() []byte

Value returns the elements of this node concatenated into a slice. May return the underlying slice without copying, so do not modify the returned slice.

func (*Node) WriteTo

func (n *Node) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

type Options

type Options struct {
	// SplitLen is the threshold above which slices will be split into separate
	// nodes.
	SplitLen int
	// JoinLen is the threshold below which nodes will be merged into slices.
	JoinLen int
	// RebalanceRatio is the threshold used to trigger a rebuild during a
	// rebalance operation.
	RebalanceRatio float64
	// LineSep is the newline byte sequence (usually '\n' or '\r\n').
	LineSep []byte
}

Jump to

Keyboard shortcuts

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