sets

package
v0.12.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

Set is a minimal set that takes only ordered types: any type that supports the operators < <= >= >.

func From

func From[T cmp.Ordered](elements ...T) *Set[T]

From returns a set from elements.

func New

func New[T cmp.Ordered](size int) *Set[T]

New returns an empty set with capacity size. The capacity will grow and shrink as a stdlib map.

func (*Set[T]) Contains

func (s *Set[T]) Contains(item T) bool

Contains returns true if s contains item.

func (*Set[T]) Difference

func (s *Set[T]) Difference(x *Set[T]) *Set[T]

Difference returns a set containing the elements of s that are not in x.

func (*Set[T]) OrderedList

func (s *Set[T]) OrderedList() []T

OrderedList returns a slice of the elements of s, ordered. TODO This can probably be replaced in Go 1.20 when a generics slice packages reaches the stdlib.

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T) bool

Remove deletes item from s. Returns true if the item was present.

func (*Set[T]) Size

func (s *Set[T]) Size() int

func (*Set[T]) String

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

String returns a string representation of s, ordered. This allows to simply pass a sets.Set as parameter to a function that expects a fmt.Stringer interface and obtain a comparable string.

Jump to

Keyboard shortcuts

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