Skip to content

Commit

Permalink
fix(vt): remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 20, 2024
1 parent 1226e90 commit 83343c3
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions vt/utils.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
package vt

import (
"cmp"
)

// binarySearch searches for target in a sorted slice and returns the earliest
// position where target is found, or the position where target would appear
// in the sort order; it also returns a bool saying whether the target is
// really found in the slice. The slice must be sorted in increasing order.
//
// Copied from the Go standard library's sort.go.
// TODO: Use [slices.BinarySearch] instead after updating the Go version.
func binarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool) {
// Inlining is faster than calling BinarySearchFunc with a lambda.
n := len(x)
// Define x[-1] < target and x[n] >= target.
// Invariant: x[i-1] < target, x[j] >= target.
i, j := 0, n
for i < j {
h := int(uint(i+j) >> 1) // avoid overflow when computing h
// i ≤ h < j
if cmp.Less(x[h], target) {
i = h + 1 // preserves x[i-1] < target
} else {
j = h // preserves x[j] >= target
}
}
// i == j, x[i-1] < target, and x[j] (= x[i]) >= target => answer is i.
return i, i < n && (x[i] == target || (isNaN(x[i]) && isNaN(target)))
}

// isNaN reports whether x is a NaN without requiring the math package.
// This will always return false if T is not floating-point.
func isNaN[T cmp.Ordered](x T) bool {
return x != x
}

func max(a, b int) int {
func max(a, b int) int { //nolint:predeclared
if a > b {
return a
}
return b
}

func min(a, b int) int {
func min(a, b int) int { //nolint:predeclared
if a > b {
return b
}
Expand Down

0 comments on commit 83343c3

Please sign in to comment.