collections

package
v0.0.0-...-1ca5a2d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 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 (*MultiMap[K, V]) Add

func (s *MultiMap[K, V]) Add(key K, value V)

func (*MultiMap[K, V]) Clear

func (s *MultiMap[K, V]) Clear()

func (*MultiMap[K, V]) Get

func (s *MultiMap[K, V]) Get(key K) []V

func (*MultiMap[K, V]) Has

func (s *MultiMap[K, V]) Has(key K) bool

func (*MultiMap[K, V]) Keys

func (s *MultiMap[K, V]) Keys() iter.Seq[K]

func (*MultiMap[K, V]) Len

func (s *MultiMap[K, V]) Len() int

func (*MultiMap[K, V]) Remove

func (s *MultiMap[K, V]) Remove(key K, value V)

func (*MultiMap[K, V]) RemoveAll

func (s *MultiMap[K, V]) RemoveAll(key K)

func (*MultiMap[K, V]) Values

func (s *MultiMap[K, V]) Values() iter.Seq[[]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]) Add

func (s *OrderedSet[T]) Add(value T)

Add adds a value to the set.

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]) Add

func (s *Set[T]) Add(key T)

func (*Set[T]) AddIfAbsent

func (s *Set[T]) AddIfAbsent(key T) bool

Returns true if the key was not already present in the set.

func (*Set[T]) Clear

func (s *Set[T]) Clear()

func (*Set[T]) Clone

func (s *Set[T]) Clone() *Set[T]

func (*Set[T]) Delete

func (s *Set[T]) Delete(key T)

func (*Set[T]) Equals

func (s *Set[T]) Equals(other *Set[T]) bool

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

func (*Set[T]) Keys

func (s *Set[T]) Keys() map[T]struct{}

func (*Set[T]) Len

func (s *Set[T]) Len() int

type SyncMap

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*SyncMap[K, V]) Clear

func (s *SyncMap[K, V]) Clear()

func (*SyncMap[K, V]) Clone

func (s *SyncMap[K, V]) Clone() *SyncMap[K, V]

func (*SyncMap[K, V]) Delete

func (s *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) Keys

func (s *SyncMap[K, V]) Keys() iter.Seq[K]

func (*SyncMap[K, V]) Load

func (s *SyncMap[K, V]) Load(key K) (value V, ok bool)

func (*SyncMap[K, V]) LoadOrStore

func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*SyncMap[K, V]) Range

func (s *SyncMap[K, V]) Range(f func(key K, value V) bool)

func (*SyncMap[K, V]) Size

func (s *SyncMap[K, V]) Size() int

Size returns the approximate number of items in the map. Note that this is not a precise count, as the map may be modified concurrently while this method is running.

func (*SyncMap[K, V]) Store

func (s *SyncMap[K, V]) Store(key K, value V)

func (*SyncMap[K, V]) ToMap

func (s *SyncMap[K, V]) ToMap() map[K]V

type SyncSet

type SyncSet[T comparable] struct {
	// contains filtered or unexported fields
}

func (*SyncSet[T]) Add

func (s *SyncSet[T]) Add(key T)

func (*SyncSet[T]) AddIfAbsent

func (s *SyncSet[T]) AddIfAbsent(key T) bool

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).

func (*SyncSet[T]) Delete

func (s *SyncSet[T]) Delete(key T)

func (*SyncSet[T]) Has

func (s *SyncSet[T]) Has(key T) bool

func (*SyncSet[T]) Keys

func (s *SyncSet[T]) Keys() iter.Seq[T]

func (*SyncSet[T]) Range

func (s *SyncSet[T]) Range(fn func(key T) bool)

func (*SyncSet[T]) Size

func (s *SyncSet[T]) Size() int

Size returns the approximate number of items in the map. Note that this is not a precise count, as the map may be modified concurrently while this method is running.

func (*SyncSet[T]) ToSlice

func (s *SyncSet[T]) ToSlice() []T

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL