mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-04 18:49:00 -06:00
Merge pull request #8719 from Juneezee/refactor/minmax
Replace min/max helpers with built-in min/max
This commit is contained in:
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/vitess/go/sqltypes"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/utils/mathutil"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -184,7 +183,7 @@ func mustBlobBytes(t *testing.T, b []byte) types.Blob {
|
||||
func loop(t *testing.T, start int64, endInclusive int64, numOfSteps uint16, loopedFunc func(int64)) {
|
||||
require.True(t, endInclusive > start)
|
||||
maxNumOfSteps := endInclusive - start + 1
|
||||
trueNumOfSteps := mathutil.MinInt64(int64(numOfSteps), maxNumOfSteps) - 1
|
||||
trueNumOfSteps := min(int64(numOfSteps), maxNumOfSteps) - 1
|
||||
inc := float64(maxNumOfSteps) / float64(trueNumOfSteps)
|
||||
fCurrentVal := float64(start)
|
||||
currentVal := int64(math.Round(fCurrentVal))
|
||||
|
||||
@@ -25,14 +25,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
func maxU64(x, y uint64) uint64 {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
// KVToSqlRowConverter takes noms types.Value key value pairs and converts them directly to a sql.Row. It
|
||||
// can be configured to only process a portion of the columns and map columns to desired output columns.
|
||||
type KVToSqlRowConverter struct {
|
||||
@@ -73,7 +65,7 @@ func getValLocations(tagToSqlColIdx map[uint64]int, cols []schema.Column) (int,
|
||||
fromKey++
|
||||
} else {
|
||||
fromVal++
|
||||
maxValTag = maxU64(maxValTag, col.Tag)
|
||||
maxValTag = max(maxValTag, col.Tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +101,3 @@ func ColoredStringWidth(coloredText string, uncoloredText string) FixedWidthStri
|
||||
}
|
||||
return uncolored
|
||||
}
|
||||
|
||||
func min(x, y int) int {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/utils/mathutil"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/osutil"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/test"
|
||||
)
|
||||
@@ -150,7 +149,7 @@ func (gen *FixedRateDataGenerator) Read(p []byte) (int, error) {
|
||||
case <-time.After(nextRead):
|
||||
gen.dataGenerated += uint64(gen.BytesPerInterval)
|
||||
gen.lastRead = time.Now()
|
||||
return mathutil.Min(gen.BytesPerInterval, len(p)), nil
|
||||
return min(gen.BytesPerInterval, len(p)), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
// Copyright 2019 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package mathutil
|
||||
|
||||
var Max = MaxInt // alias
|
||||
var Min = MinInt // alias
|
||||
|
||||
func MaxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinInt(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MaxInt64(a, b int64) int64 {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinInt64(a, b int64) int64 {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MaxUint(a, b uint) uint {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinUint(a, b uint) uint {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MaxUint64(a, b uint64) uint64 {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinUint64(a, b uint64) uint64 {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MaxFloat(a, b float32) float32 {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinFloat(a, b float32) float32 {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MaxFloat64(a, b float64) float64 {
|
||||
if a > b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
func MinFloat64(a, b float64) float64 {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2019 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package mathutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMax(t *testing.T) {
|
||||
if MaxInt(1, 2) != 2 || MaxInt(2, 1) != 2 {
|
||||
t.Error("MaxInt error")
|
||||
}
|
||||
if Max(1, 2) != 2 || Max(2, 1) != 2 {
|
||||
t.Error("Max error")
|
||||
}
|
||||
if MaxInt64(1, 2) != 2 || MaxInt64(2, 1) != 2 {
|
||||
t.Error("MaxInt64 error")
|
||||
}
|
||||
if MaxFloat(1, 2) != 2 || MaxFloat(2, 1) != 2 {
|
||||
t.Error("MaxFloat error")
|
||||
}
|
||||
if MaxFloat64(1, 2) != 2 || MaxFloat64(2, 1) != 2 {
|
||||
t.Error("MaxFloat64 error")
|
||||
}
|
||||
if MaxUint(1, 2) != 2 || MaxUint(2, 1) != 2 {
|
||||
t.Error("MaxUint error")
|
||||
}
|
||||
if MaxUint64(1, 2) != 2 || MaxUint64(2, 1) != 2 {
|
||||
t.Error("MaxUint error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMin(t *testing.T) {
|
||||
if MinInt(1, 2) != 1 || MinInt(2, 1) != 1 {
|
||||
t.Error("MinInt error")
|
||||
}
|
||||
if Min(1, 2) != 1 || Min(2, 1) != 1 {
|
||||
t.Error("Min error")
|
||||
}
|
||||
if MinInt64(1, 2) != 1 || MinInt64(2, 1) != 1 {
|
||||
t.Error("MinInt64 error")
|
||||
}
|
||||
if MinFloat(1, 2) != 1 || MinFloat(2, 1) != 1 {
|
||||
t.Error("MinFloat error")
|
||||
}
|
||||
if MinFloat64(1, 2) != 1 || MinFloat64(2, 1) != 1 {
|
||||
t.Error("MinFloat64 error")
|
||||
}
|
||||
if MinUint(1, 2) != 1 || MinUint(2, 1) != 1 {
|
||||
t.Error("MaxUint error")
|
||||
}
|
||||
if MinUint64(1, 2) != 1 || MinUint64(2, 1) != 1 {
|
||||
t.Error("MaxUint error")
|
||||
}
|
||||
}
|
||||
@@ -232,12 +232,3 @@ func (bs *GCSBlobstore) composeObjects(ctx context.Context, composite string, so
|
||||
func fmtGeneration(g int64) string {
|
||||
return strconv.FormatInt(g, 16)
|
||||
}
|
||||
|
||||
func min(l, r int) (m int) {
|
||||
if l < r {
|
||||
m = l
|
||||
} else {
|
||||
m = r
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -342,20 +342,6 @@ func hexStr(bytes []byte) string {
|
||||
|
||||
const bytesPerRow = 16
|
||||
|
||||
func max(i, j int) int {
|
||||
if i > j {
|
||||
return i
|
||||
}
|
||||
return j
|
||||
}
|
||||
|
||||
func min(i, j int) int {
|
||||
if i < j {
|
||||
return i
|
||||
}
|
||||
return j
|
||||
}
|
||||
|
||||
func hexView(bytes []byte, indent string) string {
|
||||
str := ""
|
||||
for i := 0; i < len(bytes); i += bytesPerRow {
|
||||
|
||||
@@ -29,8 +29,6 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/utils/mathutil"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/atomicerr"
|
||||
"github.com/dolthub/dolt/go/store/d"
|
||||
)
|
||||
@@ -81,7 +79,7 @@ func (b Blob) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValua
|
||||
var b2Array [maxSliceSize]byte
|
||||
length := uint64(0)
|
||||
for i := uint64(0); i < minBlobLength; i += length {
|
||||
length = mathutil.MinUint64(maxSliceSize, minBlobLength-i)
|
||||
length = min(maxSliceSize, minBlobLength-i)
|
||||
b1Data := b1Array[:length]
|
||||
b2Data := b2Array[:length]
|
||||
n1, err := b1Reader.Read(b1Data)
|
||||
|
||||
@@ -54,26 +54,6 @@ func (s Splice) String() string {
|
||||
return fmt.Sprintf("[%d, %d, %d, %d]", s.SpAt, s.SpRemoved, s.SpAdded, s.SpFrom)
|
||||
}
|
||||
|
||||
func uint64Min(a, b uint64) uint64 {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func uint64Min3(a, b, c uint64) uint64 {
|
||||
if a < b {
|
||||
if a < c {
|
||||
return a
|
||||
}
|
||||
} else {
|
||||
if b < c {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func reverse(numbers []uint64) []uint64 {
|
||||
newNumbers := make([]uint64, len(numbers))
|
||||
for i := 0; i < len(numbers); i++ {
|
||||
@@ -91,7 +71,7 @@ func addSplice(splices []Splice, s Splice) []Splice {
|
||||
}
|
||||
|
||||
func calcSplices(previousLength uint64, currentLength uint64, maxSpliceMatrixSize uint64, eqFn EditDistanceEqualsFn) ([]Splice, error) {
|
||||
minLength := uint64Min(previousLength, currentLength)
|
||||
minLength := min(previousLength, currentLength)
|
||||
prefixCount, err := sharedPrefix(eqFn, minLength)
|
||||
|
||||
if err != nil {
|
||||
@@ -227,7 +207,7 @@ func calcEditDistances(eqFn EditDistanceEqualsFn, previousStart uint64, previous
|
||||
} else {
|
||||
north := distances[i-1][j] + 1
|
||||
west := distances[i][j-1] + 1
|
||||
distances[i][j] = uint64Min(north, west)
|
||||
distances[i][j] = min(north, west)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +235,7 @@ func operationsFromEditDistances(distances [][]uint64) []uint64 {
|
||||
west := distances[i-1][j]
|
||||
north := distances[i][j-1]
|
||||
|
||||
minValue := uint64Min3(west, north, northWest)
|
||||
minValue := min(west, north, northWest)
|
||||
|
||||
if minValue == northWest {
|
||||
if northWest == current {
|
||||
|
||||
Reference in New Issue
Block a user