splay

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

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

Node is a node of Tree.

func NewNode

func NewNode(value Value) *Node

NewNode creates a new instance of Node.

func (*Node) Value

func (n *Node) Value() Value

Value returns the value of this Node.

type Tree

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

Tree is weighted binary search tree which is based on Splay tree. original paper on Splay Trees:

func NewTree

func NewTree(root *Node) *Tree

NewTree creates a new instance of Tree.

func (*Tree) AnnotatedString

func (t *Tree) AnnotatedString() string

AnnotatedString returns a string containing the meta data of the Node for debugging purpose.

func (*Tree) Delete

func (t *Tree) Delete(node *Node)

Delete deletes the given node from this Tree.

func (*Tree) Find

func (t *Tree) Find(index int) (*Node, int)

Find returns the Node and offset of the given index.

func (*Tree) IndexOf

func (t *Tree) IndexOf(node *Node) int

IndexOf Find the index of the given node.

func (*Tree) Insert

func (t *Tree) Insert(node *Node) *Node

Insert inserts the node at the last.

func (*Tree) InsertAfter

func (t *Tree) InsertAfter(prev *Node, node *Node) *Node

InsertAfter inserts the node after the given previous node.

func (*Tree) Splay

func (t *Tree) Splay(node *Node)

Splay moves the given node to the root.

func (*Tree) String

func (t *Tree) String() string

String returns a string containing node values.

func (*Tree) UpdateSubtree

func (t *Tree) UpdateSubtree(node *Node)

UpdateSubtree recalculates the weight of this node with the value and children.

type Value

type Value interface {
	Len() int
	String() string
}

Value represents the data stored in the nodes of Tree.

Jump to

Keyboard shortcuts

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