Documentation ¶
Index ¶
- Variables
- type Node
- func (n *Node) At(pos int) byte
- func (n *Node) Each(fn func(n *Node))
- func (n *Node) EachLeaf(fn func(n *Node) bool) bool
- func (n *Node) Insert(pos int, value []byte)
- func (n *Node) LLen() (lines, cols int)
- func (n *Node) Len() int
- func (n *Node) LineColAt(pos int) (line, col int)
- func (n *Node) NumLines() int
- func (n *Node) OffsetAt(line, col int) int
- func (n *Node) ReadAt(p []byte, off int64) (nread int, err error)
- func (n *Node) Rebalance()
- func (n *Node) Rebuild()
- func (n *Node) Remove(start, end int)
- func (n *Node) SliceLC(startl, startc, endl, endc int) []byte
- func (n *Node) SplitAt(i int) (*Node, *Node)
- func (n *Node) Value() []byte
- func (n *Node) WriteTo(w io.Writer) (int64, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
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 New ¶
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 ¶
NewWithOpts constructs a rope with the given options.
func (*Node) LLen ¶
LLen returns the line/col location one byte beyond the last position in the file.
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) SplitAt ¶
SplitAt splits the node at the given index and returns two new ropes corresponding to the left and right portions of the split.
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 }