set

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package set is based on public code from John Arundel, goroutine safety added. It defines goroutine-safe methods for manipulating a generic set data structure via the standard operations Add, Contains, Intersection, Members, String and Union

URL: https://bitfieldconsulting.com/posts/generic-set

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

Set is a generics implementation of the set data type

func New

func New[E comparable](vals ...E) *Set[E]

New creates a new Set

func (*Set[E]) Add

func (s *Set[E]) Add(vals ...E)

Add puts a new value into a Set

func (*Set[E]) Clear

func (s *Set[E]) Clear()

Clear removes all values from a Set

func (*Set[E]) Contains

func (s *Set[E]) Contains(v E) bool

Contains checks if a value is in the Set

func (*Set[E]) Delete

func (s *Set[E]) Delete(vals ...E)

Delete remove values(s) from a Set

func (*Set[E]) Difference

func (s *Set[E]) Difference(s2 *Set[E]) *Set[E]

Difference returns the set of values that are in s (set A) but not in s2 (set B) ... i.e. A - B

func (*Set[E]) Disjoint

func (s *Set[E]) Disjoint(s2 *Set[E]) bool

Disjoint returns true if the intersection of s with another set s2 is empty

func (*Set[E]) Empty

func (s *Set[E]) Empty() bool

Empty returns true if the Set is empty

func (*Set[E]) Intersection

func (s *Set[E]) Intersection(s2 *Set[E]) *Set[E]

Intersection returns the logical intersection of 2 Sets

func (*Set[E]) Members

func (s *Set[E]) Members() []E

Members returns a slice of the values in a Set

func (*Set[E]) Size

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

Size returns the number of values in a Set

func (*Set[E]) String

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

String returns a string representation of the Set members

func (*Set[E]) Union

func (s *Set[E]) Union(s2 *Set[E]) *Set[E]

Union returns the logical union of 2 Sets

Jump to

Keyboard shortcuts

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