Documentation
¶
Index ¶
- func DiffOrderedMaps[K comparable, V comparable](m1 *OrderedMap[K, V], m2 *OrderedMap[K, V], onAdded func(key K, value V), ...)
- func DiffOrderedMapsFunc[K comparable, V any](m1 *OrderedMap[K, V], m2 *OrderedMap[K, V], equalValues func(a, b V) bool, ...)
- type CopyOnWriteMap
- type CopyOnWriteSet
- type MapEntry
- type MultiMap
- func (s *MultiMap[K, V]) Add(key K, value V)
- func (s *MultiMap[K, V]) Clear()
- func (s *MultiMap[K, V]) Get(key K) []V
- func (s *MultiMap[K, V]) Has(key K) bool
- func (s *MultiMap[K, V]) Keys() iter.Seq[K]
- func (s *MultiMap[K, V]) Len() int
- func (s *MultiMap[K, V]) Remove(key K, value V)
- func (s *MultiMap[K, V]) RemoveAll(key K)
- func (s *MultiMap[K, V]) Values() iter.Seq[[]V]
- type OrderedMap
- func (m *OrderedMap[K, V]) Clear()
- func (m *OrderedMap[K, V]) Clone() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) (V, bool)
- func (m *OrderedMap[K, V]) Entries() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) EntryAt(index int) (K, V, bool)
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap[K, V]) GetOrZero(key K) V
- func (m *OrderedMap[K, V]) Has(key K) bool
- func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
- func (m *OrderedMap[K, V]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (m *OrderedMap[K, V]) Set(key K, value V)
- func (m *OrderedMap[K, V]) Size() int
- func (m *OrderedMap[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (m *OrderedMap[K, V]) Values() iter.Seq[V]
- type OrderedSet
- type Set
- func (s *Set[T]) Add(key T)
- func (s *Set[T]) AddIfAbsent(key T) bool
- func (s *Set[T]) Clear()
- func (s *Set[T]) Clone() *Set[T]
- func (s *Set[T]) Delete(key T)
- func (s *Set[T]) Equals(other *Set[T]) bool
- func (s *Set[T]) Has(key T) bool
- func (s *Set[T]) Intersects(other *Set[T]) bool
- func (s *Set[T]) IsSubsetOf(other *Set[T]) bool
- func (s *Set[T]) Keys() map[T]struct{}
- func (s *Set[T]) Len() int
- func (s *Set[T]) Union(other *Set[T])
- func (s *Set[T]) UnionedWith(other *Set[T]) *Set[T]
- type SyncMap
- func (s *SyncMap[K, V]) Clear()
- func (s *SyncMap[K, V]) Clone() *SyncMap[K, V]
- func (s *SyncMap[K, V]) Delete(key K)
- func (s *SyncMap[K, V]) Keys() iter.Seq[K]
- func (s *SyncMap[K, V]) Load(key K) (value V, ok bool)
- func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (s *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (s *SyncMap[K, V]) Size() int
- func (s *SyncMap[K, V]) Store(key K, value V)
- func (s *SyncMap[K, V]) ToMap() map[K]V
- type SyncSet
- func (s *SyncSet[T]) Add(key T)
- func (s *SyncSet[T]) AddIfAbsent(key T) bool
- func (s *SyncSet[T]) Delete(key T)
- func (s *SyncSet[T]) Has(key T) bool
- func (s *SyncSet[T]) IsEmpty() bool
- func (s *SyncSet[T]) Keys() iter.Seq[T]
- func (s *SyncSet[T]) Range(fn func(key T) bool)
- func (s *SyncSet[T]) Size() int
- func (s *SyncSet[T]) ToSlice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffOrderedMaps ¶
func DiffOrderedMaps[K comparable, V comparable](m1 *OrderedMap[K, V], m2 *OrderedMap[K, V], onAdded func(key K, value V), onRemoved func(key K, value V), onModified func(key K, oldValue V, newValue V))
func DiffOrderedMapsFunc ¶
func DiffOrderedMapsFunc[K comparable, V any](m1 *OrderedMap[K, V], m2 *OrderedMap[K, V], equalValues func(a, b V) bool, onAdded func(key K, value V), onRemoved func(key K, value V), onModified func(key K, oldValue V, newValue V))
Types ¶
type CopyOnWriteMap ¶ added in v0.15.0
type CopyOnWriteMap[K comparable, V any] struct { // contains filtered or unexported fields }
CopyOnWriteMap is a map that defers cloning of an inherited backing map until the first mutation, and supports nested scopes that share the parent's map for reads but get their own clone on write.
The zero value is an empty map ready to use.
func (*CopyOnWriteMap[K, V]) EnterScope ¶ added in v0.15.0
func (c *CopyOnWriteMap[K, V]) EnterScope() func()
EnterScope returns a function that restores this map to its current state. While the scope is active, the map shares its current backing storage with the parent scope: reads see the inherited entries, and the first mutation transparently clones the storage so the parent's view is not modified.
func (*CopyOnWriteMap[K, V]) Get ¶ added in v0.15.0
func (c *CopyOnWriteMap[K, V]) Get(k K) (V, bool)
Get returns the value for k and whether it was present.
func (*CopyOnWriteMap[K, V]) Has ¶ added in v0.15.0
func (c *CopyOnWriteMap[K, V]) Has(k K) bool
Has reports whether k is in the map.
func (*CopyOnWriteMap[K, V]) Set ¶ added in v0.15.0
func (c *CopyOnWriteMap[K, V]) Set(k K, v V)
Set assigns v to k, cloning the inherited backing map first if necessary.
type CopyOnWriteSet ¶ added in v0.15.0
type CopyOnWriteSet[K comparable] struct { // contains filtered or unexported fields }
func (*CopyOnWriteSet[K]) Add ¶ added in v0.15.0
func (c *CopyOnWriteSet[K]) Add(k K)
Set adds k to the set, cloning the inherited backing map first if necessary.
func (*CopyOnWriteSet[K]) EnterScope ¶ added in v0.15.0
func (c *CopyOnWriteSet[K]) EnterScope() func()
EnterScope returns a function that restores this set to its current state. While the scope is active, the set shares its current backing storage with the parent scope: reads see the inherited entries, and the first mutation transparently clones the storage so the parent's view is not modified.
func (*CopyOnWriteSet[K]) Has ¶ added in v0.15.0
func (c *CopyOnWriteSet[K]) Has(k K) bool
Has reports whether k is in the set.
type MapEntry ¶
type MapEntry[K comparable, V any] struct { Key K Value V }
type MultiMap ¶
type MultiMap[K comparable, V comparable] struct { M map[K][]V }
func GroupBy ¶
func GroupBy[K comparable, V comparable](items []V, groupId func(V) K) *MultiMap[K, V]
func NewMultiMapWithSizeHint ¶
func NewMultiMapWithSizeHint[K comparable, V comparable](hint int) *MultiMap[K, V]
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is an insertion ordered map.
func NewOrderedMapFromList ¶
func NewOrderedMapFromList[K comparable, V any](items []MapEntry[K, V]) *OrderedMap[K, V]
func NewOrderedMapWithSizeHint ¶
func NewOrderedMapWithSizeHint[K comparable, V any](hint int) *OrderedMap[K, V]
NewOrderedMapWithSizeHint creates a new OrderedMap with a hint for the number of elements it will contain.
func (*OrderedMap[K, V]) Clear ¶
func (m *OrderedMap[K, V]) Clear()
Clear removes all key-value pairs from the map. The space allocated for the map will be reused.
func (*OrderedMap[K, V]) Clone ¶
func (m *OrderedMap[K, V]) Clone() *OrderedMap[K, V]
Clone returns a shallow copy of the map.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) (V, bool)
Delete removes a key-value pair from the map.
func (*OrderedMap[K, V]) Entries ¶
func (m *OrderedMap[K, V]) Entries() iter.Seq2[K, V]
Entries returns an iterator over the key-value pairs in the map.
func (*OrderedMap[K, V]) EntryAt ¶
func (m *OrderedMap[K, V]) EntryAt(index int) (K, V, bool)
EntryAt retrieves the key-value pair at the specified index.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get retrieves a value from the map.
func (*OrderedMap[K, V]) GetOrZero ¶
func (m *OrderedMap[K, V]) GetOrZero(key K) V
GetOrZero retrieves a value from the map, or returns the zero value of the value type if the key is not present.
func (*OrderedMap[K, V]) Has ¶
func (m *OrderedMap[K, V]) Has(key K) bool
Has returns true if the map contains the key.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
Keys returns an iterator over the keys in the map. A slice of the keys can be obtained by calling `slices.Collect`.
func (*OrderedMap[K, V]) MarshalJSONTo ¶
func (m *OrderedMap[K, V]) MarshalJSONTo(enc *jsontext.Encoder) error
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V)
Set sets a key-value pair in the map.
func (*OrderedMap[K, V]) Size ¶
func (m *OrderedMap[K, V]) Size() int
Size returns the number of key-value pairs in the map.
func (*OrderedMap[K, V]) UnmarshalJSONFrom ¶
func (m *OrderedMap[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() iter.Seq[V]
Values returns an iterator over the values in the map. A slice of the values can be obtained by calling `slices.Collect`.
type OrderedSet ¶
type OrderedSet[T comparable] struct { // contains filtered or unexported fields }
OrderedSet an insertion ordered set.
func NewOrderedSetWithSizeHint ¶
func NewOrderedSetWithSizeHint[T comparable](hint int) *OrderedSet[T]
NewOrderedSetWithSizeHint creates a new OrderedSet with a hint for the number of elements it will contain.
func (*OrderedSet[T]) Clear ¶
func (s *OrderedSet[T]) Clear()
Clear removes all elements from the set. The space allocated for the set will be reused.
func (*OrderedSet[T]) Clone ¶
func (s *OrderedSet[T]) Clone() *OrderedSet[T]
Clone returns a shallow copy of the set.
func (*OrderedSet[T]) Delete ¶
func (s *OrderedSet[T]) Delete(value T) bool
Delete removes a value from the set.
func (*OrderedSet[T]) Has ¶
func (s *OrderedSet[T]) Has(value T) bool
Has returns true if the set contains the value.
func (*OrderedSet[T]) Size ¶
func (s *OrderedSet[T]) Size() int
Size returns the number of elements in the set.
func (*OrderedSet[T]) Values ¶
func (s *OrderedSet[T]) Values() iter.Seq[T]
Values returns an iterator over the values in the set.
type Set ¶
type Set[T comparable] struct { M map[T]struct{} }
func NewSetFromItems ¶
func NewSetFromItems[T comparable](items ...T) *Set[T]
func NewSetWithSizeHint ¶
func NewSetWithSizeHint[T comparable](hint int) *Set[T]
NewSetWithSizeHint creates a new Set with a hint for the number of elements it will contain.
func (*Set[T]) AddIfAbsent ¶
Returns true if the key was not already present in the set.
func (*Set[T]) Intersects ¶
func (*Set[T]) IsSubsetOf ¶
func (*Set[T]) UnionedWith ¶
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
func (*SyncMap[K, V]) LoadOrStore ¶
type SyncSet ¶
type SyncSet[T comparable] struct { // contains filtered or unexported fields }
func (*SyncSet[T]) AddIfAbsent ¶
AddIfAbsent adds the key to the set if it is not already present using LoadOrStore. It returns true if the key was not already present (opposite of the return value of LoadOrStore).