Embedded btree database package fully implemented in GO.
This package provides an implementation of a concurrent paged disk BTree. I created this package for other projects I am working on. I wanted a simple, easy-to-use disk BTree that I could use in my projects and now hopefully yours. Feel free to drop a PR or an issue if you have any suggestions or improvements.
- Concurrent: The BTree is safe for concurrent use.
- Disk-based: The BTree is designed to be used with a disk-based storage engine.
int
int8
int16
int32
int64
uint
uint8
uint16
uint32
uint64
float32
float64
string
[]byte
Any, using interface{}
import "github.com/guycipher/btree"
You can use the Open
method to open an existing btree or create a new one.
You can specify the file, permission and T(degree)
btree := btree.Open("path/to/btree.db", 0644, 3)
You can insert a value into a key using the Put
method. Keys can store many values.
btree.Put("key", "value")
To get a value you can you the Get
method. The get method will return all the keys values.
value := btree.Get("key")
To delete a key and all of it's values you can use the Delete
method.
btree.Delete("key")
To remove a value from a key you can use the Remove
method.
btree.Remove("key", "value")
The iterator is used to iterate over values of a key
it := b.Iterator()
for it.Next() {
value, err := it.Value()
if err != nil {
// handle error
}
fmt.Println(value)
}
keys, err := bt.Range(12, 16)
if err != nil {
t.Fatal(err)
}
You can close the BTree by calling the Close function.
btree.Close()