sortutil

package
v1.0.0-rc3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryInsert

func BinaryInsert[T any](l *[]T, cmp func(entry T) int) (entry *T, added bool)

BinaryInsert uses Search to find the smallest index i in [0, len(l)) at which cmp(l[i]) ≥ 0. If i ≥ len(l), an empty entry is appended. Otherwise an empty entry is inserted at i unless cmp == 0. BinaryInsert returns l, the address of l[i], and whether a new entry was added.

func RemoveAt

func RemoveAt[T any](l *[]T, i int)

RemoveAt removes the specified element.

func Search[T any](l []T, cmp func(entry T) int) (index int, found bool)

Search uses a binary search to find and return the smallest index i in [0, len(l)) at which cmp(l[i]) ≥ 0, assuming that on the range [0, len(l)), cmp(l[i]) ≥ 0 implies cmp(l[i+1]) ≥ 0. That is, Search requires that cmp ≥ 0 for some (possibly empty) prefix of the input range [0, len(l)) and then < 0 for the (possibly empty) remainder; Search returns the first ≥ 0 index and whether cmp == 0 for that index. If there is no such index, Search returns len(l), false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL