set

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

set

Go Reference

A set type for Go.

Documentation

Overview

Package set implements Set types for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapSet added in v0.3.0

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

MapSet type that implements the Set interface. It uses a Go map to store the elements.

func NewMapSet added in v0.3.0

func NewMapSet[T comparable](elems ...T) *MapSet[T]

NewMapSet returns a new MapSet with the given elements.

func (*MapSet[T]) Add added in v0.3.0

func (s *MapSet[T]) Add(elem T) bool

Add adds an element to the Set. Returns true if it was added, false if it already was in the set.

func (*MapSet[T]) Cardinality added in v0.3.0

func (s *MapSet[T]) Cardinality() int

Cardinality returns the number of elements in the Set.

func (*MapSet[T]) Clone added in v0.3.0

func (s *MapSet[T]) Clone() Set[T]

Clone clones the Set.

func (*MapSet[T]) Contains added in v0.3.0

func (s *MapSet[T]) Contains(elem T) bool

Contains reports whether the element is in the Set.

func (*MapSet[T]) Difference added in v0.3.0

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

Difference returns a new Set which is the set difference of s and s2.

func (*MapSet[T]) Elements added in v0.3.0

func (s *MapSet[T]) Elements() []T

Elements returns a slice with all elements of the Set.

func (*MapSet[T]) Equal added in v0.3.0

func (s *MapSet[T]) Equal(s2 Set[T]) bool

Equal returns true if s and s2 contain the same elements.

func (*MapSet[T]) Intersection added in v0.3.0

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

Intersection returns a new Set which is the intersection of s and s2.

func (*MapSet[T]) IsEmpty added in v0.3.0

func (s *MapSet[T]) IsEmpty() bool

IsEmpty returns true if Set is an empty set.

func (*MapSet[T]) IsProperSubset added in v0.3.0

func (s *MapSet[T]) IsProperSubset(s2 Set[T]) bool

IsProperSubset returns true if s is a proper subset of s2.

func (*MapSet[T]) IsSubset added in v0.3.0

func (s *MapSet[T]) IsSubset(s2 Set[T]) bool

IsSubset returns true if s is a subset of s2.

func (*MapSet[T]) Remove added in v0.3.0

func (s *MapSet[T]) Remove(elem T) bool

Remove removes an element from the Set. Returns true if it was in the set, false otherwise.

func (*MapSet[T]) String added in v0.3.0

func (s *MapSet[T]) String() string

String returns a string representation of the Set.

func (*MapSet[T]) SymDifference added in v0.3.0

func (s *MapSet[T]) SymDifference(s2 Set[T]) Set[T]

SymDifference returns a new Set which is the symmetric difference of s and s2.

func (*MapSet[T]) Union added in v0.3.0

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

Union returns a new Set which is the union of s and s2.

type Set

type Set[T any] interface {
	// Contains reports whether the element is in the Set.
	Contains(elem T) bool

	// Add adds an element to the Set.
	// Returns true if it was added, false if it already was in the set.
	Add(elem T) bool

	// Remove removes an element from the Set.
	// Returns true if it was in the set, false otherwise.
	Remove(elem T) bool

	// IsEmpty returns true if Set is an empty set.
	IsEmpty() bool

	// Cardinality returns the number of elements in the Set.
	Cardinality() int

	// Union returns a new Set which is the union of the Set and s2.
	Union(s2 Set[T]) Set[T]

	// Intersection returns a new Set which is the intersection of the Set and s2.
	Intersection(s2 Set[T]) Set[T]

	// Difference returns a new Set which is the set difference of the Set and s2.
	Difference(s2 Set[T]) Set[T]

	// SymDifference returns a new Set which is the symmetric difference of the Set and s2.
	SymDifference(s2 Set[T]) Set[T]

	// IsSubset returns true if the Set is a subset of s2.
	IsSubset(s2 Set[T]) bool

	// IsProperSubset returns true if the Set is a proper subset of s2.
	IsProperSubset(s2 Set[T]) bool

	// Equal returns true if the Set and s2 contain the same elements.
	Equal(s2 Set[T]) bool

	// Clone clones the Set.
	Clone() Set[T]

	// Elements returns a slice with all elements of the Set.
	Elements() []T

	// String returns a string representation of the Set.
	String() string
}

type TreeSet added in v0.3.0

type TreeSet[T any] struct {
	// contains filtered or unexported fields
}

TreeSet type that implements the Set interface. It uses an AVL tree to store the elements.

func NewTreeSet added in v0.3.0

func NewTreeSet[T cmp.Ordered](elems ...T) *TreeSet[T]

NewTreeSet returns a new TreeSet with the given elements.

func NewTreeSetFunc added in v0.3.0

func NewTreeSetFunc[T any](cmp func(T, T) int, elems ...T) *TreeSet[T]

NewTreeSetFunc returns a new TreeSet with the given elements. Function cmp is used to compare two elements. It returns 0 if a == b, -1 if a < b, and 1 if a > b.

func (*TreeSet[T]) Add added in v0.3.0

func (s *TreeSet[T]) Add(elem T) bool

Add adds an element to the Set. Returns true if it was added, false if it already was in the set.

func (*TreeSet[T]) Cardinality added in v0.3.0

func (s *TreeSet[T]) Cardinality() int

Cardinality returns the number of elements in the Set.

func (*TreeSet[T]) Clone added in v0.3.0

func (s *TreeSet[T]) Clone() Set[T]

Clone clones the Set.

func (*TreeSet[T]) Contains added in v0.3.0

func (s *TreeSet[T]) Contains(elem T) bool

Contains reports whether the element is in the Set.

func (*TreeSet[T]) Difference added in v0.3.0

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

Difference returns a new Set which is the set difference of s and s2.

func (*TreeSet[T]) Elements added in v0.3.0

func (s *TreeSet[T]) Elements() []T

Elements returns a slice with all elements of the Set.

func (*TreeSet[T]) Equal added in v0.3.0

func (s *TreeSet[T]) Equal(s2 Set[T]) bool

Equal returns true if s and s2 contain the same elements.

func (*TreeSet[T]) Intersection added in v0.3.0

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

Intersection returns a new Set which is the intersection of s and s2.

func (*TreeSet[T]) IsEmpty added in v0.3.0

func (s *TreeSet[T]) IsEmpty() bool

IsEmpty returns true if Set is an empty set.

func (*TreeSet[T]) IsProperSubset added in v0.3.0

func (s *TreeSet[T]) IsProperSubset(s2 Set[T]) bool

IsProperSubset returns true if s is a proper subset of s2.

func (*TreeSet[T]) IsSubset added in v0.3.0

func (s *TreeSet[T]) IsSubset(s2 Set[T]) bool

IsSubset returns true if s is a subset of s2.

func (*TreeSet[T]) Remove added in v0.3.0

func (s *TreeSet[T]) Remove(elem T) bool

Remove removes an element from the Set. Returns true if it was in the set, false otherwise.

func (*TreeSet[T]) String added in v0.3.0

func (s *TreeSet[T]) String() string

String returns a string representation of the Set.

func (*TreeSet[T]) SymDifference added in v0.3.0

func (s *TreeSet[T]) SymDifference(s2 Set[T]) Set[T]

SymDifference returns a new Set which is the symmetric difference of s and s2.

func (*TreeSet[T]) Union added in v0.3.0

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

Union returns a new Set which is the union of s and s2.

Jump to

Keyboard shortcuts

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