https://github.com/gobwas/avl
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/gobwas/avl
- Owner: gobwas
- License: mit
- Created: 2021-06-06T20:01:50.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-11T12:18:01.000Z (over 4 years ago)
- Last Synced: 2025-04-11T04:35:09.073Z (11 months ago)
- Language: Go
- Size: 16.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# avl
[![GoDoc][godoc-image]][godoc-url]
[![CI][ci-badge]][ci-url]
> AVL (Adelson-Velsky and Landis) immutable tree implementation.
# Overview
This is an *immutable* implementation of the balanced binary search tree.
Its goal is to be as simple as possible in terms of API as well as correct and generic.
# Installation
```bash
go get github.com/gobwas/avl
```
# Documentation
You can read the docs at [GoDoc][godoc-url].
# Usage
```go
package main
import (
"strings"
"github.com/gobwas/avl"
)
func main() {
var tree avl.Tree
tree, _ = tree.Insert(StringItem("foo"))
tree, _ = tree.Delete(StringItem("foo"))
if tree.Search(StringItem("foo")) != nil {
// whoa!
}
}
type StringItem string
func (s StringItem) Compare(x Item) int {
return strings.Compare(string(s), string(x.(StringItem)))
}
```
[godoc-image]: https://godoc.org/github.com/gobwas/avl?status.svg
[godoc-url]: https://godoc.org/github.com/gobwas/avl
[ci-badge]: https://github.com/gobwas/avl/actions/workflows/main.yml/badge.svg?branch=main
[ci-url]: https://github.com/gobwas/avl/actions/workflows/main.yml