Commit a18c7fc5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 348288f6
......@@ -30,37 +30,39 @@ type Range struct {
hi_ Key // NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
}
// RangeSet is set of non-overlapping Key ranges.
// XXX RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// XXX -> RangedSet ?
type RangeSet struct {
// TODO rework to use BTree lo->hi_ instead if performance turns out to
// be not acceptable
// 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
// (i.e. performance turns out to be not acceptable)
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 ?
// XXX -> AddRange ?
func (S *RangeSet) Add(r Range) {
// AddRange adds Range r to the set.
func (S *RangeSet) AddRange(r Range) {
panic("TODO") // XXX
}
// Del removes Range r from the set of keys. // XXX -> DifferenceInplace1 ?
// XXX -> DelRange?
func (S *RangeSet) Del(r Range) {
// Del removes Range r from the set.
func (S *RangeSet) DelRange(r Range) {
panic("TODO") // XXX
}
// XXX Has?
// XXX AddKey ?
// XXX DelKey ?
// XXX HasKey
// Union returns RangeSet(A.keys | B.keys).
func (A *RangeSet) Union(B *RangeSet) *RangeSet {
......@@ -85,7 +87,7 @@ func (A *RangeSet) UnionInplace(B *RangeSet) {
// XXX dumb
for _, r := range B.rangev {
A.Add(r)
A.AddRange(r)
}
}
......@@ -96,7 +98,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// XXX dumb
for _, r := range B.rangev {
A.Del(r)
A.DelRange(r)
}
}
......
......@@ -46,7 +46,7 @@ func TestRangeSet(t *testing.T) {
}
S := &RangeSet{}
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
}
......
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