avltree

package
v0.0.0-...-8992419 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package avltree provides an universal AVL tree

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparable

type Comparable func(c1 interface{}, c2 interface{}) bool

Comparable is an interface used to pass compare functions to this avltree

type EachFunc

type EachFunc func(node *TreeNode, vals ...interface{})

EachFunc is an interface used to pass a function to the each() method

type Tree

type Tree struct {
	Count int
	// contains filtered or unexported fields
}

Tree represents a tree

func Intersection

func Intersection(candidates []*Tree) (res *Tree)

Intersection builds a tree of common elements of all trees in `candidates`

func New

func New() *Tree

New simply returns a new (empty) tree

func (*Tree) Dump

func (t *Tree) Dump() (res []interface{})

Dump dumps tree `t` into a slice and returns it

func (*Tree) Each

func (t *Tree) Each(f EachFunc, vals ...interface{})

Each can be used to traverse tree `t` and call function f with params vals... for each node in the tree

func (*Tree) Exists

func (t *Tree) Exists(key interface{}) bool

Exists checks if a node with key `key` exists in tree `t`

func (*Tree) Insert

func (t *Tree) Insert(key interface{}, value interface{}, issmaller Comparable) (new *TreeNode, err error)

Insert inserts an element to tree with root `t`

func (*Tree) Intersection

func (t *Tree) Intersection(x *Tree) (res *Tree)

Intersection finds common elements in trees `t` and `x` and returns them in a new tree

func (*Tree) TopN

func (t *Tree) TopN(n int) (res []interface{})

TopN finds the the `n` biggest elements in tree `t` and returns them in a slice

type TreeNode

type TreeNode struct {
	Values []interface{}
	// contains filtered or unexported fields
}

TreeNode represents a node in a tree

func (*TreeNode) Each

func (root *TreeNode) Each(f EachFunc, vals ...interface{})

Each recursively traverses tree `tree` and calls functions f with params vals... for each node in the tree

Jump to

Keyboard shortcuts

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