Commit 6e933964 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fab28d10
......@@ -269,11 +269,18 @@ func (tg *AllStructsSrv) AllStructs(kv1, kv2 map[Key]string, maxdepth, maxsplit,
}
// RTree represents Tree node covering [lo, hi_] key range in its parent tree.
type RTree struct {
oid Oid
parent *RTree
// XXX +children?
}
// RBucket represents Bucket node covering [lo, hi_] key range in its Tree.
// NOTE it is not [lo,hi) but [lo,hi_] instead to avoid overflow at KeyMax.
type RBucket struct {
// XXX +oid, +parent (RTree)
oid Oid
parent *RTree
lo, hi_ Key
kv map[Key]string // bucket's k->v; values were ZBlk objects whose data is loaded instead.
}
......@@ -340,18 +347,34 @@ func XGetTree(db *zodb.DB, at zodb.Tid, root zodb.Oid) RBucketSet {
rbucketv = append(rbucketv, rb)
})
if len(rbucketv) == 0 { // empty tree -> [-∞, ∞){}
rbucketv = RBucketSet{&RBucket{-kInf, kInf, map[Key]string{}}}
etree := &RTree{
oid: zodb.InvalidOid,
parent: nil,
}
ebucket := &RBucket{
oid: zodb.InvalidOid,
parent: etree,
lo: -kInf,
hi_: kInf,
kv: map[Key]string{},
}
rbucketv = RBucketSet{ebucket}
}
return rbucketv
}
// xwalkDFS walks ztree in depth-first order emitting bvisit callback on visited bucket nodes.
func xwalkDFS(ctx context.Context, lo, hi_ Key, ztree *Tree, bvisit func(*RBucket)) {
_xwalkDFS(ctx, lo, hi_, ztree, /*rparent*/nil, bvisit)
}
func _xwalkDFS(ctx context.Context, lo, hi_ Key, ztree *Tree, rparent *RTree, bvisit func(*RBucket)) {
X := exc.Raiseif
err := ztree.PActivate(ctx); X(err)
defer ztree.PDeactivate()
rtree := &RTree{oid: ztree.POid(), parent: rparent}
// [i].Key ≤ [i].Child.*.Key < [i+1].Key i ∈ [0, len([]))
//
// [0].Key = -∞ ; always returned so
......@@ -363,7 +386,7 @@ func xwalkDFS(ctx context.Context, lo, hi_ Key, ztree *Tree, bvisit func(*RBucke
tchild, ok := ev[i].Child().(*Tree)
if ok {
xwalkDFS(ctx, xlo, xhi_, tchild, bvisit)
_xwalkDFS(ctx, xlo, xhi_, tchild, rparent, bvisit)
continue
}
......@@ -387,7 +410,8 @@ func xwalkDFS(ctx context.Context, lo, hi_ Key, ztree *Tree, bvisit func(*RBucke
}
bvisit(&RBucket{xlo, xhi_, bkv})
b := &RBucket{oid: zbucket.POid(), parent: rtree, lo: xlo, hi_: xhi_, kv: bkv}
bvisit(b)
}
}
......@@ -603,7 +627,9 @@ func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid,
badf("δbtail.holeIdx1 wrong ; holeIdx=%v holeIdxOK=%v", δbtail.holeIdx, holes1)
}
// XXX verify δbtail trackIdx against @at1
// verify δbtail.trackIdx against @at1
// tracked1 = ... XXX
// δB <- δZ
δB, err := δbtail.Update(δZ); X(err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment