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

boundedmap

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package boundedmap is a map with a capacity: once full, putting a new key evicts the least recently used one. Plugins that keep per-principal or per-address state in memory use it so that state cannot grow without bound over the life of a process.

A Map is not safe for concurrent use; callers hold their own lock, as they already did around the plain maps this replaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map holds at most capacity entries in least-recently-used order.

func New

func New[K comparable, V any](capacity int) *Map[K, V]

New returns an empty map that holds at most capacity entries. A capacity of zero or less means no bound, for callers that opt out.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete removes key. Deleting an absent key does nothing.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (V, bool)

Get returns the value under key and marks it recently used.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns how many entries the map holds.

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(key K, value V)

Put stores value under key as the most recently used entry, evicting the least recently used one when the map is full.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(fn func(key K, value V) bool)

Range calls fn for each entry, most recently used first, until fn returns false. fn must not modify the map.

Jump to

Keyboard shortcuts

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