Commit c4a49a11 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 45383e25
......@@ -694,10 +694,10 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
var av rangeSplit // nodes expanded from a
var bv rangeSplit // nodes expanded from b
Aqueue := SetKey{} // "to process" keys on A
Bqueue := SetKey{} // "to process" keys on B
Adone := SetKey{} // "processed" keys on A
Bdone := SetKey{} // "processed" keys on B
// Aqueue := SetKey{} // "to process" keys on A
// Bqueue := SetKey{} // "to process" keys on B
// Adone := SetKey{} // "processed" keys on A
// Bdone := SetKey{} // "processed" keys on B
// XXX precise range as for a ^^^ ?
btop := &nodeInRange{lo: KeyMin, hi_: KeyMax, node: b} // [-∞, ∞)
......@@ -708,7 +708,10 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
// XXX maybe walk till a from root to get more precise initial range?
atop := &nodeInRange{lo: KeyMin, hi_: KeyMax, node: a} // [-∞, ∞)
av = rangeSplit{atop}
aq := []*nodeInRange{atop} // stack
Aqueue := []*nodeInRange{atop} // stack: "to process" nodes on A
Bqueue := []*nodeInRange{} // stack: "to process" nodes on B
/*
for len(aq) > 0 {
l := len(aq)
arn := aq[l-1]; aq=aq[:l-1] // arn=aq.pop()
......@@ -749,7 +752,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
for _, rchild := range children {
coid := rchild.node.POid()
if !( δZTC.Has(coid) ||
/* embedded bucket */
embedded bucket
(len(children) == 1 && coid == zodb.InvalidOid) ) {
continue
}
......@@ -789,6 +792,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
}
}
}
*/
tracef(" av: %s\n", av)
tracef(" bv: %s\n", bv)
......@@ -797,9 +801,6 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
// corresponding nodes, and merge diff generated from them into δ.
// Each delve for A or B, potentially adds new keys to process on the
// other side.
//
// XXX inefficient: we process each key separately, while they can be
// processed in sorted batches.
for {
tracef("\n")
tracef(" aq: %s\n", Aqueue)
......@@ -809,6 +810,61 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
break
}
// A queue
// Bqueue = SetKey{}
for len(Aqueue) > 0 {
Xa := pop(&Aqueue)
tracef(" A %v\n", Xa)
/*
anode, ok, err := av.GetToLeaf(ctx, k)
if err != nil {
return nil, err
}
if !ok {
// FIXME -> key must be included into some node.hole
continue // key not covered
}
// XXX check for anode.node.(*Tree) (ø tree case)
// - bucket if that bucket is reached for the first time
if !anode.done {
δA, err := diffB(ctx, anode.node.(*Bucket), nil)
if err != nil {
return nil, err
}
// XXX also extract holes
// δ <- δA
err = δMerge(δ, δA)
if err != nil {
return nil, err
}
// Adone <- δA
// Bqueue <- δA
for k_ := range δA {
Adone.Add(k_)
if !Bdone.Has(k_) {
Bqueue.Add(k_)
}
}
anode.done = true
}
// k is not there -> -[k]ø
if !Adone.Has(k) {
// XXX do we need to add(?) [k]ø->ø ?
Adone.Add(k)
}
*/
tracef(" av: %s\n", av)
}
/*
// B queue
// expand keys from new δA -> in B till buckets;
// process B buckets that cover new keys into δ+
......@@ -862,6 +918,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
tracef(" bv: %s\n", bv)
}
*/
// FIXME update trackIdx
/*
......@@ -891,55 +948,6 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
}
*/
// A queue
Bqueue = SetKey{}
for k := range Aqueue {
tracef(" A [%v]\n", k)
anode, ok, err := av.GetToLeaf(ctx, k)
if err != nil {
return nil, err
}
if !ok {
// FIXME -> key must be included into some node.hole
continue // key not covered
}
// XXX check for anode.node.(*Tree) (ø tree case)
// - bucket if that bucket is reached for the first time
if !anode.done {
δA, err := diffB(ctx, anode.node.(*Bucket), nil)
if err != nil {
return nil, err
}
// XXX also extract holes
// δ <- δA
err = δMerge(δ, δA)
if err != nil {
return nil, err
}
// Adone <- δA
// Bqueue <- δA
for k_ := range δA {
Adone.Add(k_)
if !Bdone.Has(k_) {
Bqueue.Add(k_)
}
}
anode.done = true
}
// k is not there -> -[k]ø
if !Adone.Has(k) {
// XXX do we need to add(?) [k]ø->ø ?
Adone.Add(k)
}
tracef(" av: %s\n", av)
}
}
return δ, nil
......@@ -1522,6 +1530,15 @@ func (track nodeTrack) String() string {
}
// pop pops top element from node stack.
func pop(nodeStk *[]*nodeInRange) *nodeInRange {
stk := *nodeStk
l := len(stk)
top := stk[l-1]
*nodeStk = stk[:l-1]
return top
}
const debug = true
func tracef(format string, argv ...interface{}) {
......
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