splay

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 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

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)

func (*Tree) Find

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

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)

type Value

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

DocKey is an interface that represents the value of Node. User can extend this interface to use custom value in Node.

Jump to

Keyboard shortcuts

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