binary_tree_ts

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyFunction

type ApplyFunction[T comparable.Comparable] func(pos, depth int, data *T, userData interface{}) bool

type BinaryTree

type BinaryTree[T comparable.Comparable] struct {
	// contains filtered or unexported fields
}

BinaryTree is a generic binary tree

func NewBinaryTree

func NewBinaryTree[T comparable.Comparable]() *BinaryTree[T]

Create a new BinaryTree and return it. Complexity is O(1).

func (*BinaryTree[T]) Delete

func (tt *BinaryTree[T]) Delete(find *T) (found bool)

func (*BinaryTree[T]) DeleteAtHead

func (tt *BinaryTree[T]) DeleteAtHead() (found bool)

func (*BinaryTree[T]) DeleteAtTail

func (tt *BinaryTree[T]) DeleteAtTail() (found bool)

func (*BinaryTree[T]) DeleteMatch

func (tt *BinaryTree[T]) DeleteMatch(find *T, fx func(a, b *T) int) (found bool)

func (*BinaryTree[T]) Depth

func (tt *BinaryTree[T]) Depth() (d int)

func (*BinaryTree[T]) Dump

func (tt *BinaryTree[T]) Dump(fo io.Writer)

Dump will print out the tree to the file `fo`.

func (*BinaryTree[T]) FindMax

func (tt *BinaryTree[T]) FindMax() (item *T)

func (*BinaryTree[T]) FindMin

func (tt *BinaryTree[T]) FindMin() (item *T)

func (*BinaryTree[T]) Front

func (tt *BinaryTree[T]) Front() (rv *BinaryTreeIter[T])

Front will start at the inorder traversal beginning of the tree for iteration over tree.

func (*BinaryTree[T]) Index

func (tt *BinaryTree[T]) Index(pos int) (item *T)

func (*BinaryTree[T]) Insert

func (tt *BinaryTree[T]) Insert(item *T) (vv bool)

Insert will add a new item to the tree. If it is a duplicate of an exiting item the new item will replace the existing one.

func (*BinaryTree[T]) IsEmpty

func (tt *BinaryTree[T]) IsEmpty() bool

IsEmpty will return true if the binary-tree is empty

func (*BinaryTree[T]) Len

func (tt *BinaryTree[T]) Len() int

Length returns the number of elements in the list.

func (*BinaryTree[T]) Length

func (tt *BinaryTree[T]) Length() int

func (*BinaryTree[T]) Reverse

func (tt *BinaryTree[T]) Reverse()

func (*BinaryTree[T]) Search

func (tt *BinaryTree[T]) Search(find *T) (item *T)

Search will walk the tree looking for `find` and retrn the found item if it is in the tree. If it is not found then `nil` will be returned.

func (*BinaryTree[T]) Truncate

func (tt *BinaryTree[T]) Truncate()

Truncate removes all data from the tree.

func (*BinaryTree[T]) WalkFunc

func (tt *BinaryTree[T]) WalkFunc(Fx func(a *T))

func (*BinaryTree[T]) WalkInOrder

func (tt *BinaryTree[T]) WalkInOrder(fx ApplyFunction[T], userData interface{})

func (*BinaryTree[T]) WalkPostOrder

func (tt *BinaryTree[T]) WalkPostOrder(fx ApplyFunction[T], userData interface{})

func (*BinaryTree[T]) WalkPreOrder

func (tt *BinaryTree[T]) WalkPreOrder(fx ApplyFunction[T], userData interface{})

type BinaryTreeElement

type BinaryTreeElement[T comparable.Comparable] struct {
	// contains filtered or unexported fields
}

func (*BinaryTreeElement[T]) GetData

func (ee *BinaryTreeElement[T]) GetData() *T

Complexity is O(1).

func (*BinaryTreeElement[T]) SetData

func (ee *BinaryTreeElement[T]) SetData(x *T)

Complexity is O(1).

type BinaryTreeIter

type BinaryTreeIter[T comparable.Comparable] struct {
	// contains filtered or unexported fields
}

An iteration type that allows a for loop to walk the tree inorder.

This is more moemory effecient than the Walk* functions becasue it manages the stack interally. It is a tiny bit faster than the Walk* functions.

The main benefit is that it can be used to make cleaner code.

Jump to

Keyboard shortcuts

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