set

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package set contains set implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyInto

func CopyInto[T comparable](dest, src Set[T])

CopyInto copies all the elements from src into dest.

func Equal

func Equal[T comparable](a, b Set[T]) bool

Equal returns true if two sets have the same elements.

func SortedElements

func SortedElements[T constraints.Ordered](s Set[T]) []T

SortedElements returns the set's entries as an ordered slice.

Types

type MapSet

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

MapSet is an unordered Set backed by the builtin map type.

func New

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

New creates a new set with the given elements.

func (MapSet[T]) Add

func (m MapSet[T]) Add(elem T)

func (MapSet[T]) AddAll

func (m MapSet[T]) AddAll(elems ...T)

func (MapSet[T]) Clear

func (m MapSet[T]) Clear()

func (MapSet[T]) Diff

func (m MapSet[T]) Diff(o MapSet[T]) MapSet[T]

func (MapSet[T]) Elements

func (m MapSet[T]) Elements() []T

func (MapSet[T]) Has

func (m MapSet[T]) Has(value T) bool

func (MapSet[T]) Iterate

func (m MapSet[T]) Iterate(callback func(value T) bool)

func (MapSet[T]) Len

func (m MapSet[T]) Len() int

func (MapSet[T]) Remove

func (m MapSet[T]) Remove(elem T)

func (MapSet[T]) RemoveAll

func (m MapSet[T]) RemoveAll(elems ...T)

type Set

type Set[T comparable] interface {
	// Add puts an element into the set.
	Add(elem T)

	// AddAll puts many elements into the set.
	AddAll(elems ...T)

	// Remove removes an element from the set.
	Remove(elem T)

	// RemoveAll removes all the given elements from the set.
	RemoveAll(elems ...T)

	// Clear removes all elements from the set.
	Clear()

	// Has returns true if the set contains the given element.
	Has(elem T) bool

	// Elements returns all elements in the set in a non-deterministic order.
	// For empty sets, this may return either nil or an empty slice.
	Elements() []T

	// Iterate invokes the callback for every element in the set.
	// Values are iterated in a non-deterministic order.
	// If the callback returns false then iteration will stop.
	Iterate(callback func(elem T) bool)

	// Len returns the number of elements in the set.
	Len() int
}

Set is a mutable unordered set of comparable elements. This is a minimal interface for a set type.

func Difference

func Difference[T comparable](a, b Set[T]) Set[T]

Difference returns a new set representing the difference between sets a and b, that is, elements which only exist in set a and not set b. The first argument is a function which returns a new empty set into which the resulting elements are added.

type SyncStrings

type SyncStrings interface {
	Has(n string) bool
	Add(elts ...string)
	Del(elts ...string)
	Clone() SyncStrings
	Minus(other SyncStrings) SyncStrings
	Entries() []string
	SortedEntries() []string
	Empty() bool
	Len() int
	Join(sep string) string
	Equal(other SyncStrings) bool
}

SyncStrings is a set of strings where all operations are protected by a mutex. Prefer using the generic Set and New instead of SyncStrings and NewSyncStrings.

func NewSyncStrings

func NewSyncStrings(elts ...string) SyncStrings

NewSyncStrings returns a new string set pre-populated with elements.

Jump to

Keyboard shortcuts

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