set

package
v0.0.0-...-39373db Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package set is a template Set type

Tries to be similar to Python's set type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A

type A int

An A is the element of the set

template type Set(A)

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set provides a general purpose set modeled on Python's set type.

func NewSet

func NewSet() *Set

NewSet returns a new empty set

func NewSizedSet

func NewSizedSet(capacity int) *Set

NewSizedSet returns a new empty set with the given capacity

func (*Set) Add

func (s *Set) Add(elem A) *Set

Add adds elem to the set, returning the set

If the element already exists then it has no effect

func (*Set) AddList

func (s *Set) AddList(elems []A) *Set

AddList adds a list of elems to the set

If the elements already exists then it has no effect

func (*Set) AsList

func (s *Set) AsList() []A

AsList returns all the elements as a slice

func (*Set) Clear

func (s *Set) Clear() *Set

Clear removes all the elements

func (*Set) Contains

func (s *Set) Contains(elem A) bool

Contains returns whether elem is in the set or not

func (*Set) Copy

func (s *Set) Copy() *Set

Copy returns a shallow copy of the Set

func (*Set) Difference

func (s *Set) Difference(other *Set) *Set

Difference returns a new set with all the elements that are in this set but not in the other

func (*Set) DifferenceUpdate

func (s *Set) DifferenceUpdate(other *Set) *Set

DifferenceUpdate removes all the elements that are in the other set from this set. It returns the set.

func (*Set) Discard

func (s *Set) Discard(elem A) *Set

Discard removes elem from the set

If it wasn't in the set it does nothing

It returns the set

func (*Set) Intersection

func (s *Set) Intersection(other *Set) *Set

Intersection returns a new set with all the elements that are only in this set and the other set. It returns the new set.

func (*Set) IntersectionUpdate

func (s *Set) IntersectionUpdate(other *Set) *Set

IntersectionUpdate changes this set so that it only contains elements that are in both this set and the other set. It returns the set.

func (*Set) IsDisjoint

func (s *Set) IsDisjoint(other *Set) bool

IsDisjoint returns a bool indicating whether this set and other set have no elements in common.

func (*Set) IsSubset

func (s *Set) IsSubset(strict bool, other *Set) bool

IsSubset returns a bool indicating whether this set is a subset of other set.

func (*Set) IsSuperset

func (s *Set) IsSuperset(strict bool, other *Set) bool

IsSuperset returns a bool indicating whether this set is a superset of other set.

func (*Set) Len

func (s *Set) Len() int

Len returns the number of elements in the set

func (*Set) Pop

func (s *Set) Pop(elem A) (A, bool)

Pop removes elem from the set and returns it

It also returns whether the elem was found or not

func (*Set) Remove

func (s *Set) Remove(elem A) bool

Remove removes elem from the set

It returns whether the elem was in the set or not

func (*Set) SymmetricDifference

func (s *Set) SymmetricDifference(other *Set) *Set

SymmetricDifference returns a new set of all elements that are a member of exactly one of this set and other set(elements which are in one of the sets, but not in both).

func (*Set) SymmetricDifferenceUpdate

func (s *Set) SymmetricDifferenceUpdate(other *Set) *Set

SymmetricDifferenceUpdate modifies this set to be a set of all elements that are a member of exactly one of this set and other set(elements which are in one of the sets, but not in both) and returns this set.

func (*Set) Union

func (s *Set) Union(other *Set) *Set

Union returns a new set with all the elements that are in either set. It returns the new set.

func (*Set) Update

func (s *Set) Update(other *Set) *Set

Update adds all the elements from the other set to this set. It returns the set.

type SetNothing

type SetNothing struct{}

SetNothing is used as a zero sized member in the map

Jump to

Keyboard shortcuts

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