Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinarySearcher ¶
type BinarySearcher[V any] struct { // contains filtered or unexported fields }
BinarySearcher searches element from a slice of non decreasing elements.
func NewBinarySearcher ¶
func NewBinarySearcher[V any](compare func(v1, v2 V) int) *BinarySearcher[V]
NewBinarySearcher creates a BinarySearcher using the compare function.
func (*BinarySearcher[V]) LowerBound ¶
func (s *BinarySearcher[V]) LowerBound(elements []V, first int, last int, val V) int
LowerBound finds the leftmost position such that the element at the position is larger than or equal to val. Imagine we'd insert val to the sorted slice and keep the slice sorted, the returned position is the lower bound where we can insert. The range is half close [first, last). Return last if all elements are less than val.
func (*BinarySearcher[V]) UpperBound ¶
func (s *BinarySearcher[V]) UpperBound(elements []V, first int, last int, val V) int
UpperBound finds the leftmost position such that the element at the position is larger than val. Imagine we'd insert val to the sorted slice and keep the slice sorted, the returned position is the upper bound where we can insert. The range is half close [first, last). Return last if all elements are less than or equal to val.