maps

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetToSlice

func SetToSlice[V comparable](m map[V]struct{}) []V

SetToSlice returns a slice containing the keys of the provided Set/map

func SliceToSet

func SliceToSet[V comparable](s []V) map[V]struct{}

SliceToSet returns a Set/map whose keys are formed by the values in the slice argument. It will deduplicate any repeated value in the slice

Types

type Bits

type Bits uint

Bits wraps an unsigned integer that can be used as a bit map

func MappedBits

func MappedBits[T comparable](values []T, maps map[T]Bits, opts ...BuilderOpt[T]) Bits

MappedBits builds a Bits map from a set of values (e.g. strings) that are mapped in the form value --> corresponding Bits value in the "maps" constructor argument

func (Bits) Has

func (i Bits) Has(value Bits) bool

Has returns true if the map contains all the value Bits passed as argument

type BuilderOpt

type BuilderOpt[T any] func(*builderOpts[T])

BuilderOpt allows defining option for building Bits map in the MappedBits method

func WithTransform

func WithTransform[T any](transformFunc func(T) T) BuilderOpt[T]

WithTransform will apply the provided transformer function to the passed key values in the MappedBits constructor function

type Map2

type Map2[K1, K2 comparable, V any] map[K1]map[K2]V

Map2 implements a 2-level map where each 1st-level key maps to a 2nd level map.

func (Map2[K1, K2, V]) Delete

func (m Map2[K1, K2, V]) Delete(key1 K1, key2 K2)

func (Map2[K1, K2, V]) DeleteAll

func (m Map2[K1, K2, V]) DeleteAll(key1 K1)

DeleteAll the 2nd-level entries associated with the 1st-level key.

func (Map2[K1, K2, V]) Get

func (m Map2[K1, K2, V]) Get(key1 K1, key2 K2) (V, bool)

func (Map2[K1, K2, V]) Put

func (m Map2[K1, K2, V]) Put(key1 K1, key2 K2, val V)

type MultiCounter

type MultiCounter[K comparable] map[K]*int

MultiCounter maps a counter to a given key

func (MultiCounter[K]) Dec

func (m MultiCounter[K]) Dec(key K) int

Dec decrements the counter associated to the given key and returns the new count.

func (MultiCounter[K]) Inc

func (m MultiCounter[K]) Inc(key K) int

Inc increments the counter associated to the given key and returns the new count.

Jump to

Keyboard shortcuts

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