Commit eff86eeb authored by Kirill Smelkov's avatar Kirill Smelkov

.

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