Skip to content

Self balancing binary tree with logarithmic amortized time of CRUD operations

License

Notifications You must be signed in to change notification settings

stepulak/splay-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Splay Tree

Self balancing binary tree with logarithmic amortized time of CRUD operations.

Install this package via: go get github.com/stepulak/splay-tree

Usage example:

package main

import (
	"fmt"

	splaytree "github.com/stepulak/splay-tree"
)

func main() {
	tree := splaytree.Create(func(a, b interface{}) int {
		if a, b := a.(int), b.(int); a < b {
			return -1
		} else if a > b {
			return 1
		}
		return 0
	})

	tree.Add(1, "value 1")
	tree.Add(2, "value 2")
	tree.Add(3, "value 3")

	fmt.Println(tree)
	fmt.Println(tree.Root)
	fmt.Println(tree.Count)

	node := tree.Find(1)
	fmt.Println(node)

	tree.Remove(1)
	tree.TraverseInorder(func(n *splaytree.Node) {
		fmt.Println(n)
	})
}

For more usage info look at source code splaytree.go and splaytree_test.go.

About

Self balancing binary tree with logarithmic amortized time of CRUD operations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages