set

package
v1.28.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const ElementNotInUniversalSet = "element not in universal set"
View Source
const NoUniversalSetPanic = "cannot complement without universal set"
View Source
const UniversalSetMismatch = "sets have different universal sets"

Variables

This section is empty.

Functions

This section is empty.

Types

type CartesianElement

type CartesianElement[T, U comparable] struct {
	First  T
	Second U
}

func (CartesianElement[T, U]) String

func (e CartesianElement[T, U]) String() string

type MutableSet

type MutableSet[T comparable] interface {
	Set[T]
	// Modify by adding elements
	Add(elements ...T)
	// Modify by removing elements
	Remove(elements ...T)
	// Modify to Difference between sets
	ToDifference(rhs Set[T])
	// Modify to Union of sets
	ToUnion(rhs Set[T])
	// Modify to Intersection of sets
	ToIntersection(rhs Set[T])
	// Modify to Complement the set
	ToComplement()
}

Mutable set

func MakeMutableSet

func MakeMutableSet[T comparable](elements ...T) MutableSet[T]

func MakeMutableSetWithUniversal

func MakeMutableSetWithUniversal[T comparable](universal Set[T], elements ...T) MutableSet[T]

type Set

type Set[T comparable] interface {
	fmt.Stringer
	patterns.Iteratable[T]
	// Set is empty
	IsEmpty() bool
	// Length of set
	Len() int
	// Elements as a slice
	Elements() []T
	// Equals another set (ignore universal)
	Equals(rhs Set[T]) bool
	// Hash code
	Hash() uint64
	// Operate on each element
	Foreach(action func(element T))
	// Does set contain element
	Contains(element T) bool
	// Is subset
	IsSubsetOf(rhs Set[T]) bool
	IsProperSubsetOf(rhs Set[T]) bool
	// Is superset
	IsSupersetOf(rhs Set[T]) bool
	IsProperSupersetOf(rhs Set[T]) bool
	// Add elements
	Plus(elements ...T) Set[T]
	// Remove elements
	Minus(elements ...T) Set[T]
	// Difference between sets
	Difference(rhs Set[T]) Set[T]
	// Union of sets
	Union(rhs Set[T]) Set[T]
	// Intersection of sets
	Intersection(rhs Set[T]) Set[T]
	// Complement the set
	Complement() Set[T]
	// The universal set
	UniversalSet() Set[T]
	// Create a mutable set from this
	CreateMutableSet(increaseCapacity uint) MutableSet[T]
	// contains filtered or unexported methods
}

Immutable set

func CartesianProduct

func CartesianProduct[T, U comparable](lhs Set[T], rhs Set[U]) Set[CartesianElement[T, U]]

Create cartesian product

func MakeSet

func MakeSet[T comparable](elements ...T) Set[T]

func MakeSetWithUniversal

func MakeSetWithUniversal[T comparable](universal Set[T], elements ...T) Set[T]

Jump to

Keyboard shortcuts

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