mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Add a lib/interval sharedEmptyRange global
This commit is contained in:
1 parent
3b56ace877
commit
648932e0fb
2 files changed
+16
-10
No files matched your search
@@ -39,7 +39,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
one = big.NewInt(1)
|
minusOne = big.NewInt(-1)
|
||||||
|
one = big.NewInt(+1)
|
||||||
|
|
||||||
|
// sharedEmptyRange is an emtpy IntRange. Users should not modify it. It is
|
||||||
|
// not exported, directly or indirectly (by another function returning its
|
||||||
|
// elements).
|
||||||
|
sharedEmptyRange = IntRange{one, minusOne}
|
||||||
)
|
)
|
||||||
|
|
||||||
var smallBitMasks = [...]*big.Int{
|
var smallBitMasks = [...]*big.Int{
|
||||||
@@ -308,13 +314,13 @@ func (x IntRange) justZero() bool {
|
|||||||
// any negative or non-negative elements.
|
// any negative or non-negative elements.
|
||||||
func (x IntRange) split2Ways() (neg IntRange, nonNeg IntRange) {
|
func (x IntRange) split2Ways() (neg IntRange, nonNeg IntRange) {
|
||||||
if x.Empty() {
|
if x.Empty() {
|
||||||
return makeEmptyRange(), makeEmptyRange()
|
return sharedEmptyRange, sharedEmptyRange
|
||||||
}
|
}
|
||||||
if x[0] != nil && x[0].Sign() >= 0 {
|
if x[0] != nil && x[0].Sign() >= 0 {
|
||||||
return makeEmptyRange(), x
|
return sharedEmptyRange, x
|
||||||
}
|
}
|
||||||
if x[1] != nil && x[1].Sign() < 0 {
|
if x[1] != nil && x[1].Sign() < 0 {
|
||||||
return x, makeEmptyRange()
|
return x, sharedEmptyRange
|
||||||
}
|
}
|
||||||
|
|
||||||
neg[0] = x[0]
|
neg[0] = x[0]
|
||||||
@@ -337,10 +343,10 @@ func (x IntRange) split2Ways() (neg IntRange, nonNeg IntRange) {
|
|||||||
// negative or positive elements.
|
// negative or positive elements.
|
||||||
func (x IntRange) split() (neg IntRange, pos IntRange, negEmpty bool, hasZero bool, posEmpty bool) {
|
func (x IntRange) split() (neg IntRange, pos IntRange, negEmpty bool, hasZero bool, posEmpty bool) {
|
||||||
if x[0] != nil && x[0].Sign() > 0 {
|
if x[0] != nil && x[0].Sign() > 0 {
|
||||||
return makeEmptyRange(), x, true, false, x.Empty()
|
return sharedEmptyRange, x, true, false, x.Empty()
|
||||||
}
|
}
|
||||||
if x[1] != nil && x[1].Sign() < 0 {
|
if x[1] != nil && x[1].Sign() < 0 {
|
||||||
return x, makeEmptyRange(), x.Empty(), false, true
|
return x, sharedEmptyRange, x.Empty(), false, true
|
||||||
}
|
}
|
||||||
|
|
||||||
neg[0] = x[0]
|
neg[0] = x[0]
|
||||||
|
|||||||
@@ -283,8 +283,8 @@ func TestContainsEtc(tt *testing.T) {
|
|||||||
tt.Errorf("%s.Empty(): got %t, want %t", tc.s, got, want)
|
tt.Errorf("%s.Empty(): got %t, want %t", tc.s, got, want)
|
||||||
} else if !got {
|
} else if !got {
|
||||||
eqTestCases = append(eqTestCases, x)
|
eqTestCases = append(eqTestCases, x)
|
||||||
} else if !x.Eq(makeEmptyRange()) {
|
} else if !x.Eq(sharedEmptyRange) {
|
||||||
tt.Errorf("%v eq %v: got %t, want %t", x, makeEmptyRange(), got, want)
|
tt.Errorf("%v eq %v: got %t, want %t", x, sharedEmptyRange, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, want := x.justZero(), tc.s == "[ 0, 0]"; got != want {
|
if got, want := x.justZero(), tc.s == "[ 0, 0]"; got != want {
|
||||||
@@ -929,7 +929,7 @@ func TestOpAndWithZero(tt *testing.T) {
|
|||||||
x := IntRange{x0, x1}
|
x := IntRange{x0, x1}
|
||||||
want := zero
|
want := zero
|
||||||
if x.Empty() {
|
if x.Empty() {
|
||||||
want = makeEmptyRange()
|
want = sharedEmptyRange
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, _ := x.And(zero); !got.Eq(want) {
|
if got, _ := x.And(zero); !got.Eq(want) {
|
||||||
@@ -949,7 +949,7 @@ func TestOpOrWithMinusOne(tt *testing.T) {
|
|||||||
x := IntRange{x0, x1}
|
x := IntRange{x0, x1}
|
||||||
want := minusOne
|
want := minusOne
|
||||||
if x.Empty() {
|
if x.Empty() {
|
||||||
want = makeEmptyRange()
|
want = sharedEmptyRange
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, _ := x.Or(minusOne); !got.Eq(want) {
|
if got, _ := x.Or(minusOne); !got.Eq(want) {
|
||||||
|
|||||||
Reference in new issue
Block a user