File: bisect.go

package info (click to toggle)
golang-github-c-bata-go-prompt 0.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 396 kB
  • sloc: makefile: 37; python: 13; sh: 9
file content (15 lines) | stat: -rw-r--r-- 327 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package bisect

import "sort"

// Right to locate the insertion point for v in a to maintain sorted order.
func Right(a []int, v int) int {
	return bisectRightRange(a, v, 0, len(a))
}

func bisectRightRange(a []int, v int, lo, hi int) int {
	s := a[lo:hi]
	return sort.Search(len(s), func(i int) bool {
		return s[i] > v
	})
}