set

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: ISC Imports: 6 Imported by: 0

README

Set

Documentation

Overview

Package set implements a set data structure. A set is a collection of objects without any particular order.

Package set implements a set data structure. A set is a collection of objects without any particular order.

Package set implements a set data structure. A set is a collection of objects without any particular order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormatFunc added in v0.12.0

type FormatFunc[T any] func([]T) string

FormatFunc is a function type for formatting a set into a single string representation.

type Set

type Set[T any] interface {
	fmt.Stringer
	generic.Equaler[Set[T]]
	generic.Cloner[Set[T]]
	generic.Collection1[T]

	CloneEmpty() Set[T]
	IsSubset(Set[T]) bool
	IsSuperset(Set[T]) bool
	Union(...Set[T]) Set[T]
	Intersection(...Set[T]) Set[T]
	Difference(...Set[T]) Set[T]
}

Set represents a set abstract data type.

func New

func New[T any](equal generic.EqualFunc[T], vals ...T) Set[T]

New creates a new set that does not maintain any specific order for its members.

func NewSorted added in v0.11.0

func NewSorted[T any](compare generic.CompareFunc[T], vals ...T) Set[T]

NewSorted creates a new set that maintains its members in sorted order. This is useful for cases where a sorted ordering of set members is required.

func NewSortedWithFormat added in v0.11.0

func NewSortedWithFormat[T any](compare generic.CompareFunc[T], format FormatFunc[T], vals ...T) Set[T]

NewSortedWithFormat creates a new sorted set with a custom format for String method.

func NewStable added in v0.11.0

func NewStable[T any](equal generic.EqualFunc[T], vals ...T) Set[T]

NewStable creates a new set that preserves the order in which members are added. This is useful for cases where a deterministic ordering of set members is required.

func NewStableWithFormat added in v0.11.0

func NewStableWithFormat[T any](equal generic.EqualFunc[T], format FormatFunc[T], vals ...T) Set[T]

NewStableWithFormat creates a new stable set with a custom format for String method.

func NewWithFormat added in v0.10.3

func NewWithFormat[T any](equal generic.EqualFunc[T], format FormatFunc[T], vals ...T) Set[T]

NewWithFormat creates a new set with a custom format for String method.

func Partitions added in v0.4.2

func Partitions[T any](s Set[T]) Set[Set[Set[T]]]

Partitions creates and returns the set of all partitions for a given set. A partition of a set is a grouping of its elements into non-empty subsets, in such a way that every element is included in exactly one subset.

Set[T]            A set
Set[Set[T]        A partition (a set of non-empty disjoint subsets with every element included)
Set[Set[Set[T]]]  The set of all partitions

func Powerset added in v0.4.2

func Powerset[T any](s Set[T]) Set[Set[T]]

Powerset creates and returns the power set of a given set. The power set of a set is the set of all subsets, including the empty set and the set itself.

Set[T]      A set
Set[Set[T]  The power set (the set of all subsets)

Jump to

Keyboard shortcuts

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