summaryrefslogtreecommitdiff
path: root/lib/slices
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-17 20:26:52 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-17 22:41:05 -0600
commit273890421b31aa7b43d778e4da3de16659e77d73 (patch)
treea46cd884fe2132a6c69d7d1f9c8ddc84509b4afa /lib/slices
parent6fc662d5faa238cc71d06c2c888858747c55c55a (diff)
tools: Upgrade to Go 1.19
1. Edit Makefile:goversion 2. Run `make go-mod-tidy` 3. Run `gofmt -s -w .` 4. Look at the ignore-whitespace-change diff and fixup band gofmt changes
Diffstat (limited to 'lib/slices')
-rw-r--r--lib/slices/sliceutil.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/slices/sliceutil.go b/lib/slices/sliceutil.go
index f95c7e7..567f9ec 100644
--- a/lib/slices/sliceutil.go
+++ b/lib/slices/sliceutil.go
@@ -95,15 +95,15 @@ func max(a, b int) int {
// Search the slice for a value for which `fn(slice[i]) = 0`.
//
-// + + + 0 0 0 - - -
-// ^ ^ ^
-// any of
+// : + + + 0 0 0 - - -
+// : ^ ^ ^
+// : any of
//
// You can conceptualize `fn` as subtraction:
//
-// func(straw T) int {
-// return needle - straw
-// }
+// func(straw T) int {
+// return needle - straw
+// }
func Search[T any](slice []T, fn func(T) int) (int, bool) {
beg, end := 0, len(slice)
for beg < end {
@@ -123,14 +123,14 @@ func Search[T any](slice []T, fn func(T) int) (int, bool) {
// Search the slice for the left-most value for which `fn(slice[i]) = 0`.
//
-// + + + 0 0 0 - - -
-// ^
+// : + + + 0 0 0 - - -
+// : ^
//
// You can conceptualize `fn` as subtraction:
//
-// func(straw T) int {
-// return needle - straw
-// }
+// func(straw T) int {
+// return needle - straw
+// }
func SearchLowest[T any](slice []T, fn func(T) int) (int, bool) {
lastBad, firstGood, firstBad := -1, len(slice), len(slice)
for lastBad+1 < min(firstGood, firstBad) {
@@ -153,14 +153,14 @@ func SearchLowest[T any](slice []T, fn func(T) int) (int, bool) {
// Search the slice for the right-most value for which `fn(slice[i]) = 0`.
//
-// + + + 0 0 0 - - -
-// ^
+// : + + + 0 0 0 - - -
+// : ^
//
// You can conceptualize `fn` as subtraction:
//
-// func(straw T) int {
-// return needle - straw
-// }
+// func(straw T) int {
+// return needle - straw
+// }
func SearchHighest[T any](slice []T, fn func(T) int) (int, bool) {
lastBad, lastGood, firstBad := -1, -1, len(slice)
for max(lastBad, lastGood)+1 < firstBad {