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

.

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