set

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: MIT Imports: 5 Imported by: 0

README

Generic Hash Set for GO

Just a simple hashset type built for go using map[T]struct{}.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] map[T]struct{}

Set is an unordered collection of distinct comparable items. Common uses include membership testing, removing duplicates from sequence, and doing boolean set operations like Intersection and Union.

func Difference

func Difference[T comparable](lhs Set[T], others ...Set[T]) Set[T]

Difference returns a new set which contains items that are in the first Set but not in the others.

func Intersection

func Intersection[T comparable](sets ...Set[T]) Set[T]

Intersection returns a new Set which contains items that only exist in all given sets.

func New

func New[T comparable](items ...T) Set[T]

New creates a new set with 0 or many items.

func SymmetricDifference

func SymmetricDifference[T comparable](lhs, rhs Set[T]) Set[T]

SymmetricDifference returns a new set that contains elements from either passed set but not both.

func Union

func Union[T comparable](sets ...Set[T]) Set[T]

Union is the merger of multiple sets. It returns a new Set with all elements in all the sets passed.

func (Set[T]) Add

func (s Set[T]) Add(items ...T)

Add includes the specified items (one or many) to the Set s. Set s is modified in place. If passed nothing it silently returns.

func (Set[T]) Contains

func (s Set[T]) Contains(items ...T) bool

Contains tests if Set s contains all items passed. It returns false if nothing is passed.

func (Set[T]) ContainsAny

func (s Set[T]) ContainsAny(items ...T) bool

ContainsAny tests if Set s contains any of the items passed. It returns false of nothing is passed.

func (Set[T]) Copy

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

Copy return a new Set with a copy of s.

func (Set[T]) Equals

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

Equals tests whether s and other are the same size and contain the same items.

func (Set[T]) IsSubSet added in v0.2.0

func (s Set[T]) IsSubSet(other Set[T]) bool

IsSubSet tests if every element of s exists in the other.

func (Set[T]) IsSuperSet added in v0.2.0

func (s Set[T]) IsSuperSet(other Set[T]) bool

IsSuperSet tests if every element of other exists in s.

func (Set[T]) MarshalJSON added in v1.0.0

func (s Set[T]) MarshalJSON() ([]byte, error)

func (Set[T]) Merge

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

Merge adds all items from Set other into Set s. This works just like Union, but it applies to Set s in place.

func (Set[T]) Remove

func (s Set[T]) Remove(items ...T)

Remove deletes the specified items (one or many) from the Set s. Set s is modified in place. If passed nothing it silently returns.

func (Set[T]) Separate

func (s Set[T]) Separate(other Set[T])

Separate removes items in Set other from Set s. This works just like Difference but applies to the Set in place.

func (Set[T]) Slice

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

Slice returns a Slice of all items in Set s as a []T.

func (Set[T]) String

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

String returns a string representation of s

func (*Set[T]) UnmarshalJSON added in v1.0.0

func (s *Set[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements the json.Unmarshaler interface turns the slice back to a Set.

Jump to

Keyboard shortcuts

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