bptree does not work well for auto-increasing keys

This commit is contained in:
Chris Lu
2021-08-22 18:19:26 -07:00
parent 51c8f2518f
commit df1d6133a8
6 changed files with 193 additions and 28 deletions

View File

@@ -1,5 +1,13 @@
package bptree
var (
protoNodeId = int64(0)
)
func GetProtoNodeId() int64 {
protoNodeId++
return protoNodeId
}
func (self *BpMap) getRoot() *BpNode {
return self.root
}
@@ -26,3 +34,39 @@ func (self *BpNode) getPrev() *BpNode {
func (self *BpNode) setPrev(prev *BpNode) {
self.prev = prev
}
func (self *BpNode) getNode(x int)(*BpNode) {
return self.pointers[x]
}
func (self *BpNode) maybePersist(shouldPersist bool) error {
if !shouldPersist {
return nil
}
return self.persist()
}
func (self *BpNode) persist() error {
if PersistFn != nil {
return PersistFn(self)
}
return nil
}
func (self *BpNode) destroy() error {
if DestroyFn != nil {
return DestroyFn(self)
}
return nil
}
func persist(a, b *BpNode) error {
if a != nil {
if err := a.persist(); err != nil {
return err
}
}
if b != nil {
if err := b.persist(); err != nil {
return err
}
}
return nil
}