Documentation
¶
Index ¶
- type KV
- type SortedMap
- func (sm *SortedMap[Map, K, V]) All() iter.Seq2[K, V]
- func (sm *SortedMap[Map, K, V]) Collect() Map
- func (sm *SortedMap[Map, K, V]) Delete(key K) (val *V, existed bool)
- func (sm *SortedMap[Map, K, V]) Get(key K) (V, bool)
- func (sm *SortedMap[Map, K, V]) Insert(key K, val V)
- func (sm *SortedMap[Map, K, V]) Keys() iter.Seq[K]
- func (sm *SortedMap[Map, K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KV ¶
type KV[K comparable, V any] struct { Key K Val V }
type SortedMap ¶
type SortedMap[Map ~map[K]V, K comparable, V any] struct { // contains filtered or unexported fields }
SortedMap is a map-like struct that keeps sorted by key or value. It uses a heap to maintain the order.
func New ¶
func New[Map ~map[K]V, K comparable, V any](less func(i, j KV[K, V]) bool) *SortedMap[Map, K, V]
New creates a new SortedMap with `less` as the comparison function The complexity is O(1)
func NewFromMap ¶
func NewFromMap[Map ~map[K]V, K comparable, V any](m Map, less func(i, j KV[K, V]) bool) *SortedMap[Map, K, V]
NewFromMap creates a new SortedMap with `less` as the comparison function and populates it with the contents of `m`. The complexity is O(n log n) where n = len(m).
func (*SortedMap[Map, K, V]) Collect ¶
func (sm *SortedMap[Map, K, V]) Collect() Map
Collect returns a map with the same contents as the SortedMap
func (*SortedMap[Map, K, V]) Delete ¶
Delete removes the key from the map and returns the value associated with the key and a boolean indicating if the key existed in the map. The complexity is O(n) where n = len(sm.h.xs)
func (*SortedMap[Map, K, V]) Get ¶
Get returns the value associated with the key and a boolean indicating if the key exists in the map The complexity is O(1)
func (*SortedMap[Map, K, V]) Insert ¶
func (sm *SortedMap[Map, K, V]) Insert(key K, val V)
Insert adds a key-value pair to the map. If the key already exists, the value is updated.