cmap

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cmap provides a concurrent map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteFunc

type DeleteFunc[K comparable, V any] func(value V, exists bool) bool

DeleteFunc is a function to delete a value from the map.

type Map

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

Map is a concurrent map that is safe for multiple routines. It is optimized to reduce lock contention and improve performance.

func New

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

New creates a new Map.

func (*Map[K, V]) Delete

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

Delete removes a value from the map.

func (*Map[K, V]) Get

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

Get retrieves a value from the map.

func (*Map[K, V]) Has

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

Has checks if a key exists in the map

func (*Map[K, V]) Keys

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

Keys returns a slice of all keys in the map

func (*Map[K, V]) Len

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

Len returns the number of items in the map

func (*Map[K, V]) Set

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

Set sets a key-value pair.

func (*Map[K, V]) Upsert

func (m *Map[K, V]) Upsert(key K, upsertFunc UpsertFunc[K, V]) V

Upsert inserts or updates a key-value pair.

func (*Map[K, V]) Values

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

Values returns a slice of all values in the map

type UpsertFunc

type UpsertFunc[K comparable, V any] func(value V, exists bool) V

UpsertFunc is a function to insert or update a key-value pair.

Jump to

Keyboard shortcuts

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