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

cookie

package
v1.20.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBakery

func NewBakery[C constraints.Unsigned, V comparable](logger *slog.Logger) *bakery[C, V]

NewBakery creates a new Bakery. It manages cookies of type C for values of type V.

Types

type Bakery

type Bakery[C constraints.Unsigned, V comparable] interface {
	// Allocate returns a unique, cookie for the given value and whether a cookie could be
	// allocated or reused. A successfully allocated cookie is always non-zero. If no cookie
	// could be allocated, a zero cookie is returned. If the same value is provided again,
	// Allocate returns the previously allocated cookie for that value.
	Allocate(value V) (cookie C, ok bool)
	// Get returns the value for a given cookie and whether it exists in the bakery. If the
	// cookie doesn't exist, a zero value will be returned.
	Get(cookie C) (value V, exists bool)
	// MarkInUse marks a cookie as in-use for the next sweep.
	MarkInUse(cookie C)
	// Sweep removes all cookies not marked as in-use since the last time sweep cycle.
	Sweep()
	// Count returns the number of allocated cookies.
	Count() int
}

Bakery allocates unique unsigned integer cookies of type C for a comparable value of type. It allows looking up the value for a given cookie and mark-and-sweep garbage collection.

Jump to

Keyboard shortcuts

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