/hash-set

Golang Set Implementation

Primary LanguageGoMIT LicenseMIT

hash_set

import "github.com/ryantate13/hash-set"

Index

type Set

Set is a collection type with unique elements

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

func New

func New[T comparable]() *Set[T]

New instantiates an empty set

func Of

func Of[T comparable](els ...T) *Set[T]

Of instantiates a set with the given elements

func (*Set[T]) Add

func (s *Set[T]) Add(els ...T) *Set[T]

Add adds an element to the set, optionally supports chaining

func (*Set[T]) Difference

func (s *Set[T]) Difference(s2 *Set[T]) *Set[T]

Difference returns the set of elements not in the other set

func (*Set[T]) Empty

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

Empty returns true if a set is empty

func (*Set[T]) Filter

func (s *Set[T]) Filter(fn func(T) bool) *Set[T]

Filter returns the subset of a set that pass a given a filter func

func (*Set[T]) Foreach

func (s *Set[T]) Foreach(fn func(T)) *Set[T]

Foreach executes a callback function with every member of the set

func (*Set[T]) Has

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

Has returns true if a given element is in a set

func (*Set[T]) Intersection

func (s *Set[T]) Intersection(s2 *Set[T]) *Set[T]

Intersection returns the set of elements common to both sets

func (*Set[T]) Len

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

Len returns the number of elements in the set

func (*Set[T]) Remove

func (s *Set[T]) Remove(els ...T) *Set[T]

Remove removes an element from the set, optionally supports chaining

func (*Set[T]) Slice

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

Slice returns the elements of the set as a slice

func (*Set[T]) Subset

func (s *Set[T]) Subset(s2 *Set[T]) bool

Subset returns true if the set is a subset of another set

func (*Set[T]) Union

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

Union returns the combined elements of both sets

Generated by gomarkdoc