Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krasun/fbptree
A persistent storage (in file) based using B+ tree with byte-slice keys and values
https://github.com/krasun/fbptree
bplus-tree bplustree bptree go golang
Last synced: 2 months ago
JSON representation
A persistent storage (in file) based using B+ tree with byte-slice keys and values
- Host: GitHub
- URL: https://github.com/krasun/fbptree
- Owner: krasun
- License: mit
- Created: 2021-07-24T11:51:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T12:31:21.000Z (about 3 years ago)
- Last Synced: 2024-12-09T17:00:34.944Z (2 months ago)
- Topics: bplus-tree, bplustree, bptree, go, golang
- Language: Go
- Homepage:
- Size: 92.8 KB
- Stars: 24
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - fbptree - slice keys and values (Repositories)
README
# **fbp**tree
[![Build](https://github.com/krasun/fbptree/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/krasun/fbptree/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/krasun/fbptree/branch/main/graph/badge.svg?token=8NU6LR4FQD)](https://codecov.io/gh/krasun/fbptree)
[![Go Report Card](https://goreportcard.com/badge/github.com/krasun/fbptree)](https://goreportcard.com/report/github.com/krasun/fbptree)
[![GoDoc](https://godoc.org/https://godoc.org/github.com/krasun/fbptree?status.svg)](https://godoc.org/github.com/krasun/fbptree)`fbptree` is a persistent key-value storage engine based on [B+ tree](https://en.wikipedia.org/wiki/B%2B_tree) with byte-slice keys and values.
## Installation
To install, run:
```
go get github.com/krasun/fbptree
```## Usage
An example of usage:
```go
package fbptree_testimport (
"fmt"
"io/ioutil"
"os"
"path""github.com/krasun/fbptree"
)func Example() {
dbDir, err := ioutil.TempDir(os.TempDir(), "example")
if err != nil {
panic(fmt.Errorf("failed to create %s: %w", dbDir, err))
}
defer func() {
if err := os.RemoveAll(dbDir); err != nil {
panic(fmt.Errorf("failed to remove %s: %w", dbDir, err))
}
}()dbPath := path.Join(dbDir, "sample.data")
tree, err := fbptree.Open(dbPath, fbptree.PageSize(4096), fbptree.Order(500))
if err != nil {
panic(fmt.Errorf("failed to open B+ tree %s: %w", dbDir, err))
}_, _, err = tree.Put([]byte("Hi!"), []byte("Hello world, B+ tree!"))
if err != nil {
panic(fmt.Errorf("failed to put: %w", err))
}_, _, err = tree.Put([]byte("Does it override key?"), []byte("No!"))
if err != nil {
panic(fmt.Errorf("failed to put: %w", err))
}_, _, err = tree.Put([]byte("Does it override key?"), []byte("Yes, absolutely! The key has been overridden."))
if err != nil {
panic(fmt.Errorf("failed to put: %w", err))
}if err := tree.Close(); err != nil {
panic(fmt.Errorf("failed to close: %w", err))
}tree, err = fbptree.Open(dbPath, fbptree.PageSize(4096), fbptree.Order(500))
if err != nil {
panic(fmt.Errorf("failed to open B+ tree %s: %w", dbDir, err))
}value, ok, err := tree.Get([]byte("Hi!"))
if err != nil {
panic(fmt.Errorf("failed to get value: %w", err))
}
if !ok {
fmt.Println("failed to find value")
}fmt.Println(string(value))
value, ok, err = tree.Get([]byte("Does it override key?"))
if err != nil {
panic(fmt.Errorf("failed to get value: %w", err))
}
if !ok {
fmt.Println("failed to find value")
}if err := tree.Close(); err != nil {
panic(fmt.Errorf("failed to close: %w", err))
}fmt.Println(string(value))
// Output:
// Hello world, B+ tree!
// Yes, absolutely! The key has been overridden.
}
```## Tests
Run tests with:
```
$ go test .
ok github.com/krasun/fbptree 0.679s
```## License
**fbp**tree is released under [the MIT license](LICENSE).