syncmap

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: Apache-2.0 Imports: 1 Imported by: 4 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package syncmap provides a very small, generic wrapper around Go’s built-in map type guarded by a sync.RWMutex.

It trades a little indirection for convenience when a concurrent, goroutine safe map is needed but the full feature set (and memory cost) of `sync.Map` is not justified.

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
}

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) Delete

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

func (*Map[K, V]) Get

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

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(k K, v V)

func (*Map[K, V]) Range

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

func (*Map[K, V]) Size added in v0.3.1

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

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() []V

type OrderedMap

type OrderedMap[T any] struct {
	*Map[string, T] // Holds a collection of prompts indexed by their names
	Keys            []string
}

OrderedMap is a generic collection type that holds items of type T indexed by string names

func NewOrderedMap

func NewOrderedMap[T any]() *OrderedMap[T]

func (*OrderedMap[T]) Add

func (c *OrderedMap[T]) Add(key string, item T) bool

Add adds a new item to the collection, if the name already exists it will overwrite the existing item

func (*OrderedMap[T]) Get

func (c *OrderedMap[T]) Get(name string) (T, bool)

Get retrieves an item from the collection by its name.

Jump to

Keyboard shortcuts

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