randommap

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: Apache-2.0, BSD-2-Clause Imports: 1 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 {
	*randommap.RandomMap
}

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

func New

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

New creates a new random map

func (*RandomMap[K, V]) Delete

func (rmap *RandomMap[K, V]) Delete(key K) (result V, exists bool)

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

func (*RandomMap[K, V]) ForEach

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

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

func (*RandomMap[K, V]) Get

func (rmap *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]) Keys

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

Keys returns the list of keys stored in the RandomMap.

func (*RandomMap[K, V]) RandomEntry

func (rmap *RandomMap[K, V]) RandomEntry() (result V, exists bool)

RandomEntry returns a random value from the map.

func (*RandomMap[K, V]) RandomKey

func (rmap *RandomMap[K, V]) RandomKey() (result K, exists bool)

RandomKey returns a random key from the map.

func (*RandomMap[K, V]) RandomUniqueEntries

func (rmap *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 (rmap *RandomMap[K, V]) Set(key K, value V) (updated bool)

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

Jump to

Keyboard shortcuts

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