Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crufter/btree
This is technically a B+Tree, but the btree name is easier on the tongoue :). Completely improvised and not based on anything sane
https://github.com/crufter/btree
Last synced: 2 months ago
JSON representation
This is technically a B+Tree, but the btree name is easier on the tongoue :). Completely improvised and not based on anything sane
- Host: GitHub
- URL: https://github.com/crufter/btree
- Owner: crufter
- Created: 2012-05-24T07:22:34.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-07T05:31:19.000Z (over 12 years ago)
- Last Synced: 2023-03-24T04:23:23.320Z (almost 2 years ago)
- Language: Go
- Homepage:
- Size: 122 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Btree
=====
This is technically a B+Tree, but the btree name is easier on the tongoue :). Implemented in Go.
The leaves are chained bidirectionally.What's the point?
=====
I needed a sorted set, which internals I know and I can extend to my own database related needs.Is it threadsafe?
=====
No.Examples
=====
```
package mainimport(
"github.com/opesun/btree"
"fmt"
)// Here we declare a type what the btree will happily accept.
// Note this design does not really allow more than one type in a btree, but thats the point.
// Of course, if you want, you can implement your very own crazy types which compare ints to string or things like that.
type Int int
func (i Int) Less(c btree.Comper) bool {
a, ok := c.(Int)
if !ok {
return false
}
return i < a
}
func (i Int) Eq(c btree.Comper) bool {
a, ok := c.(Int)
if !ok {
return false
}
return i == a
}func main() {
t, err := btree.New(50) // branching factor of the btree. For high performance 100 is optimal.
if err != nil {
panic(err)
}
t.Insert(Int(8)) // Btree accepts btee.Comper interface
fmt.Println(
t.Find(Int(8)),
t.Delete(Int(8)),
t.Find(Int(8)),
)
}
```What's up with those panics in the source code, a Go pkg shall not panic!
=====
The fact is, the pkg only panics if there is a bug in the algorithm, and it's better for you, me, and the globe if you notice it.Future
=====
Transform this into a counted b+tree.Credits
=====
- Thanks skelterjohn (John Asmuth) for pointing out that I don't need two different struct for the node and leaf, and also for helping me grasping some concepts of Go.