Documentation
¶
Index ¶
- type Container
- type ImmutableMapSet
- func (h ImmutableMapSet[T]) All() iter.Seq[T]
- func (h ImmutableMapSet[T]) Contains(item T) bool
- func (h ImmutableMapSet[T]) Equal(o Container[T]) bool
- func (h ImmutableMapSet[T]) Intersects(o Container[T]) bool
- func (h ImmutableMapSet[T]) Iterate(callback func(item T) bool)deprecated
- func (h ImmutableMapSet[T]) Len() int
- func (h ImmutableMapSet[T]) MarshalJSON() ([]byte, error)
- func (h ImmutableMapSet[T]) Slice() []T
- func (h *ImmutableMapSet[T]) UnmarshalJSON(b []byte) error
- type MapSet
- func (h *MapSet[T]) Add(item T) bool
- func (h MapSet[T]) All() iter.Seq[T]
- func (h MapSet[T]) Contains(item T) bool
- func (h MapSet[T]) Equal(o Container[T]) bool
- func (h MapSet[T]) Intersects(o Container[T]) bool
- func (h MapSet[T]) Iterate(callback func(item T) bool)deprecated
- func (h MapSet[T]) Len() int
- func (h MapSet[T]) MarshalJSON() ([]byte, error)
- func (h *MapSet[T]) Remove(item T) bool
- func (h MapSet[T]) Slice() []T
- func (h *MapSet[T]) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container[T comparable] interface { Contains(T) bool Len() int }
type ImmutableMapSet ¶
type ImmutableMapSet[T comparable] MapSet[T]
func Immutable ¶
func Immutable[T comparable](args ...T) ImmutableMapSet[T]
func (ImmutableMapSet[T]) All ¶ added in v1.2.0
func (h ImmutableMapSet[T]) All() iter.Seq[T]
All returns an iterator over elements in the set. Iteration order is undefined.
func (ImmutableMapSet[T]) Contains ¶
func (h ImmutableMapSet[T]) Contains(item T) bool
Contains returns whether the item exists in the set
func (ImmutableMapSet[T]) Equal ¶
func (h ImmutableMapSet[T]) Equal(o Container[T]) bool
Equal returns whether the same items exist in both h and o
func (ImmutableMapSet[T]) Intersects ¶
func (h ImmutableMapSet[T]) Intersects(o Container[T]) bool
Intersects returns whether any items in this set exist in o
func (ImmutableMapSet[T]) Iterate
deprecated
func (h ImmutableMapSet[T]) Iterate(callback func(item T) bool)
Iterate the items in the set, calling callback for each item. If the callback returns false, iteration is halted. Iteration order is undefined.
Deprecated: Use All() instead.
func (ImmutableMapSet[T]) Len ¶
func (h ImmutableMapSet[T]) Len() int
Len returns the size of the set
func (ImmutableMapSet[T]) MarshalJSON ¶
func (h ImmutableMapSet[T]) MarshalJSON() ([]byte, error)
MarshalJSON serializes a MapSet as a JSON array. Elements are ordered lexicographically by their marshaled value.
func (ImmutableMapSet[T]) Slice ¶
func (h ImmutableMapSet[T]) Slice() []T
func (*ImmutableMapSet[T]) UnmarshalJSON ¶
func (h *ImmutableMapSet[T]) UnmarshalJSON(b []byte) error
UnmarshalJSON deserializes an ImmutableMapSet from a JSON array.
type MapSet ¶
type MapSet[T comparable] struct { // contains filtered or unexported fields }
MapSet is a struct that adds some convenience to the otherwise cumbersome map[T]struct{} idiom used in Go to implement mapset of comparable types.
Note: the zero value of MapSet[T] (i.e. MapSet[T]{}) is fully usable and avoids unnecessary allocations in the case where nothing gets added to the MapSet. However, take care in using it, especially when passing it by value to other functions. If passed by value, mutating operations (e.g. Add(), Remove()) in the called function will persist in the calling function's version if the MapSet[T] has been changed from the zero value prior to the call. See the "zero value" test for an example.
func FromItems ¶
func FromItems[T comparable](items ...T) *MapSet[T]
FromItems creates a MapSet of size len(items) and calls Add for each of the items to it.
func Make ¶
func Make[T comparable](args ...int) *MapSet[T]
Make returns a MapSet ready for use. Optionally, a desired size for the MapSet can be passed as an argument, as in the argument to make() for a map type.
func (MapSet[T]) All ¶ added in v1.2.0
All returns an iterator over elements in the set. Iteration order is undefined.
func (MapSet[T]) Intersects ¶
Intersects returns whether any items in this set exist in o
func (MapSet[T]) MarshalJSON ¶
MarshalJSON serializes a MapSet as a JSON array. Elements are ordered lexicographically by their marshaled value.
func (*MapSet[T]) Remove ¶
Remove an item from the Set. Returns true if the item existed in the set.
func (*MapSet[T]) UnmarshalJSON ¶
UnmarshalJSON deserializes a MapSet from a JSON array.