tree

package
v0.0.0-...-943f218 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Btree

type Btree[T Val[T]] struct {
	// contains filtered or unexported fields
}

Btree represents an AVL tree

func New

func New[T Val[T]]() *Btree[T]

New returns a new btree

func (*Btree[T]) Ascend

func (t *Btree[T]) Ascend(iterator NodeIterator[T])

Ascend performs an ascending order traversal of the tree calling the iterator function on each node the iterator will continue as long as the NodeIterator returns true

func (*Btree[T]) Contains

func (t *Btree[T]) Contains(value T) bool

Contains returns true if the tree contains the specified value

func (*Btree[T]) ContainsAll

func (t *Btree[T]) ContainsAll(values []T) bool

ContainsAll returns true if the tree contains all of the values

func (*Btree[T]) ContainsAny

func (t *Btree[T]) ContainsAny(values []T) bool

ContainsAny returns true if the tree contains any of the values

func (*Btree[T]) Debug

func (t *Btree[T]) Debug()

Debug prints out useful debug information about the tree for debugging purposes

func (*Btree[T]) Delete

func (t *Btree[T]) Delete(value T) *Btree[T]

Delete deletes the node from the tree associated with the search value

func (*Btree[T]) DeleteAll

func (t *Btree[T]) DeleteAll(values []T) *Btree[T]

DeleteAll deletes the nodes from the tree associated with the search values

func (*Btree[T]) Descend

func (t *Btree[T]) Descend(iterator NodeIterator[T])

Descend performs a descending order traversal of the tree using the iterator the iterator will continue as long as the NodeIterator returns true

func (*Btree[T]) Empty

func (t *Btree[T]) Empty() bool

Empty returns true if the tree is empty

func (*Btree[T]) Get

func (t *Btree[T]) Get(value T) *T

Get returns the node value associated with the search value

func (*Btree[T]) Head

func (t *Btree[T]) Head() *T

Head returns the first value in the tree

func (*Btree[T]) Init

func (t *Btree[T]) Init() *Btree[T]

Init initializes all values/clears the tree and returns the tree pointer

func (*Btree[T]) Insert

func (t *Btree[T]) Insert(value T) *Btree[T]

Insert inserts a new value into the tree and returns the tree pointer

func (*Btree[T]) InsertAll

func (t *Btree[T]) InsertAll(values []T) *Btree[T]

InsertAll inserts all the values into the tree and returns the tree pointer

func (*Btree[T]) Len

func (t *Btree[T]) Len() int

Len return the number of nodes in the tree

func (*Btree[T]) Match

func (t *Btree[T]) Match(cond T) []T

func (*Btree[T]) NotEmpty

func (t *Btree[T]) NotEmpty() bool

NotEmpty returns true if the tree is not empty

func (*Btree[T]) Pop

func (t *Btree[T]) Pop() *T

Pop deletes the last node from the tree and returns its value

func (*Btree[T]) Pull

func (t *Btree[T]) Pull() *T

Pull deletes the first node from the tree and returns its value

func (*Btree[T]) String

func (t *Btree[T]) String() string

String returns a string representation of the tree values

func (*Btree[T]) Tail

func (t *Btree[T]) Tail() *T

Tail returns the last value in the tree

func (*Btree[T]) Values

func (t *Btree[T]) Values() []T

Values returns a slice of all the values in tree in order

type Node

type Node[T Val[T]] struct {
	Value T
	// contains filtered or unexported fields
}

Node represents a node in the tree with a value, left and right children, and a height/balance of the node.

func (*Node[T]) Debug

func (n *Node[T]) Debug()

Debug prints out useful debug information about the tree node for debugging purposes

func (*Node[T]) Init

func (n *Node[T]) Init() *Node[T]

Init initializes the values of the node or clears the node and returns the node pointer

func (*Node[T]) String

func (n *Node[T]) String() string

String returns a string representing the node

type NodeIterator

type NodeIterator[T Val[T]] func(n *Node[T], i int) bool

NodeIterator expresses the iterator function used for traversals

type Val

type Val[T any] interface {
	Comp(val T) int8   // returns 1 if > val, -1 if < val, 0 if equals to val
	Match(cond T) int8 // returns 1 if > cond, -1 if < cond, 0 if matches cond
}

Jump to

Keyboard shortcuts

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