package mapx
import "tailscale.com/types/mapx"
Package mapx contains extra map types and functions.
Index ¶
- type OrderedMap
- func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Contains(key K) bool
- func (m *OrderedMap[K, V]) Delete(key K)
- func (m *OrderedMap[K, V]) Get(key K) V
- func (m *OrderedMap[K, V]) GetOk(key K) (_ V, ok bool)
- func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
- func (m *OrderedMap[K, V]) Set(key K, value V)
- func (m *OrderedMap[K, V]) Values() iter.Seq[V]
Types ¶
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is a map that maintains the order of its keys.
It is meant for maps that only grow or that are small; is it not optimized for deleting keys.
The zero value is ready to use.
Locking-wise, it has the same rules as a regular Go map: concurrent reads are safe, but not writes.
func (*OrderedMap[K, V]) All ¶
func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]
All yields all the keys and values, in the order they were inserted.
func (*OrderedMap[K, V]) Contains ¶
func (m *OrderedMap[K, V]) Contains(key K) bool
Contains reports whether the map contains the given key.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K)
Delete removes the key from the map.
The cost is O(n) in the number of keys in the map.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) V
Get returns the value for the given key in the map. If the key does not exist, it returns the zero value for V.
func (*OrderedMap[K, V]) GetOk ¶
func (m *OrderedMap[K, V]) GetOk(key K) (_ V, ok bool)
GetOk returns the value for the given key in the map and whether it was present in the map.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
Keys yields the map keys, in the order they were inserted.
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V)
Set sets the value for the given key in the map.
If the key already exists, it updates the value and keeps the order.
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() iter.Seq[V]
Values yields the map values, in the order they were inserted.
Source Files ¶
ordered.go
- Version
- v1.84.1 (latest)
- Published
- May 29, 2025
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 1 day ago –
Tools for package owners.