mapz

package
v1.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexOfValueInMultimap added in v1.35.0

func IndexOfValueInMultimap[T comparable, Q comparable](mm *MultiMap[T, Q], key T, value Q) int

IndexOfValueInMultimap returns the index of the value in the map for the given key.

Types

type CountingMultiMap added in v1.27.0

type CountingMultiMap[T comparable, Q comparable] struct {
	// contains filtered or unexported fields
}

CountingMultiMap is a multimap that counts the number of distinct values for each key, removing the key from the map when the count reaches zero. Safe for concurrent use.

func NewCountingMultiMap added in v1.27.0

func NewCountingMultiMap[T comparable, Q comparable]() *CountingMultiMap[T, Q]

NewCountingMultiMap constructs a new counting multimap.

func (*CountingMultiMap[T, Q]) Add added in v1.27.0

func (cmm *CountingMultiMap[T, Q]) Add(key T, value Q) bool

Add adds the given value to the map at the given key. Returns true if the value already existed in the map for the given key.

func (*CountingMultiMap[T, Q]) Remove added in v1.27.0

func (cmm *CountingMultiMap[T, Q]) Remove(key T, value Q)

Remove removes the given value for the given key from the map. If, after this removal, the key has no additional values, it is removed entirely from the map.

type MultiMap

type MultiMap[T comparable, Q any] struct {
	// contains filtered or unexported fields
}

MultiMap represents a map that can contain 1 or more values for each key.

func NewMultiMap

func NewMultiMap[T comparable, Q any]() *MultiMap[T, Q]

NewMultiMap initializes a new MultiMap.

func NewMultiMapWithCap

func NewMultiMapWithCap[T comparable, Q any](capacity uint32) *MultiMap[T, Q]

NewMultiMapWithCap initializes with the provided capacity for the top-level map.

func (*MultiMap[T, Q]) Add

func (mm *MultiMap[T, Q]) Add(key T, item Q)

Add inserts the value into the map at the given key.

If there exists an existing value, then this value is appended *without comparison*. Put another way, a value can be added twice, if this method is called twice for the same value.

func (*MultiMap[T, Q]) AsReadOnly

func (mm *MultiMap[T, Q]) AsReadOnly() ReadOnlyMultimap[T, Q]

AsReadOnly returns a read-only *copy* of the mulitmap.

func (*MultiMap[T, Q]) Clear

func (mm *MultiMap[T, Q]) Clear()

Clear clears all entries in the map.

func (*MultiMap[T, Q]) Clone added in v1.35.2

func (mm *MultiMap[T, Q]) Clone() *MultiMap[T, Q]

Clone returns a clone of the map.

func (*MultiMap[T, Q]) CountOf added in v1.35.0

func (mm *MultiMap[T, Q]) CountOf(key T) int

CountOf returns the number of values stored for the given key.

func (*MultiMap[T, Q]) Get

func (mm *MultiMap[T, Q]) Get(key T) ([]Q, bool)

Get returns the values stored in the map for the provided key and whether the key existed.

If the key does not exist, an empty slice is returned.

func (*MultiMap[T, Q]) Has

func (mm *MultiMap[T, Q]) Has(key T) bool

Has returns true if the key is found in the map.

func (*MultiMap[T, Q]) IsEmpty

func (mm *MultiMap[T, Q]) IsEmpty() bool

IsEmpty returns true if the map is currently empty.

func (*MultiMap[T, Q]) Keys

func (mm *MultiMap[T, Q]) Keys() []T

Keys returns the keys of the map.

func (*MultiMap[T, Q]) Len

func (mm *MultiMap[T, Q]) Len() int

Len returns the length of the map, e.g. the number of *keys* present.

func (*MultiMap[T, Q]) RemoveKey

func (mm *MultiMap[T, Q]) RemoveKey(key T)

RemoveKey removes the given key from the map.

func (*MultiMap[T, Q]) Set added in v1.35.2

func (mm *MultiMap[T, Q]) Set(key T, values []Q)

Sets sets the values in the multimap to those provided.

func (MultiMap[T, Q]) Values

func (mm MultiMap[T, Q]) Values() []Q

Values returns all values in the map.

type ReadOnlyMultimap

type ReadOnlyMultimap[T comparable, Q any] interface {
	// Has returns true if the key is found in the map.
	Has(key T) bool

	// Get returns the values for the given key in the map and whether the key
	// existed.
	// If the key does not exist, an empty slice is returned.
	Get(key T) ([]Q, bool)

	// IsEmpty returns true if the map is currently empty.
	IsEmpty() bool

	// Len returns the length of the map, e.g. the number of *keys* present.
	Len() int

	// Keys returns the keys of the map.
	Keys() []T

	// Values returns all values in the map.
	Values() []Q
}

ReadOnlyMultimap is a read-only multimap.

type Set

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

Set implements a very basic generic set.

func NewSet

func NewSet[T comparable](items ...T) *Set[T]

NewSet returns a new set.

func (*Set[T]) Add

func (s *Set[T]) Add(value T) bool

Add adds the given value to the set and returns true. If the value is already present, returns false.

func (*Set[T]) AsSlice

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

AsSlice returns the set as a slice of values.

func (*Set[T]) Copy

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

Copy returns a copy of this set.

func (*Set[T]) Delete added in v1.29.0

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

Delete removes the value from the set, returning nothing.

func (*Set[T]) Equal

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

Equal returns true if both sets have the same elements

func (*Set[T]) Extend

func (s *Set[T]) Extend(values []T)

Extend adds all the values to the set.

func (*Set[T]) ForEach

func (s *Set[T]) ForEach(callback func(value T) error) error

ForEach executes the callback for each item in the set until an error is encountered.

func (*Set[T]) Has

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

Has returns true if the set contains the given value.

func (*Set[T]) Insert added in v1.29.0

func (s *Set[T]) Insert(value T)

Insert adds the given value to the set.

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

Intersect removes any values from this set that are not shared with the other set, returning a new set.

func (*Set[T]) IntersectionDifference

func (s *Set[T]) IntersectionDifference(other *Set[T]) *Set[T]

IntersectionDifference removes any values from this set that are not shared with the other set. Returns the same set.

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

IsEmpty returns true if the set is empty.

func (*Set[T]) Len

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

Len returns the length of the set.

func (*Set[T]) MarshalZerologObject

func (s *Set[T]) MarshalZerologObject(e *zerolog.Event)

func (*Set[T]) Merge added in v1.29.0

func (s *Set[T]) Merge(other *Set[T])

Merge adds all the values from the other set to this set.

func (*Set[T]) RemoveAll

func (s *Set[T]) RemoveAll(other *Set[T])

RemoveAll removes all values from this set found in the other set.

func (*Set[T]) Subtract

func (s *Set[T]) Subtract(other *Set[T]) *Set[T]

Subtract subtracts the other set from this set, returning a new set.

func (*Set[T]) Union added in v1.29.0

func (s *Set[T]) Union(other *Set[T]) *Set[T]

Union adds all the values from the other set to this set, returning a new set.

Jump to

Keyboard shortcuts

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