sets

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package sets contains functions related to a generic Set implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set represents a finite set (in the sense of Discrete mathematics) of comparable elements. It supports standard set operations such as union and set difference.

func Difference

func Difference[T comparable](A, B Set[T]) Set[T]

Difference returns the set difference of sets A and B. The result contains all elements of A which cannot be found in B.

func Intersect

func Intersect[T comparable](A, B Set[T]) Set[T]

Intersect returns the intersection of sets A and B. The result contains all elements of A which are also in B.

func New

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

New constructs a new set with the provided elements. Duplicate elements are collapsed.

func SymmetricDiff

func SymmetricDiff[T comparable](A, B Set[T]) Set[T]

SymmetricDiff returns the symmetric difference of sets A and B. The result contains all elements of A and B, except those elements which are found in both A and B.

func Union

func Union[T comparable](A, B Set[T]) Set[T]

Union returns the union of sets A and B. The result contains all elements of A and all elements of B.

func (Set[T]) Add

func (s Set[T]) Add(elem T)

Add adds the provided element to this set, modifying it if it does not already exist.

func (Set[T]) Contains

func (s Set[T]) Contains(elem T) bool

Contains returns true if and only if this set contains the provided element.

func (Set[T]) ContainsSet

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

ContainsSet returns true if and only if this set contains the other set.

func (Set[T]) Equals

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

Equals returns true if and only if this set is equal to other.

Jump to

Keyboard shortcuts

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