Documentation
¶
Overview ¶
Package randmap implements key-value map capable of uniform sampling of keys in it.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RandMap ¶
type RandMap[K comparable, V any] struct { // contains filtered or unexported fields }
RandMap represents key-value map which allows to fetch random key from map, granting equal probability of selection among keys. Time complexity of all operations is O(1) am.
func Wrap ¶
func Wrap[K comparable, V any](m map[K]V) *RandMap[K, V]
Wrap indexes and wraps existing standard map into a *RandMap instance. Original map should not be modified directly after that.
func (*RandMap[K, V]) GetRandom ¶
GetRandom retrieves uniformly-distributed random key-value pair from map, if it's not empty.
Click to show internal directories.
Click to hide internal directories.