import "github.com/brackendawson/ordered"
ordered contains ordered data structures
- type Map
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Index(n int) (key K, value V, loaded bool)
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadAndDeleteFirst() (key K, value V, loaded bool)
- func (m *Map[K, V]) LoadAndDeleteLast() (key K, value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(index int, key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) StoreFirst(key K, value V)
- func (m *Map[K, V]) Swap(i, j int)
- type Ordered
- type SortMap
Map is an ordered map data structure that is safe for concurrent use by multiple goroutines without additional locking or coordination.
The zero Map is empty and ready for use. A Map must not be copied after first use.
type Map[K comparable, V any] struct {
// contains filtered or unexported fields
}
func (m *Map[K, V]) Delete(key K)
Delete deletes the vlaue for a key
func (m *Map[K, V]) Index(n int) (key K, value V, loaded bool)
Index loads the key and value of the key at index n. The loaded result reports whether the index was in range. Negative value of n index from the end of the Map.
func (m *Map[K, V]) Len() int
Len returns the number of keys in Map
func (m *Map[K, V]) Load(key K) (value V, ok bool)
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (m *Map[K, V]) LoadAndDeleteFirst() (key K, value V, loaded bool)
LoadAndDeleteFirst delered the last key, returning the kay and its previous value if any. The loaded result reports whether the key was present.
func (m *Map[K, V]) LoadAndDeleteLast() (key K, value V, loaded bool)
LoadAndDeleteLast delered the last key, returning the kay and its previous value if any. The loaded result reports whether the key was present.
func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value, adding it to the end. The loaded result is true if the value was loaded, false if stored.
func (m *Map[K, V]) Range(f func(index int, key K, value V) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: nevery index will be visited in order, but if the value for any key stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.
func (m *Map[K, V]) Store(key K, value V)
Store sets the value for a key adding it to the end if it was not in the map.
func (m *Map[K, V]) StoreFirst(key K, value V)
StoreFirst sets the value for a key adding it to the beginning if it was not in the map.
func (m *Map[K, V]) Swap(i, j int)
Swap swaps the position of the keys at indicies i and j.
Ordered represents all orderable types.
Deprecated: This will be removed when the constraints package is added to the standard library.
type Ordered interface {
// contains filtered or unexported methods
}
SortMap is a Map which fully impliments sort.Interface. Sort is not sortable if the key type is float and NaN is used as a key.
type SortMap[K Ordered, V any] struct {
// contains filtered or unexported fields
}
func (m *SortMap[K, V]) Less(i, j int) bool
Less returns true if the key at index i is less than the key at index j.
Generated by gomarkdoc