Commit eff86eeb authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5d5bf632
......@@ -22,6 +22,7 @@ package xbtree
import (
"fmt"
// "sort"
)
// Range represents [lo,hi) Key range.
......@@ -54,11 +55,17 @@ func (S *RangeSet) Del(k Key) {
// AddRange adds Range r to the set.
func (S *RangeSet) AddRange(r Range) {
S.verify()
defer S.verify()
panic("TODO") // XXX
}
// Del removes Range r from the set.
func (S *RangeSet) DelRange(r Range) {
S.verify()
defer S.verify()
panic("TODO") // XXX
}
......@@ -106,7 +113,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// --------
// verify check RangeSet for internal consistency:
// - ranges must be not overlapping and ↑
// - ranges must be not overlapping nor adjacent and ↑
func (S *RangeSet) verify() {
// XXX !debug -> return ?
......@@ -127,11 +134,11 @@ func (S *RangeSet) verify() {
hi_Prev := KeyMin
for i, r := range S.rangev {
if !(hi_Prev <= r.lo) {
badf("[%d]: lo < hi_Prev", i)
if i > 0 && !(hi_Prev < r.lo) { // NOTE not ≤ - adjacent ranges must be merged
badf("[%d]: lo <= hi_Prev", i)
}
if !(r.lo < r.hi_) {
badf("[%d]: lo >= hi_", i)
if !(r.lo <= r.hi_) {
badf("[%d]: lo > hi_", i)
}
hi_Prev = r.hi_
}
......
......@@ -46,8 +46,10 @@ func TestRangeSet(t *testing.T) {
}
S := &RangeSet{}
for i := 0; i < l/2; i++ {
S.AddRange(Range{kv[2*i], kv[2*i+1]})
// construct .rangev directly, not via AddRange
S.rangev = append(S.rangev, Range{kv[2*i], kv[2*i+1]})
}
S.verify()
return S
}
......
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