set

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 5 Imported by: 10

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

func NewHashset

func NewHashset[K comparable](cap uint64, equals generic.EqualsFn[K], hash generic.HashFn[K], in ...K) Set[K]

func NewMapset

func NewMapset[K comparable](in ...K) Set[K]

func NewSet

func NewSet[K comparable, S func() SetOf[K]](con S, in ...K) Set[K]

func (Set[K]) Clone

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

func (Set[K]) ConstDifference

func (s Set[K]) ConstDifference(with ...K) Set[K]
Example
fmt.Print(NewMapset(1.2, 1.8, 2.6, 3.5).ConstDifference(1.2, 2.6))
Output:

[1.8 3.5]

func (Set[K]) ConstIntersection

func (s Set[K]) ConstIntersection(with ...K) Set[K]
Example
fmt.Print(NewMapset("a", "b", "c").ConstIntersection("b", "c", "e"))
Output:

[b c]

func (Set[K]) ConstSymmetricDifference

func (s Set[K]) ConstSymmetricDifference(with ...K) Set[K]
Example
fmt.Print(NewMapset(1, 2, 3).ConstSymmetricDifference(2, 3, 4))
Output:

[1 4]

func (Set[K]) ConstUnion

func (s Set[K]) ConstUnion(with ...K) Set[K]
Example
fmt.Print(NewMapset(1, 4, 7).ConstUnion(2, 3, 5, 6))
Output:

[1 2 3 4 5 6 7]

func (Set[K]) Difference

func (s Set[K]) Difference(others ...SetOf[K]) Set[K]
Example
s := NewHashset(1, generic.Equals[int], generic.HashInt, 3, 4, 5, 6, 7)
o := NewMapset(5)
diff := s.Difference(o)

fmt.Println(diff)
fmt.Printf("%T", diff.SetOf) // the same type as the receiver
Output:

[3 4 6 7]
*hashset.Set[int]

func (Set[K]) Equal

func (s Set[K]) Equal(to SetOf[K]) bool

func (Set[K]) InPlaceDifference

func (s Set[K]) InPlaceDifference(others ...SetOf[K]) Set[K]

func (Set[K]) InPlaceIntersection

func (s Set[K]) InPlaceIntersection(others ...SetOf[K]) Set[K]
Example
one := NewMapset(2, 3, 4)
two := NewMapset(4, 5, 6)
one.InPlaceIntersection(two)
fmt.Print(one)
Output:

[4]

func (Set[K]) InPlaceUnion

func (s Set[K]) InPlaceUnion(others ...SetOf[K]) Set[K]

func (Set[K]) Intersection

func (s Set[K]) Intersection(others ...SetOf[K]) Set[K]
Example
s := NewMapset(1, 4, 7)
o := NewHashset(1, generic.Equals[int], generic.HashInt, 1, 7)
inter := s.Intersection(o)

fmt.Println(inter)
fmt.Printf("%T", inter.SetOf) // the same type as the receiver
Output:

[1 7]
mapset.Set[int]

func (Set[K]) IsDisjoint

func (s Set[K]) IsDisjoint(other SetOf[K]) bool

func (Set[K]) IsProperSubset

func (s Set[K]) IsProperSubset(to SetOf[K]) bool

func (Set[K]) IsProperSuperset

func (s Set[K]) IsProperSuperset(to SetOf[K]) bool

func (Set[K]) IsSubset

func (s Set[K]) IsSubset(of SetOf[K]) bool

func (Set[K]) IsSuperset

func (s Set[K]) IsSuperset(of SetOf[K]) bool

func (Set[K]) Keys

func (s Set[K]) Keys() []K
Example
keys := NewMapset("one", "two").Keys()
sort.Strings(keys)
fmt.Println(keys)
Output:

[one two]

func (Set[K]) Map

func (s Set[K]) Map() map[K]struct{}

func (Set[K]) String

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

func (Set[K]) SymmetricDifference

func (s Set[K]) SymmetricDifference(others ...SetOf[K]) Set[K]
Example
one := NewMapset(2, 3, 4)
two := NewMapset(4, 5, 6)
fmt.Print(NewMapset(1, 2, 3).SymmetricDifference(one, two))
Output:

[1 5 6]

func (Set[K]) Union

func (s Set[K]) Union(others ...SetOf[K]) Set[K]
Example
one := NewMapset(2, 3, 4)
two := NewMapset(4, 5, 6)
fmt.Print(NewMapset(1, 2, 3).Union(one, two))
Output:

[1 2 3 4 5 6]

type SetOf

type SetOf[K comparable] interface {
	Put(val K)
	Has(val K) bool
	Remove(val K)
	Clear()
	Size() int
	Each(fn func(key K))
}

Jump to

Keyboard shortcuts

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