set

package
v1.17.0-rc.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MembersOfType

func MembersOfType[M any, T comparable](s Set[T]) iter.Seq[M]

MembersOfType return an iterator for each member of type M in the set.

Types

type Set

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

Set contains zero, one, or more members. Zero or one members do not consume any additional storage, more than one members are held in an non-exported membersMap.

func NewSet

func NewSet[T comparable](members ...T) Set[T]

NewSet returns a Set initialized to contain the members in 'members'.

func (Set[T]) AsSlice

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

AsSlice converts the set to a slice.

func (*Set[T]) Clear

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

Clear makes the set '*s' empty.

func (Set[T]) Clone

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

Clone returns a copy of the set.

func (Set[T]) Empty

func (s Set[T]) Empty() bool

Empty returns 'true' if the set is empty.

func (Set[T]) Equal

func (s Set[T]) Equal(o Set[T]) bool

Equal returns 'true' if the receiver and argument sets are the same.

func (Set[T]) Get

func (s Set[T]) Get() (m T, found bool)

Get returns any one member from the set. Useful when it is known that the set has only one element.

func (Set[T]) Has

func (s Set[T]) Has(member T) bool

Has returns 'true' if 'member' is in the set.

func (*Set[T]) Insert

func (s *Set[T]) Insert(member T) (changed bool)

Insert inserts a member to the set. Returns 'true' when '*s' value has changed, so that if it is stored by value the caller must knows to update the stored value.

func (Set[T]) Len

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

Len returns the number of members in the set.

func (Set[T]) Members

func (s Set[T]) Members() iter.Seq[T]

Members returns an iterator for the members in the set.

func (*Set[T]) Merge

func (s *Set[T]) Merge(sets ...Set[T]) (changed bool)

Merge inserts members in 'o' into to the set 's'. Returns 'true' when '*s' value has changed, so that if it is stored by value the caller must knows to update the stored value.

func (*Set[T]) Remove

func (s *Set[T]) Remove(member T) (changed bool)

Remove removes a member from the set. Returns 'true' when '*s' value was changed, so that if it is stored by value the caller knows to update the stored value.

func (*Set[T]) RemoveSets

func (s *Set[T]) RemoveSets(sets ...Set[T]) (changed bool)

RemoveSets removes one or more Sets from the receiver set. Returns 'true' when '*s' value was changed, so that if it is stored by value the caller knows to update the stored value.

func (Set[T]) String

func (s Set[T]) String() string

Jump to

Keyboard shortcuts

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