package main
import (
"github.com/google/btree"
"fmt"
"flag"
)
var btreeDegree = flag.Int("degree", 32, "B-Tree degree")
func main() {
tr := btree.New(*btreeDegree)
for i := btree.Int(0); i < 10; i++ {
tr.ReplaceOrInsert(i)
}
fmt.Println("len: ", tr.Len())
fmt.Println("len: ", tr.Len())
fmt.Println("get3: ", tr.Get(btree.Int(3)))
fmt.Println("get100: ", tr.Get(btree.Int(100)))
fmt.Println("del4: ", tr.Delete(btree.Int(4)))
fmt.Println("del100: ", tr.Delete(btree.Int(100)))
fmt.Println("replace5: ", tr.ReplaceOrInsert(btree.Int(5)))
fmt.Println("replace100:", tr.ReplaceOrInsert(btree.Int(100)))
fmt.Println("min: ", tr.Min())
fmt.Println("delmin: ", tr.DeleteMin())
fmt.Println("max: ", tr.Max())
fmt.Println("delmax: ", tr.DeleteMax())
fmt.Println("len: ", tr.Len())
}
However, what if I want to insert pair instead of int?
For example, I want to insert (v1,v2,…)into the btree, and the btree is sorted by v2.
So basically I want to do CRUD on the btree(Create a node and then insert, Retrieve the node, Update the node by changing the v2,Delete the node by v1)
It will be better if it can generalize to arbitrary item and sort by certain element.