reuse

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reuse provides operations on reusable scratch storage.

Index

Constants

View Source
const RetentionFrames = 30

Variables

This section is empty.

Functions

func Compact

func Compact[T any](values []T, minimum int) []T

Compact is used once a containing owner's retention window has expired.

func Reset

func Reset[T any](values []T, maxCapacity int) []T

Reset clears references throughout the backing array and keeps bounded scratch storage. Oversized arrays are released instead of retained in a pool.

func Resize

func Resize[T any](values []T, length int) []T

Resize reuses storage when capacity permits. Growth starts with zeroed values; callers fill the result rather than relying on old contents after growth.

func UpdateAt

func UpdateAt[T comparable](values *[]T, index int, value T) bool

UpdateAt appends or replaces the next observed value and reports a change. Callers visit indices in order and truncate the slice after the last value.

Types

type MapRetention

type MapRetention struct {
	// contains filtered or unexported fields
}

MapRetention tracks the largest live population because Go maps expose no capacity. Rebuilding after sustained underuse releases historical buckets.

func (*MapRetention) Record

func (r *MapRetention) Record(length int)

func (*MapRetention) Trim

func (r *MapRetention) Trim[K comparable, V any](values map[K]V, minimum int) map[K]V

type Retention

type Retention struct {
	// contains filtered or unexported fields
}

Retention releases historical peaks after sustained underuse. Record folds multiple batches into one observation; Trim observes once per completed frame.

func (*Retention) Record

func (r *Retention) Record(length int)

func (*Retention) Trim

func (r *Retention) Trim[T any](values []T, minimum int) []T

Trim preserves live values and keeps twice the recent peak, with a small capacity floor. Empty, unused storage is released entirely.

func (*Retention) TrimCapacity

func (r *Retention) TrimCapacity(capacity, length, minimum int) int

TrimCapacity returns zero while storage stays warm, -1 when idle storage can be released, or a smaller capacity after sustained underuse.

Jump to

Keyboard shortcuts

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