Help us shape the future of Go! Take the 2026 Go Developer Survey

downsample

package
v1.1.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocateTargets

func AllocateTargets[K comparable](groups []AllocationGroup[K], maxTotal int) map[K]int

AllocateTargets splits maxTotal across groups proportionally to their lengths, using largest-remainder rounding so the allocation sums exactly to maxTotal (or to the sum of group lengths, whichever is smaller). A negative maxTotal means "unlimited": every group keeps its full length.

func SampleEvenly

func SampleEvenly[T any](in []T, k int) []T

SampleEvenly returns k elements of in, spaced as evenly as possible across its full span (always including the first and last element when k >= 2). It returns in unchanged when k >= len(in), and an empty slice when k <= 0.

Types

type AllocationGroup

type AllocationGroup[K comparable] struct {
	Key    K
	Length int
}

AllocationGroup is one group of records competing for a share of a fixed total point budget in AllocateTargets.

Jump to

Keyboard shortcuts

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