Documentation ¶
Overview ¶
Package tree is a package for work with Binary trees.
Index ¶
- Constants
- type Tree
- func (t *Tree[V]) Delete(key V)
- func (t *Tree[V]) Exists(key V) bool
- func (t *Tree[V]) GetValue(key V) (any, error)
- func (t *Tree[V]) InOrderTreeWalk(d direction) []V
- func (t *Tree[V]) InOrderTreeWalkWithStack(d direction) []V
- func (t *Tree[V]) Insert(key V, value any)
- func (t *Tree[V]) InsertWithoutRecursion(key V, value any)
- func (t *Tree[V]) Max() V
- func (t *Tree[V]) Min() V
- func (t *Tree[V]) PostOrderSuccessor(key V) (V, error)
- func (t *Tree[V]) PreOrderSuccessor(key V) (V, error)
Constants ¶
const ( // Desc specifies the sort direction to be descending. Desc direction = "desc" // Asc specifies the sort direction to be ascending. Asc direction = "asc" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tree ¶
type Tree[V constraints.Ordered] struct { // contains filtered or unexported fields }
func New ¶
func New[V constraints.Ordered]() *Tree[V]
New is a function for creation empty tree - param should be `ordered type` (`int`, `string`, `float` etc)
func NewWithElement ¶
func NewWithElement[V constraints.Ordered](key V, value any) *Tree[V]
NewWithElement is a function for creation tree with one element - param should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) Delete ¶
func (t *Tree[V]) Delete(key V)
Delete is a function for deleting node in node - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) Exists ¶
Exists is a function for searching element in node. If element exists in tree- return true, else - false - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) GetValue ¶
GetValue is a function for searching element in node and returning value of this element - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) InOrderTreeWalk ¶
func (t *Tree[V]) InOrderTreeWalk(d direction) []V
InOrderTreeWalk is a function for getting ordered array of tree's elements. - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) InOrderTreeWalkWithStack ¶
func (t *Tree[V]) InOrderTreeWalkWithStack(d direction) []V
InOrderTreeWalkWithStack is a function for getting ordered array of tree's elements. - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) Insert ¶
Insert is a function for inserting element into node - param key should be `ordered type` (`int`, `string`, `float` etc.) - param value can be any type
func (*Tree[V]) InsertWithoutRecursion ¶
InsertWithoutRecursion is a function for inserting element into node - param key should be `ordered type` (`int`, `string`, `float` etc.) - param value can be any type
func (*Tree[V]) Max ¶
func (t *Tree[V]) Max() V
Max is a function for searching max element in tree (by key).
func (*Tree[V]) Min ¶
func (t *Tree[V]) Min() V
Min is a function for searching min element in tree (by key).
func (*Tree[V]) PostOrderSuccessor ¶
PostOrderSuccessor is a function for searching postOrder key for income element (if we found it by input key param) - param key should be `ordered type` (`int`, `string`, `float` etc)
func (*Tree[V]) PreOrderSuccessor ¶
PreOrderSuccessor is a function for searching preOrder key for income element (if we found it by input key param) - param key should be `ordered type` (`int`, `string`, `float` etc)