registry

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Overview

Freezable shared registries (H07) optimize read-heavy post-startup access. Before Freeze, reads and writes use a mutex for dynamic registration. Freeze irreversibly publishes an immutable snapshot; Get, Contains, Len, and Keys then read immutable entries after obtaining the snapshot under a read lock. Put and Remove reject subsequent writes with ErrFrozen.

Index

Constants

This section is empty.

Variables

View Source
var ErrFrozen = errors.New("registry: frozen, mutation not allowed")

ErrFrozen indicates that a frozen registry rejects writes.

Functions

This section is empty.

Types

type Freezable

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

Freezable is a generic shared registry that can become immutable.

func NewFreezable

func NewFreezable[K comparable, V any]() *Freezable[K, V]

NewFreezable creates an empty registry.

func NewFreezableFrom

func NewFreezableFrom[K comparable, V any](entries map[K]V) *Freezable[K, V]

NewFreezableFrom copies the supplied map to avoid sharing its backing table.

func (*Freezable[K, V]) Clone

func (r *Freezable[K, V]) Clone() *Freezable[K, V]

Clone copies current entries into an independent, unfrozen registry.

func (*Freezable[K, V]) Contains

func (r *Freezable[K, V]) Contains(k K) bool

Contains checks key presence, acquiring the frozen snapshot under RLock.

func (*Freezable[K, V]) Freeze

func (r *Freezable[K, V]) Freeze()

Freeze irreversibly publishes a read-only snapshot. Writes return ErrFrozen and reads acquire the snapshot under RLock before accessing its immutable entries. Repeated calls are safe.

func (*Freezable[K, V]) Get

func (r *Freezable[K, V]) Get(k K) (V, bool)

Get obtains the snapshot under RLock, then reads its immutable entries. Before freezing, it reads the mutable map under a read lock.

func (*Freezable[K, V]) IsFrozen

func (r *Freezable[K, V]) IsFrozen() bool

IsFrozen reports whether the registry is frozen.

func (*Freezable[K, V]) Keys

func (r *Freezable[K, V]) Keys() []K

Keys returns keys in map iteration order; callers may sort for deterministic output.

func (*Freezable[K, V]) Len

func (r *Freezable[K, V]) Len() int

Len returns the entry count.

func (*Freezable[K, V]) Put

func (r *Freezable[K, V]) Put(k K, v V) error

Put inserts or replaces an entry, returning ErrFrozen after freezing.

func (*Freezable[K, V]) Remove

func (r *Freezable[K, V]) Remove(k K) error

Remove deletes an entry, returning ErrFrozen after freezing.

Jump to

Keyboard shortcuts

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