Commit 38715d34 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1cbb2749
......@@ -32,7 +32,8 @@ type Range struct {
// RangeSet is set of non-overlapping Key ranges.
type RangeSet struct {
// TODO use BTree lo->hi_ instead
// TODO rework to use BTree lo->hi_ instead if performance turns out to
// be not acceptable
rangev []Range // lo↑
}
......@@ -95,6 +96,39 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// --------
// verify check RangeSet for internal consistency:
// - ranges must be not overlapping and ↑
func (S *RangeSet) verify() {
// XXX !debug -> return ?
var badv []string
badf := func(format string, argv ...interface{}) {
badv = append(badv, fmt.Sprintf(format, argv...))
}
defer func() {
if badv != nil {
emsg := fmt.Sprintf("S.verify: fail:\n\n")
for _, bad := range badv {
emsg += fmt.Sprintf("- %s\n", bad)
}
emsg += fmt.Sprintf("\nS: %s\n", S)
panic(emsg)
}
}()
hi_Prev := KeyMin
for i, r := range S.rangev {
if !(r.hi_ >= r.lo) {
badf("[%d]: hi_ < lo", i)
}
if !(r.lo >= hi_Prev) {
badf("[%d]: lo < hi_Prev", i)
}
hi_Prev = r.hi_
}
}
// Clone returns copy of the set.
func (orig *RangeSet) Clone() *RangeSet {
klon := &RangeSet{}
......@@ -102,15 +136,6 @@ func (orig *RangeSet) Clone() *RangeSet {
return klon
}
// XXX RangeSet.verify to check ranges are not overlapping and ↑
func (r Range) String() string {
slo := "-∞"; if r.lo > KeyMin { slo = fmt.Sprintf("%v", r.lo) }
shi := "∞"; if r.hi_ < KeyMax { shi = fmt.Sprintf("%v", r.hi_+1) }
return fmt.Sprintf("[%s,%s)", slo, shi)
}
func (S RangeSet) String() string {
s := "{"
for i, r := range S.rangev {
......@@ -122,3 +147,9 @@ func (S RangeSet) String() string {
s += "}"
return s
}
func (r Range) String() string {
slo := "-∞"; if r.lo > KeyMin { slo = fmt.Sprintf("%v", r.lo) }
shi := "∞"; if r.hi_ < KeyMax { shi = fmt.Sprintf("%v", r.hi_+1) }
return fmt.Sprintf("[%s,%s)", slo, shi)
}
......@@ -172,7 +172,7 @@ func (orig *ΔBtail) clone() *ΔBtail {
klon.byRoot = make(map[zodb.Oid]*ΔTtail, len(orig.byRoot))
for root, origΔTtail := range orig.byRoot {
klonΔTtail := &ΔTtail{}
klonΔTtail.vδT = append(nil, origΔTtail.vδT...)
klonΔTtail.vδT = append(klonΔTtail.vδT, origΔTtail.vδT...)
klonΔTtail.KVAtTail = make(map[Key]Value, len(origΔTtail.KVAtTail))
for k, v := range origΔTtail.KVAtTail {
klonΔTtail.KVAtTail[k] = v
......
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