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 ¶
- Variables
- type Freezable
- func (r *Freezable[K, V]) Clone() *Freezable[K, V]
- func (r *Freezable[K, V]) Contains(k K) bool
- func (r *Freezable[K, V]) Freeze()
- func (r *Freezable[K, V]) Get(k K) (V, bool)
- func (r *Freezable[K, V]) IsFrozen() bool
- func (r *Freezable[K, V]) Keys() []K
- func (r *Freezable[K, V]) Len() int
- func (r *Freezable[K, V]) Put(k K, v V) error
- func (r *Freezable[K, V]) Remove(k K) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
Clone copies current entries into an independent, unfrozen registry.
func (*Freezable[K, V]) Contains ¶
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 ¶
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]) Keys ¶
func (r *Freezable[K, V]) Keys() []K
Keys returns keys in map iteration order; callers may sort for deterministic output.