Documentation ¶
Overview ¶
Package orderedmapx is a thread safe and ordered implementation of a standard map. The elements can be retrieved in the same order in which they were added. orderedmapx allows elements to be located without having to sequentially search the list to find the element we're looking for.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a thread safe and ordered implementation of standard map. K is the type of key and V is the type of value.
func (*Map[K, V]) Delete ¶
Delete deletes the entry for the specified key from the map. Returns true if the key existed in the map and was deleted; false otherwise.
func (*Map[K, V]) Get ¶
Get returns the value for the specified key if the key exists in the map. The second return value is a boolean, which will be set to true if the key was found in the map, or false if the key was not found in the map.
func (*Map[K, V]) GetAndDelete ¶
GetAndDelete removes the first (i.e., oldest) element from the list and returns it. If the list is empty, the call will block until a new element is added. The second return value will be set to true if the list was not empty; otherwise it will be set to false if the list is empty.
func (*Map[K, V]) Put ¶
func (m *Map[K, V]) Put(key K, val V)
Put adds a key to the map with the specified value. If the key already exists, then the existing key's value is replaced with the new value.
func (*Map[K, V]) PutIfAbsent ¶
PutIfAbsent returns the existing value if the key already exists in the map and sets the second return value to false to indicate that the value was not updated because the key already existed in the map. Otherwise, if the key did not already exist in the map, it returns the new value and sets the second return value to true to indicate that the key and its value were added to the map.