bst

package
v0.0.0-...-038bce5 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 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 Tree

type Tree[K constraints.Ordered, V any] struct {
	// contains filtered or unexported fields
}

Tree represents a binary search tree (BST) structure. This structure facilitates the traversal of elements in order.

func New

func New[K constraints.Ordered, V any]() *Tree[K, V]

New returns a new Tree.

func (*Tree[K, V]) Find

func (t *Tree[K, V]) Find(k K) (V, bool)

Find finds an element from the BST. The performance of the find operation highly depends on the order of insertion, as a BST isn't a balanced structure. In cases where the element is not present in the tree, a zero value with a `false` boolean will be returned.

func (*Tree[K, V]) Insert

func (t *Tree[K, V]) Insert(key K, val V)

Insert adds an element to the BST.

func (*Tree[K, V]) Remove

func (t *Tree[K, V]) Remove(k K) (V, bool)

Remove deletes an element from the BST. The performance of the delete operation highly depends on the order of insertion, as a BST isn't a balanced structure. In cases where the element is not present in the tree, a zero value with a `false` boolean will be returned. If the object is found, it is removed from the structure and returned.

func (*Tree[K, V]) Walk

func (t *Tree[K, V]) Walk(fn func(K, V))

Jump to

Keyboard shortcuts

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