Commit 21bd85f5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9b023909
......@@ -377,6 +377,12 @@ func (S *RangedKeySet) Clear() {
S.rangev = nil
}
// AllRanges returns slice of all key ranges in the set.
// XXX -> iter?
func (S *RangedKeySet) AllRanges() /*readonly*/[]KeyRange {
return S.rangev
}
func (S RangedKeySet) String() string {
s := "{"
for i, r := range S.rangev {
......
......@@ -129,18 +129,18 @@ func TestRangedKeySet(t *testing.T) {
t.Errorf("Difference:\n A: %s\n B: %s\n ->d: %s\n okD: %s\n", tt.A, tt.B, D, tt.Difference)
}
// HasRange XXX use AllRanges instead of direct .rangev access
assertHasRange(t, A.rangev, A, true)
assertHasRange(t, B.rangev, B, true)
assertHasRange(t, A.rangev, U, true)
assertHasRange(t, B.rangev, U, true)
// HasRange
assertHasRange(t, A.AllRanges(), A, true)
assertHasRange(t, B.AllRanges(), B, true)
assertHasRange(t, A.AllRanges(), U, true)
assertHasRange(t, B.AllRanges(), U, true)
Dab := D
Dba := B.Difference(A)
assertHasRange(t, Dab.rangev, A, true)
assertHasRange(t, Dab.rangev, B, false)
assertHasRange(t, Dba.rangev, B, true)
assertHasRange(t, Dba.rangev, A, false)
assertHasRange(t, Dab.AllRanges(), A, true)
assertHasRange(t, Dab.AllRanges(), B, false)
assertHasRange(t, Dba.AllRanges(), B, true)
assertHasRange(t, Dba.AllRanges(), A, false)
}
}
......
......@@ -714,33 +714,44 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
break
}
for k := range Bkqueue {
b, err := Bv.GetToLeaf(ctx, k); /*X*/if err != nil { return nil,nil, err }
tracef(" B k%d -> %s\n", k, b)
// +bucket if that bucket is reached for the first time
if !b.done {
var δB map[Key]ΔValue
bbucket, ok := b.node.(*Bucket)
if ok { // !ok means ø tree
δB, err = diffB(ctx, nil, bbucket); /*X*/if err != nil { return nil,nil, err }
}
// for k := range Bkqueue {
for _, r := range Bkqueue.AllRanges() {
lo := r.lo
for {
b, err := Bv.GetToLeaf(ctx, lo); /*X*/if err != nil { return nil,nil, err }
tracef(" B k%d -> %s\n", lo, b)
// +bucket if that bucket is reached for the first time
if !b.done {
var δB map[Key]ΔValue
bbucket, ok := b.node.(*Bucket)
if ok { // !ok means ø tree
δB, err = diffB(ctx, nil, bbucket); /*X*/if err != nil { return nil,nil, err }
}
// δ <- δB
err = δMerge(δ, δB); /*X*/if err != nil { return nil,nil, err }
δtrack.Add.AddPath(b.Path())
// Akqueue <- δB
br := KeyRange{b.lo, b.hi_}
Bkdone.AddRange(br)
Aktodo(br)
/*
for k_ := range δB {
Bkdone.Add(k_)
Aktodo(k_)
}
*/
// δ <- δB
err = δMerge(δ, δB); /*X*/if err != nil { return nil,nil, err }
δtrack.Add.AddPath(b.Path())
// Akqueue <- δB
br := KeyRange{b.lo, b.hi_}
Bkdone.AddRange(br)
Aktodo(br)
/*
for k_ := range δB {
Bkdone.Add(k_)
Aktodo(k_)
b.done = true
}
*/
b.done = true
// stop if r coverage is complete
if r.hi_ <= b.hi_ {
break
}
// continue with next right bucket
lo = b.hi_ + 1
}
// XXX k is not there -> hole XXX test XXX <- kill?
......@@ -749,38 +760,49 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
tracef("\n")
tracef(" Akq: %s\n", Akqueue)
for k := range Akqueue {
a, err := Av.GetToLeaf(ctx, k); /*X*/if err != nil { return nil,nil, err }
tracef(" A k%d -> %s\n", k, a)
// -bucket if that bucket is reached for the first time
if !a.done {
var δA map[Key]ΔValue
abucket, ok := a.node.(*Bucket)
if ok { // !ok means ø tree
δA, err = diffB(ctx, abucket, nil); /*X*/if err != nil { return nil,nil, err }
}
// for k := range Akqueue {
for _, r := range Akqueue.AllRanges() {
lo := r.lo
for {
a, err := Av.GetToLeaf(ctx, lo); /*X*/if err != nil { return nil,nil, err }
tracef(" A k%d -> %s\n", lo, a)
// -bucket if that bucket is reached for the first time
if !a.done {
var δA map[Key]ΔValue
abucket, ok := a.node.(*Bucket)
if ok { // !ok means ø tree
δA, err = diffB(ctx, abucket, nil); /*X*/if err != nil { return nil,nil, err }
}
// δ <- δA
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err }
δtrack.Del.AddPath(a.Path())
// δ <- δA
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err }
δtrack.Del.AddPath(a.Path())
// Bkqueue <- a.range
ar := KeyRange{a.lo, a.hi_}
Akdone.AddRange(ar)
Bktodo(ar)
/* XXX kill
// Bkqueue <- δA
for k_ := range δA {
Akdone.Add(k_)
Bktodo(k_)
}
// Bkqueue <- holes(a.range)
for k_ := range holeIdx.GetInRange(a.lo, a.hi_) {
Bktodo(k_)
}
*/
// Bkqueue <- a.range
ar := KeyRange{a.lo, a.hi_}
Akdone.AddRange(ar)
Bktodo(ar)
/* XXX kill
// Bkqueue <- δA
for k_ := range δA {
Akdone.Add(k_)
Bktodo(k_)
a.done = true
}
// Bkqueue <- holes(a.range)
for k_ := range holeIdx.GetInRange(a.lo, a.hi_) {
Bktodo(k_)
}
*/
a.done = true
// stop if r coverage is complete
if r.hi_ <= a.hi_ {
break
}
// continue with next right bucket
lo = a.hi_ + 1
}
}
Akqueue.Clear()
......
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