store

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KV

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

KV is a thread-safe, generic key-value store.

func NewKV

func NewKV[K comparable, V any]() *KV[K, V]

NewKV initializes and returns a new generic KV store.

func (*KV[K, V]) Clear

func (s *KV[K, V]) Clear()

Clear removes all keys and resets the inner map.

func (*KV[K, V]) Delete

func (s *KV[K, V]) Delete(key K)

Delete removes a key-value pair from the store.

func (*KV[K, V]) DeleteIf

func (s *KV[K, V]) DeleteIf(key K, expected V) bool

DeleteIf removes key only when the stored value equals expected (same lock). Returns true if the key was deleted.

V must be comparable at runtime (e.g. pointers, strings, ints). Comparing non-comparable values (slices, maps, funcs) panics — same as Go interface ==.

func (*KV[K, V]) Get

func (s *KV[K, V]) Get(key K) (V, bool)

Get retrieves a value by key.

func (*KV[K, V]) Keys

func (s *KV[K, V]) Keys() []K

Keys returns all keys in the store.

func (*KV[K, V]) Len

func (s *KV[K, V]) Len() int

Len returns the current count of items stored.

func (*KV[K, V]) Pop

func (s *KV[K, V]) Pop(key K) (V, bool)

Pop atomically retrieves and deletes a key-value pair in a single lock step.

func (*KV[K, V]) Set

func (s *KV[K, V]) Set(key K, value V)

Set adds or updates a key-value pair.

Jump to

Keyboard shortcuts

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