rope

package module
v0.0.0-...-9bc22b8 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: MIT Imports: 4 Imported by: 1

README

rope

Implementation of the rope data structure in Go. This library can be used by a text editor to improve performance as the user is making ad-hoc changes at arbirary locations in the text.

The implementation is based on work in the rope-experiment repository, where different implentations are tested and benchmarked against each other. This implementation is V2. This implementation may change over time if further enhancements are realized.

Performance differences vs. plain string operations are published in the rope-experiment repository.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader implements io.Reader and io.WriterTo for a Rope rope

func (*Reader) Read

func (read *Reader) Read(p []byte) (n int, err error)

func (*Reader) WriteTo

func (read *Reader) WriteTo(w io.Writer) (int64, error)

WriteTo writes the contents of a Rope to the provided io.Writer

type Rope

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

Rope is a data structure that represents a string. Internally, the string is fractured into smaller strings to facilitate faster editing at the expense of memory usage

func CreateRope

func CreateRope(initial string) *Rope

CreateRope creates a Rope with the given initial value

func (*Rope) Alter

func (r *Rope) Alter(start, end int, value string) error

func (*Rope) ByteLength

func (r *Rope) ByteLength() int

ByteLength returns the number of bytes necessary to store a contiguous representation of the Rope's contents

func (*Rope) Insert

func (r *Rope) Insert(position int, value string) error

Insert adds the provided value to the rope at the given rune-offset position

func (*Rope) Length

func (r *Rope) Length() int

Length returns the number of runes in the Rope

func (*Rope) NewReader

func (r *Rope) NewReader() io.Reader

NewReader returns an `io.Reader` that will allow consuming the rope as a contiguous stream of bytes.

func (*Rope) Rebalance

func (r *Rope) Rebalance()

Rebalance rebalances the b-tree structure

func (*Rope) Remove

func (r *Rope) Remove(start, end int) error

Remove deletes the runes between the start and end point. The start and end are the rune offsets from the start of the rope.

func (*Rope) String

func (r *Rope) String() string

Jump to

Keyboard shortcuts

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