Commit 4c57cd2b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a6bac322
...@@ -29,12 +29,44 @@ type RangedKeySet struct { ...@@ -29,12 +29,44 @@ type RangedKeySet struct {
m _RangedMap_void // XXX naming m _RangedMap_void // XXX naming
} }
// void is used as value type for RangedMap to be used as set. // void is used as value type for RangedMap to be used as set.
type void struct{} type void struct{}
func (_ void) String() string { return "" } func (_ void) String() string { return "" }
// Add adds key k to the set.
func (S *RangedKeySet) Add(k Key) {
S.AddRange(KeyRange{Lo: k, Hi_: k})
}
// Del removes key k from the set.
func (S *RangedKeySet) Del(k Key) {
S.DelRange(KeyRange{Lo: k, Hi_: k})
}
// Has returns whether key k belongs to the set.
func (S *RangedKeySet) Has(k Key) bool {
return S.HasRange(KeyRange{Lo: k, Hi_: k})
}
// AddRange adds range r to the set.
func (S *RangedKeySet) AddRange(r KeyRange) {
S.m.SetRange(r, void{})
}
// DelRange removes range r from the set.
func (S *RangedKeySet) DelRange(r KeyRange) {
S.m.DelRange(r)
}
// HasRange returns whether all keys from range r belong to the set.
func (S *RangedKeySet) HasRange(r KeyRange) (yes bool) {
return S.m.HasRange(r)
}
// Union returns RangedKeySet(A.keys | B.keys). // Union returns RangedKeySet(A.keys | B.keys).
func (A *RangedKeySet) Union(B *RangedKeySet) *RangedKeySet { func (A *RangedKeySet) Union(B *RangedKeySet) *RangedKeySet {
U := A.Clone() U := A.Clone()
...@@ -75,3 +107,16 @@ func (A *RangedKeySet) DifferenceInplace(B *RangedKeySet) { ...@@ -75,3 +107,16 @@ func (A *RangedKeySet) DifferenceInplace(B *RangedKeySet) {
A.DelRange(r) A.DelRange(r)
} }
} }
// Clone
// Empty
// Equal
// Clear
// AllRanges
// String
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