Documentation ¶
Index ¶
- func BinarySearch(slice []int, toFind int) int
- func BinarySearchFunc(eval func(int) int, end int, toFind int) int
- func InvertPermutation(permutation []int) []int
- func Map[T, S any](in []T, f func(T) S) []S
- func MapAt[K comparable, V any](mp map[K]V) func(K) V
- func MapRange[S any](begin, end int, f func(int) S) []S
- func Permute[T any](slice []T, permutation []int)
- func SliceAt[T any](slice []T) func(int) T
- func SlicePtrAt[T any](slice []T) func(int) *T
- func TopologicalSort(inputs [][]int) (sorted []int, uniqueOutputs [][]int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
BinarySearch looks for toFind in a sorted slice, and returns the index at which it either is or would be were it to be inserted.
func BinarySearchFunc ¶
BinarySearchFunc looks for toFind in an increasing function of domain 0 ... (end-1), and returns the index at which it either is or would be were it to be inserted.
func InvertPermutation ¶
InvertPermutation input permutation must contain exactly 0, ..., len(permutation)-1
func MapAt ¶
func MapAt[K comparable, V any](mp map[K]V) func(K) V
func Permute ¶
Permute operates in-place but is not thread-safe; it uses the permutation for scratching permutation[i] signifies which index slice[i] is going to
func SlicePtrAt ¶
func TopologicalSort ¶
TopologicalSort takes a list of lists of dependencies and proposes a sorting of the lists in order of dependence. Such that for any wire, any one it depends on occurs before it. It tries to stick to the input order as much as possible. An already sorted list will remain unchanged. As a bonus, it returns for each list its "unique" outputs. That is, a list of its outputs with no duplicates. Worst-case inefficient O(n^2), but that probably won't matter since the circuits are small. Furthermore, it is efficient with already-close-to-sorted lists, which are the expected input. If performance was bad, consider using a heap for finding the value "leastReady". WARNING: Due to the current implementation of intSet, it is ALWAYS O(n^2).
Types ¶
This section is empty.