Commit a22223af authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fc9b4d85
...@@ -29,13 +29,16 @@ const traceRangeSet = false ...@@ -29,13 +29,16 @@ const traceRangeSet = false
const debugRangeSet = false const debugRangeSet = false
// Range represents [lo,hi) Key range. // Range represents [lo,hi) Key range.
// XXX -> KeyRange?
type Range struct { type Range struct {
lo Key lo Key
hi_ Key // NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1 hi_ Key // NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
} }
// RangeSet is set of Keys with adjacent keys coaleced into Ranges. // RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// XXX -> RangedSet ? //
// Zero value represents empty set.
// XXX -> RangedSet ? RangedKeySet ? RangeKeySet?
type RangeSet struct { type RangeSet struct {
// TODO rework to use BTree lo->hi_ instead if in practice in treediff, // TODO rework to use BTree lo->hi_ instead if in practice in treediff,
// and other usage places, N(ranges) turns out to be not small // and other usage places, N(ranges) turns out to be not small
...@@ -347,6 +350,11 @@ func (orig *RangeSet) Clone() *RangeSet { ...@@ -347,6 +350,11 @@ func (orig *RangeSet) Clone() *RangeSet {
return klon return klon
} }
// Empty returns whether the set is empty.
func (S *RangeSet) Empty() bool {
return len(S.rangev) == 0
}
// Equal returns whether A == B. // Equal returns whether A == B.
func (A *RangeSet) Equal(B *RangeSet) bool { func (A *RangeSet) Equal(B *RangeSet) bool {
if len(A.rangev) != len(B.rangev) { if len(A.rangev) != len(B.rangev) {
......
...@@ -520,25 +520,25 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet) ...@@ -520,25 +520,25 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
Bv := rangeSplit{btop} // nodes expanded from B Bv := rangeSplit{btop} // nodes expanded from B
// for phase 2: // for phase 2:
Akqueue := SetKey{} // queue for keys in A to be processed for δ- XXX -> KeyRangeSet Akqueue := &RangeSet{} // queue for keys in A to be processed for δ-
Bkqueue := SetKey{} // ----//---- in B for δ+ XXX ----//---- Bkqueue := &RangeSet{} // ----//---- in B for δ+
Akdone := SetKey{} // already processed keys in A XXX ----//---- Akdone := &RangeSet{} // already processed keys in A
Bkdone := SetKey{} // ----//---- in B XXX ----//---- Bkdone := &RangeSet{} // ----//---- in B
Aktodo := func(k Key) { Aktodo := func(k Key) {
if !Akdone.Has(k) { if !Akdone.Has(k) {
tracef(" Akq <- %d\n", k) tracef(" Akq <- %d\n", k)
Akqueue.Add(k) Akqueue.Add(k)
} }
} }
Bktodo := func(lo, hi_ Key) { // XXX func(r KeyRange) Bktodo := func(lo, hi_ Key) { // XXX -> func(r Range)
panic("TODO") r := Range{lo, hi_}
/* XXX reenable
if !Bkdone.HasRange(r) { if !Bkdone.HasRange(r) {
δtodo := r.Difference(Bkdone) // XXX name δtodo := &RangeSet{}
δtodo.AddRange(r)
δtodo.DifferenceInplace(Bkdone)
tracef(" Bkq <- %s\n", δtodo) tracef(" Bkq <- %s\n", δtodo)
Bkqueue.UnionInplace(δtodo) Bkqueue.UnionInplace(δtodo)
} }
*/
/* XXX kill /* XXX kill
if !Bkdone.Has(k) { if !Bkdone.Has(k) {
tracef(" Bkq <- %d\n", k) tracef(" Bkq <- %d\n", k)
...@@ -702,7 +702,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet) ...@@ -702,7 +702,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
tracef("\n") tracef("\n")
tracef(" Bkq: %s\n", Bkqueue) tracef(" Bkq: %s\n", Bkqueue)
if len(Bkqueue) == 0 { if Bkqueue.Empty() {
break break
} }
......
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