Commit 41045c0b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 24930939
...@@ -25,19 +25,13 @@ TYPE=$1 ...@@ -25,19 +25,13 @@ TYPE=$1
VALUE=$2 VALUE=$2
out=$3 out=$3
kind=${KIND,,} # IO -> io
Value=${VALUE^}
input=$(dirname $0)/rangemap.go.in input=$(dirname $0)/rangemap.go.in
echo "// Code generated by gen-rangemap $TYPE $VALUE; DO NOT EDIT." >$out echo "// Code generated by gen-rangemap $TYPE $VALUE; DO NOT EDIT." >$out
echo >>$out echo >>$out
sed \ sed \
-e "s/<kind>/$kind/g" \
-e "s/<KIND>/$KIND/g" \
-e "s/VALUE/$VALUE/g" \ -e "s/VALUE/$VALUE/g" \
-e "s/<Value>/$Value/g" \
-e "s/\bRangedMap\b/${TYPE}/g" \ -e "s/\bRangedMap\b/${TYPE}/g" \
-e "s/\bRangedMapEntry\b/${TYPE}Entry/g" \ -e "s/\bRangedMapEntry\b/${TYPE}Entry/g" \
-e "s/\bvInsert\b/vInsert_${TYPE}/g" \ -e "s/\bvInsert\b/vInsert_${TYPE}/g" \
......
...@@ -116,8 +116,8 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) { ...@@ -116,8 +116,8 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
defer M.verify() defer M.verify()
// clear range for r and insert new entry // clear range for r and insert new entry
// TODO optimize for set case (just merge all covered entries into one - // TODO optimize for same-value/set case (just merge all covered
// - see commented AddRange vvv) // entries into one - - see commented AddRange from set vvv)
i := M.delRange(r) i := M.delRange(r)
vInsert(&M.entryv, i, e) vInsert(&M.entryv, i, e)
debugfRMap("\tinsert %s\t-> %s\n", e, M) debugfRMap("\tinsert %s\t-> %s\n", e, M)
......
...@@ -26,10 +26,17 @@ import ( ...@@ -26,10 +26,17 @@ import (
"testing" "testing"
) )
func TestRangedMap(t *testing.T) { type (
type RangedMap = _RangedMap_str RangedMap = _RangedMap_str
type RangedMapEntry = _RangedMap_strEntry RangedMapEntry = _RangedMap_strEntry
)
const (
oo = KeyMax
noo = KeyMin
)
func TestRangedMap(t *testing.T) {
type testEntry struct { type testEntry struct {
A *RangedMap A *RangedMap
B RangedMapEntry B RangedMapEntry
...@@ -138,7 +145,7 @@ func TestRangedMap(t *testing.T) { ...@@ -138,7 +145,7 @@ func TestRangedMap(t *testing.T) {
r := B.KeyRange r := B.KeyRange
v := B.Value v := B.Value
assertMHasRange(t, A, r, tt.Has) assertMapHasRange(t, A, r, tt.Has)
Aset := A.Clone() Aset := A.Clone()
Adel := A.Clone() Adel := A.Clone()
Aset.SetRange(r, v) Aset.SetRange(r, v)
...@@ -154,8 +161,8 @@ func TestRangedMap(t *testing.T) { ...@@ -154,8 +161,8 @@ func TestRangedMap(t *testing.T) {
} }
assertMHasRange(t, Aset, r, true) assertMapHasRange(t, Aset, r, true)
assertMHasRange(t, Adel, r, false) assertMapHasRange(t, Adel, r, false)
verifyGet(t, A) verifyGet(t, A)
verifyGet(t, Aset) verifyGet(t, Aset)
...@@ -163,8 +170,8 @@ func TestRangedMap(t *testing.T) { ...@@ -163,8 +170,8 @@ func TestRangedMap(t *testing.T) {
} }
} }
// assertMHasRange asserts that RangeMap M.HasRange(r) == hasOK. // assertMapHasRange asserts that RangeMap M.HasRange(r) == hasOK.
func assertMHasRange(t *testing.T, M *_RangedMap_str, r KeyRange, hasOK bool) { func assertMapHasRange(t *testing.T, M *RangedMap, r KeyRange, hasOK bool) {
t.Helper() t.Helper()
has := M.HasRange(r) has := M.HasRange(r)
if !(has == hasOK) { if !(has == hasOK) {
...@@ -173,10 +180,7 @@ func assertMHasRange(t *testing.T, M *_RangedMap_str, r KeyRange, hasOK bool) { ...@@ -173,10 +180,7 @@ func assertMHasRange(t *testing.T, M *_RangedMap_str, r KeyRange, hasOK bool) {
} }
// verifyGet verifies RangedMap.Get . // verifyGet verifies RangedMap.Get .
func verifyGet(t *testing.T, M *_RangedMap_str) { func verifyGet(t *testing.T, M *RangedMap) {
type RangedMap = _RangedMap_str
type RangedMapEntry = _RangedMap_strEntry
t.Helper() t.Helper()
var Mranges []RangedMapEntry var Mranges []RangedMapEntry
......
...@@ -22,6 +22,7 @@ package blib ...@@ -22,6 +22,7 @@ package blib
//go:generate ./gen-rangemap _RangedMap_void void zrangemap_void.go //go:generate ./gen-rangemap _RangedMap_void void zrangemap_void.go
// RangedKeySet is set of Keys with adjacent keys coalesced into Ranges. // RangedKeySet is set of Keys with adjacent keys coalesced into Ranges.
// //
// Zero value represents empty set. // Zero value represents empty set.
...@@ -81,7 +82,7 @@ func (A *RangedKeySet) Difference(B *RangedKeySet) *RangedKeySet { ...@@ -81,7 +82,7 @@ func (A *RangedKeySet) Difference(B *RangedKeySet) *RangedKeySet {
return D return D
} }
// XXX Intersection // TODO Intersection
func (A *RangedKeySet) UnionInplace(B *RangedKeySet) { func (A *RangedKeySet) UnionInplace(B *RangedKeySet) {
A.verify() A.verify()
......
...@@ -42,11 +42,6 @@ func TestRangedKeySetTypes(t *testing.T) { ...@@ -42,11 +42,6 @@ func TestRangedKeySetTypes(t *testing.T) {
} }
} }
const (
oo = KeyMax
noo = KeyMin
)
func TestRangedKeySet(t *testing.T) { func TestRangedKeySet(t *testing.T) {
type testEntry struct { type testEntry struct {
A, B *RangedKeySet A, B *RangedKeySet
...@@ -122,12 +117,6 @@ func TestRangedKeySet(t *testing.T) { ...@@ -122,12 +117,6 @@ func TestRangedKeySet(t *testing.T) {
S(noo, oo), // U S(noo, oo), // U
S()), // D S()), // D
E(
S(5,7), // A
S(3,5), // B
S(3,7), // U
S(5,7)), // D
// [1,3) [5,7) + insert [3,5) -> [1,7) // [1,3) [5,7) + insert [3,5) -> [1,7)
E( E(
S(1,3, 5,7), // A S(1,3, 5,7), // A
...@@ -158,22 +147,22 @@ func TestRangedKeySet(t *testing.T) { ...@@ -158,22 +147,22 @@ func TestRangedKeySet(t *testing.T) {
} }
// HasRange // HasRange
assertSHasRange(t, A.AllRanges(), A, true) assertSetHasRanges(t, A, A.AllRanges(), true)
assertSHasRange(t, B.AllRanges(), B, true) assertSetHasRanges(t, B, B.AllRanges(), true)
assertSHasRange(t, A.AllRanges(), U, true) assertSetHasRanges(t, U, A.AllRanges(), true)
assertSHasRange(t, B.AllRanges(), U, true) assertSetHasRanges(t, U, B.AllRanges(), true)
Dab := D Dab := D
Dba := B.Difference(A) Dba := B.Difference(A)
assertSHasRange(t, Dab.AllRanges(), A, true) assertSetHasRanges(t, A, Dab.AllRanges(), true)
assertSHasRange(t, Dab.AllRanges(), B, false) assertSetHasRanges(t, B, Dab.AllRanges(), false)
assertSHasRange(t, Dba.AllRanges(), B, true) assertSetHasRanges(t, B, Dba.AllRanges(), true)
assertSHasRange(t, Dba.AllRanges(), A, false) assertSetHasRanges(t, A, Dba.AllRanges(), false)
} }
} }
// assertSHasRange asserts for all ranges from rangev that RangedSet S.HasRange(r) == hasOK. // assertSetHasRanges asserts for all ranges from rangev that RangedSet S.HasRange(r) == hasOK.
func assertSHasRange(t *testing.T, rangev []KeyRange, S *RangedKeySet, hasOK bool) { func assertSetHasRanges(t *testing.T, S *RangedKeySet, rangev []KeyRange, hasOK bool) {
t.Helper() t.Helper()
for _, r := range rangev { for _, r := range rangev {
has := S.HasRange(r) has := S.HasRange(r)
......
...@@ -118,8 +118,8 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) { ...@@ -118,8 +118,8 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) {
defer M.verify() defer M.verify()
// clear range for r and insert new entry // clear range for r and insert new entry
// TODO optimize for set case (just merge all covered entries into one - // TODO optimize for same-value/set case (just merge all covered
// - see commented AddRange vvv) // entries into one - - see commented AddRange from set vvv)
i := M.delRange(r) i := M.delRange(r)
vInsert__RangedMap_str(&M.entryv, i, e) vInsert__RangedMap_str(&M.entryv, i, e)
debugf_RangedMap_str("\tinsert %s\t-> %s\n", e, M) debugf_RangedMap_str("\tinsert %s\t-> %s\n", e, M)
......
...@@ -118,8 +118,8 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) { ...@@ -118,8 +118,8 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
defer M.verify() defer M.verify()
// clear range for r and insert new entry // clear range for r and insert new entry
// TODO optimize for set case (just merge all covered entries into one - // TODO optimize for same-value/set case (just merge all covered
// - see commented AddRange vvv) // entries into one - - see commented AddRange from set vvv)
i := M.delRange(r) i := M.delRange(r)
vInsert__RangedMap_void(&M.entryv, i, e) vInsert__RangedMap_void(&M.entryv, i, e)
debugf_RangedMap_void("\tinsert %s\t-> %s\n", e, M) debugf_RangedMap_void("\tinsert %s\t-> %s\n", e, M)
......
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