Commit a18c7fc5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 348288f6
...@@ -30,37 +30,39 @@ type Range struct { ...@@ -30,37 +30,39 @@ type Range struct {
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 non-overlapping Key ranges. // RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// XXX RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// XXX -> RangedSet ? // XXX -> RangedSet ?
type RangeSet struct { type RangeSet struct {
// TODO rework to use BTree lo->hi_ instead if performance turns out to // TODO rework to use BTree lo->hi_ instead if in practice in treediff,
// be not acceptable // and other usage places, N(ranges) turns out to be not small
// (i.e. performance turns out to be not acceptable)
rangev []Range // lo↑ rangev []Range // lo↑
} }
// XXX Add/Del - just add/del key // Add adds key k to the set.
func (S *RangeSet) Add(k Key) {
S.AddRange(Range{lo: k, hi_: k})
}
// Del removes key k from the set.
func (S *RangeSet) Del(k Key) {
S.DelRange(Range{lo: k, hi_: k})
}
// XXX Has?
// Add adds Range r to the set of keys. // XXX -> UnionInplace1 ? // AddRange adds Range r to the set.
// XXX -> AddRange ? func (S *RangeSet) AddRange(r Range) {
func (S *RangeSet) Add(r Range) {
panic("TODO") // XXX panic("TODO") // XXX
} }
// Del removes Range r from the set of keys. // XXX -> DifferenceInplace1 ? // Del removes Range r from the set.
// XXX -> DelRange? func (S *RangeSet) DelRange(r Range) {
func (S *RangeSet) Del(r Range) {
panic("TODO") // XXX panic("TODO") // XXX
} }
// XXX Has?
// XXX AddKey ?
// XXX DelKey ?
// XXX HasKey
// Union returns RangeSet(A.keys | B.keys). // Union returns RangeSet(A.keys | B.keys).
func (A *RangeSet) Union(B *RangeSet) *RangeSet { func (A *RangeSet) Union(B *RangeSet) *RangeSet {
...@@ -85,7 +87,7 @@ func (A *RangeSet) UnionInplace(B *RangeSet) { ...@@ -85,7 +87,7 @@ func (A *RangeSet) UnionInplace(B *RangeSet) {
// XXX dumb // XXX dumb
for _, r := range B.rangev { for _, r := range B.rangev {
A.Add(r) A.AddRange(r)
} }
} }
...@@ -96,7 +98,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) { ...@@ -96,7 +98,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// XXX dumb // XXX dumb
for _, r := range B.rangev { for _, r := range B.rangev {
A.Del(r) A.DelRange(r)
} }
} }
......
...@@ -46,7 +46,7 @@ func TestRangeSet(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestRangeSet(t *testing.T) {
} }
S := &RangeSet{} S := &RangeSet{}
for i := 0; i < l/2; i++ { for i := 0; i < l/2; i++ {
S.Add(Range{kv[2*i], kv[2*i+1]}) S.AddRange(Range{kv[2*i], kv[2*i+1]})
} }
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