rbtree

package
v0.0.0-...-e9f930d Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const Black = false

Black is a basic Coloring constant equaling false

View Source
const Red = true

Red is a basic Coloring constant equaling true

Variables

This section is empty.

Functions

func PrintInorder

func PrintInorder(n *Node)

PrintInorder prints out all the nodes of a subtree inorder

Types

type Color

type Color bool

Color is a typedef for booleans

type Node

type Node struct {
	Key    string
	Value  interface{}
	Left   *Node
	Right  *Node
	Color  Color
	Parent *Node
}

Node are nodes of base BST

func (Node) Compare

func (n Node) Compare(other Node) int

Compare compares the Keys of the two nodes returns 1 if n's is greater than other's returns 0 if n's Key is equal to other's returns -1 if n's Key is less than other's

func (*Node) Grandparent

func (n *Node) Grandparent() *Node

Grandparent returns the grandparent of the current node

func (*Node) LeftUncle

func (n *Node) LeftUncle() *Node

LeftUncle goes to find the Right uncle and panics if not

func (*Node) RightUncle

func (n *Node) RightUncle() *Node

RightUncle goes to find the Right uncle and panics if not

type RBTree

type RBTree struct {
	Root    *Node
	Compare func(a, b interface{}) int
}

RBTree implementation

func (*RBTree) Delete

func (t *RBTree) Delete(key string)

Delete deletes item with the matching key

func (*RBTree) Get

func (t *RBTree) Get(key string) (interface{}, bool)

Get returns the value found for a given key, using an a boolean indicator if found

func (*RBTree) GetNode

func (t *RBTree) GetNode(key string) (*Node, bool)

GetNode returns the node found for a given key, using a boolean indicator if found

func (RBTree) Height

func (t RBTree) Height() int

Height returns the height of the tree

func (*RBTree) Insert

func (t *RBTree) Insert(key string, val interface{})

Insert inserts with balanced algorithm involved Translated from https://www.cs.auckland.ac.nz/software/AlgAnim/red_black.html

func (RBTree) MarshalBinary

func (t RBTree) MarshalBinary() ([]byte, error)

MarshalBinary marshals the tree into a byte format

func (RBTree) Size

func (t RBTree) Size() int

Size returns the size of the tree

func (RBTree) ToMap

func (t RBTree) ToMap() map[string]interface{}

ToMap converts tree to a map

func (RBTree) ToString

func (t RBTree) ToString() string

ToString prints out a dash spaced version of the tree

Jump to

Keyboard shortcuts

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