randommap

package
v0.0.0-...-c635e59 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0, BSD-2-Clause Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RandomMap

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

RandomMap defines a map with extended ability to return a random entry.

func New

func New[K comparable, V any](opts ...shrinkingmap.Option) *RandomMap[K, V]

New creates a new random map.

func (*RandomMap[K, V]) Delete

func (r *RandomMap[K, V]) Delete(key K) (value V, deleted bool)

Delete removes the mapping for the specified key in the map.

func (*RandomMap[K, V]) ForEach

func (r *RandomMap[K, V]) ForEach(consumer func(key K, value V) bool)

ForEach iterates through the elements in the map and calls the consumer function for each element.

func (*RandomMap[K, V]) Get

func (r *RandomMap[K, V]) Get(key K) (result V, exists bool)

Get returns the value to which the specified key is mapped.

func (*RandomMap[K, V]) Has

func (r *RandomMap[K, V]) Has(key K) bool

Has returns a boolean value indicating whether it exists in the map.

func (*RandomMap[K, V]) Keys

func (r *RandomMap[K, V]) Keys() (result []K)

Keys returns the list of keys stored in the RandomMap.

func (*RandomMap[K, V]) RandomEntry

func (r *RandomMap[K, V]) RandomEntry() (defaultValue V, exists bool)

RandomEntry returns a random value from the map.

func (*RandomMap[K, V]) RandomKey

func (r *RandomMap[K, V]) RandomKey() (defaultValue K, exists bool)

RandomKey returns a random key from the map.

func (*RandomMap[K, V]) RandomUniqueEntries

func (r *RandomMap[K, V]) RandomUniqueEntries(count int) (results []V)

RandomUniqueEntries returns n random and unique values from the map. When count is equal or bigger than the size of the random map, the every entry in the map is returned.

func (*RandomMap[K, V]) Set

func (r *RandomMap[K, V]) Set(key K, value V)

Set associates the specified value with the specified key. If the association already exists, it updates the value.

func (*RandomMap[K, V]) Size

func (r *RandomMap[K, V]) Size() int

Size returns the number of key-value mappings in the map.

func (*RandomMap[K, V]) Values

func (r *RandomMap[K, V]) Values() (result []V)

Values returns the list of values stored in the RandomMap.

Jump to

Keyboard shortcuts

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