mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
simplify Walker interface
This commit is contained in:
parent
d6986b78a5
commit
b8fe08c765
2 changed files with 21 additions and 14 deletions
|
|
@ -822,15 +822,16 @@ func (e *EasyWalker) Visitor(pgno uint32, records []*rbf.RootRecord) {
|
|||
func (e *EasyWalker) VisitRoot(pgno uint32, name string) {
|
||||
e.path.WriteString("R")
|
||||
}
|
||||
func (e *EasyWalker) VisitBranch(pgno uint32) {
|
||||
e.path.WriteString("B")
|
||||
func (e *EasyWalker) Visit(pgno uint32, node rbf.Nodetype) {
|
||||
switch node {
|
||||
case rbf.Branch:
|
||||
e.path.WriteString("B")
|
||||
case rbf.Leaf:
|
||||
e.path.WriteString("L")
|
||||
case rbf.Bitmap:
|
||||
e.path.WriteString("b")
|
||||
}
|
||||
|
||||
}
|
||||
func (e *EasyWalker) VisitLeaf(pgno uint32) {
|
||||
e.path.WriteString("L")
|
||||
|
||||
}
|
||||
func (e *EasyWalker) VisitBitmap(pgno uint32) {
|
||||
}
|
||||
func (e *EasyWalker) String() string {
|
||||
return e.path.String()
|
||||
|
|
|
|||
|
|
@ -139,12 +139,18 @@ func toContainer(l leafCell) *roaring.Container {
|
|||
return nil
|
||||
}
|
||||
|
||||
type Nodetype int
|
||||
|
||||
const (
|
||||
Branch Nodetype = iota
|
||||
Leaf
|
||||
Bitmap
|
||||
)
|
||||
|
||||
type Walker interface {
|
||||
Visitor(pgno uint32, records []*RootRecord)
|
||||
VisitRoot(pgno uint32, name string)
|
||||
VisitBranch(pgno uint32)
|
||||
VisitLeaf(pgno uint32)
|
||||
VisitBitmap(pgno uint32)
|
||||
Visit(pgno uint32, n Nodetype)
|
||||
}
|
||||
|
||||
func Page(tx *Tx, pgno uint32, walker Walker) {
|
||||
|
|
@ -161,17 +167,17 @@ func Page(tx *Tx, pgno uint32, walker Walker) {
|
|||
// Handle
|
||||
switch typ := readFlags(page); typ {
|
||||
case PageTypeBranch:
|
||||
walker.VisitBranch(pgno)
|
||||
walker.Visit(pgno, Branch)
|
||||
for i, n := 0, readCellN(page); i < n; i++ {
|
||||
cell := readBranchCell(page, i)
|
||||
if cell.Flags&ContainerTypeBitmap == 0 { // leaf/branch child page
|
||||
Page(tx, cell.Pgno, walker)
|
||||
} else {
|
||||
walker.VisitBitmap(cell.Pgno)
|
||||
walker.Visit(cell.Pgno, Bitmap)
|
||||
}
|
||||
}
|
||||
case PageTypeLeaf:
|
||||
walker.VisitLeaf(pgno)
|
||||
walker.Visit(pgno, Leaf)
|
||||
default:
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue