Skip to content

Commit

Permalink
Merge pull request #8719 from Juneezee/refactor/minmax
Browse files Browse the repository at this point in the history
Replace min/max helpers with built-in min/max
  • Loading branch information
macneale4 authored Jan 9, 2025
2 parents 80ad9a2 + 0515265 commit 0cbfe0e
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 248 deletions.
3 changes: 1 addition & 2 deletions go/libraries/doltcore/schema/typeinfo/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
Expand Down
10 changes: 1 addition & 9 deletions go/libraries/doltcore/sqle/index/dolt_map_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions go/libraries/doltcore/table/untyped/tabular/stringwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions go/libraries/utils/iohelp/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
}

Expand Down
114 changes: 0 additions & 114 deletions go/libraries/utils/mathutil/max.go

This file was deleted.

65 changes: 0 additions & 65 deletions go/libraries/utils/mathutil/max_test.go

This file was deleted.

9 changes: 0 additions & 9 deletions go/store/blobstore/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 0 additions & 14 deletions go/store/cmd/noms/noms_cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions go/store/types/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 3 additions & 23 deletions go/store/types/edit_distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0cbfe0e

Please sign in to comment.