pool

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 2 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 pool implements bounded power-of-two object size classes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CeilToPowerOfTwo

func CeilToPowerOfTwo(n int) int

CeilToPowerOfTwo returns the least power of two integer value greater than or equal to n.

func FloorToPowerOfTwo

func FloorToPowerOfTwo(n int) int

FloorToPowerOfTwo returns the greatest power of two integer value less than or equal to n.

func Identity

func Identity(n int) int

Identity is identity.

func IsPowerOfTwo

func IsPowerOfTwo(n int) bool

IsPowerOfTwo reports whether given integer is a power of two.

func LogarithmicRange

func LogarithmicRange(start, end int, cb func(int))

LogarithmicRange iterates from the ceiled power-of-two start to end, calling cb on each iteration.

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

Types

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool reuses objects in power-of-two size classes up to a configured maximum. It does not retain oversized objects.

func New

func New[T any](capacity int) *Pool[T]

New creates a size-classed pool whose largest retained object is capacity.

func (*Pool[T]) Get

func (p *Pool[T]) Get(size int) (T, int)

Get pulls object whose generic size is at least of given size. It also returns a real size of x for further pass to Put() even if x is nil. Pooled sizes are rounded to the next power of two; larger requests retain their exact size because they are not pooled.

func (*Pool[T]) Put

func (p *Pool[T]) Put(x T, size int)

Put retains x only when size names one of this pool's exact size classes.

Jump to

Keyboard shortcuts

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