Documentation
¶
Index ¶
- type Map
- func (m *Map[K, V]) AsSlice() []V
- func (m *Map[K, V]) Dequeue(key K) (removedElem V)
- func (m *Map[K, V]) First() V
- func (m *Map[K, V]) Foreach() iter.Seq[V]
- func (m *Map[K, V]) Get(key K) V
- func (m *Map[K, V]) InsertIfNotExist(key K, val V) (isFirst, added bool)
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) SortByKey(cmp func(a, b K) int)
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 map data structure that allows accessing it's element in a fixed order.
func New ¶
func New[K comparable, V any](cmp func(a, b V) int) *Map[K, V]
New creates a new Map that orders inserted elements in ascending order after the first element accordingly to the cmp function. The position of the first element is fixed!
func (*Map[K, V]) AsSlice ¶
func (m *Map[K, V]) AsSlice() []V
AsSlice returns a new slice containing the elements of the orderedMap in order.
func (*Map[K, V]) Dequeue ¶
func (m *Map[K, V]) Dequeue(key K) (removedElem V)
Dequeue removes the value with the key from the map and returns it. If the key does not exist in the map, the zero value is returned.
func (*Map[K, V]) First ¶
func (m *Map[K, V]) First() V
First returns the first element in the map. If the map is empty, the zero value is returned.
func (*Map[K, V]) Get ¶
func (m *Map[K, V]) Get(key K) V
Get returns the value for the given key. If the key does not exist, the zero value is returned
func (*Map[K, V]) InsertIfNotExist ¶
InsertIfNotExist adds val to the map if K does not exist. val is inserted at the position determined by the cmp function, but always after the first element.