https://github.com/hslam/avl
Package avl implements an AVL tree.
https://github.com/hslam/avl
avl avl-tree go golang tree
Last synced: 10 months ago
JSON representation
Package avl implements an AVL tree.
- Host: GitHub
- URL: https://github.com/hslam/avl
- Owner: hslam
- License: mit
- Created: 2020-10-26T15:34:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-06T04:55:33.000Z (over 4 years ago)
- Last Synced: 2024-06-20T11:57:01.049Z (over 1 year ago)
- Topics: avl, avl-tree, go, golang, tree
- Language: Go
- Homepage:
- Size: 128 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# avl
[](https://pkg.go.dev/github.com/hslam/avl)
[](https://github.com/hslam/avl/actions)
[](https://codecov.io/gh/hslam/avl)
[](https://goreportcard.com/report/github.com/hslam/avl)
[](https://github.com/hslam/avl/blob/master/LICENSE)
Package avl implements an AVL tree.
## [Benchmark](http://github.com/hslam/tree-benchmark "tree-benchmark")




## Get started
### Install
```
go get github.com/hslam/avl
```
### Import
```
import "github.com/hslam/avl"
```
### Usage
#### Example
```go
package main
import (
"fmt"
"github.com/hslam/avl"
)
func main() {
tree := avl.New()
str := String("Hello World")
tree.Insert(str)
fmt.Println(tree.Search(str))
tree.Delete(str)
}
type String string
func (a String) Less(b avl.Item) bool {
return a < b.(String)
}
```
#### Output
```
Hello World
```
#### Iterator Example
```go
package main
import (
"fmt"
"github.com/hslam/avl"
)
func main() {
tree := avl.New()
l := "MNOLKQPHIA"
for _, v := range l {
tree.Insert(String(v))
}
iter := tree.Min()
for iter != nil {
fmt.Printf("%s\t", iter.Item())
iter = iter.Next()
}
}
type String string
func (a String) Less(b avl.Item) bool {
return a < b.(String)
}
```
#### AVL Tree

#### Output
```
A H I K L M N O P Q
```
### License
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
### Author
avl was written by Meng Huang.