mapset

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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

func (h *MapSet[T]) Add(item T) bool

Add an item to the set. Returns true if the item did not exist in the set.

func (MapSet[T]) All added in v1.2.0

func (h MapSet[T]) All() iter.Seq[T]

All returns an iterator over elements in the set. Iteration order is undefined.

func (MapSet[T]) Contains

func (h MapSet[T]) Contains(item T) bool

Contains returns whether the item exists in the set

func (MapSet[T]) Equal

func (h MapSet[T]) Equal(o Container[T]) bool

Equal returns whether the same items exist in both h and o

func (MapSet[T]) Intersects

func (h MapSet[T]) Intersects(o Container[T]) bool

Intersects returns whether any items in this set exist in o

func (MapSet[T]) Iterate deprecated

func (h MapSet[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 (MapSet[T]) Len

func (h MapSet[T]) Len() int

Len returns the size of the MapSet

func (MapSet[T]) MarshalJSON

func (h MapSet[T]) MarshalJSON() ([]byte, error)

MarshalJSON serializes a MapSet as a JSON array. Elements are ordered lexicographically by their marshaled value.

func (*MapSet[T]) Remove

func (h *MapSet[T]) Remove(item T) bool

Remove an item from the Set. Returns true if the item existed in the set.

func (MapSet[T]) Slice

func (h MapSet[T]) Slice() []T

func (*MapSet[T]) UnmarshalJSON

func (h *MapSet[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes a MapSet from a JSON array.

Jump to

Keyboard shortcuts

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