Documentation ¶
Index ¶
- type RandomMap
- func (r *RandomMap[K, V]) Delete(key K) (value V, deleted bool)
- func (r *RandomMap[K, V]) ForEach(consumer func(key K, value V) bool)
- func (r *RandomMap[K, V]) Get(key K) (result V, exists bool)
- func (r *RandomMap[K, V]) Has(key K) bool
- func (r *RandomMap[K, V]) Keys() (result []K)
- func (r *RandomMap[K, V]) RandomEntry() (defaultValue V, exists bool)
- func (r *RandomMap[K, V]) RandomKey() (defaultValue K, exists bool)
- func (r *RandomMap[K, V]) RandomUniqueEntries(count int) (results []V)
- func (r *RandomMap[K, V]) Set(key K, value V)
- func (r *RandomMap[K, V]) Size() int
- func (r *RandomMap[K, V]) Values() (result []V)
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]) ForEach ¶
ForEach iterates through the elements in the map and calls the consumer function for each element.
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 ¶
RandomEntry returns a random value from the map.
func (*RandomMap[K, V]) RandomUniqueEntries ¶
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.
Click to show internal directories.
Click to hide internal directories.