pool

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 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

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 contains logic of reusing objects distinguishable by size in generic way.

func New

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

New creates new Pool that reuses objects which size

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 takes x and its size for future reuse.

Jump to

Keyboard shortcuts

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