Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hslam/btree
Package btree implements a B-tree.
https://github.com/hslam/btree
b-tree btree go golang tree
Last synced: 2 months ago
JSON representation
Package btree implements a B-tree.
- Host: GitHub
- URL: https://github.com/hslam/btree
- Owner: hslam
- License: mit
- Created: 2020-11-03T03:20:23.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T13:57:06.000Z (over 2 years ago)
- Last Synced: 2024-08-03T23:23:04.560Z (6 months ago)
- Topics: b-tree, btree, go, golang, tree
- Language: Go
- Homepage:
- Size: 137 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - btree - tree. (Repositories)
README
# btree
[![PkgGoDev](https://pkg.go.dev/badge/github.com/hslam/btree)](https://pkg.go.dev/github.com/hslam/btree)
[![Build Status](https://github.com/hslam/btree/workflows/build/badge.svg)](https://github.com/hslam/btree/actions)
[![codecov](https://codecov.io/gh/hslam/btree/branch/master/graph/badge.svg)](https://codecov.io/gh/hslam/btree)
[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/btree)](https://goreportcard.com/report/github.com/hslam/btree)
[![LICENSE](https://img.shields.io/github/license/hslam/btree.svg?style=flat-square)](https://github.com/hslam/btree/blob/master/LICENSE)Package btree implements a B-tree.
#### Definition
According to Knuth's definition, a **[B-tree](https://en.wikipedia.org/wiki/B-tree "B-tree")** of order m is a tree which satisfies the following properties:
* Every node has at most m children.
* Every non-leaf node (except root) has at least ⌈m/2⌉ child nodes.
* The root has at least two children if it is not a leaf node.
* A non-leaf node with k children contains k − 1 keys.
* All leaves appear in the same level and carry no information.## [Benchmark](http://github.com/hslam/btree-benchmark "btree-benchmark")
## Get started
### Install
```
go get github.com/hslam/btree
```
### Import
```
import "github.com/hslam/btree"
```
### Usage
#### Example
```go
package mainimport (
"fmt"
"github.com/hslam/btree"
)func main() {
tree := btree.New(2)
str := String("Hello World")
tree.Insert(str)
fmt.Println(tree.Search(str))
tree.Delete(str)
}type String string
func (a String) Less(b btree.Item) bool {
return a < b.(String)
}
```#### Output
```
Hello World
```#### Iterator Example
```go
package mainimport (
"fmt"
"github.com/hslam/btree"
)func main() {
tree := btree.New(2)
for i := 0; i < 10; i++ {
tree.Insert(Int(i))
}
iter := tree.Min().MinIterator()
for iter != nil {
fmt.Printf("%d\t", iter.Item())
iter = iter.Next()
}
}type Int int
func (a Int) Less(b btree.Item) bool {
return a < b.(Int)
}
```
#### B-Tree#### Output
```
0 1 2 3 4 5 6 7 8 9
```### License
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)### Author
btree was written by Meng Huang.