safenum

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 1 Imported by: ? 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 safenum provides small overflow-safe numeric helpers, primarily for sizing make() capacity hints from untrusted or accumulated lengths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cap

func Cap(a, b, max int) int

Cap returns a safe make() capacity hint for a+b, clamped to max so the addition can never overflow int and the hint never requests an absurd up-front allocation. Negative inputs are treated as zero.

The size argument to make() is only a capacity hint -- append() still grows the backing array as needed -- so clamping the hint below the true a+b never changes program behavior, it only avoids an oversized allocation. Callers that must refuse to proceed entirely above some size (rather than just allocate conservatively and let append grow it) need their own guard; see pkg/merge.processAppendList for that different, deliberate semantic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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