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.
Click to show internal directories.
Click to hide internal directories.