set

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package set defines a generic set type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is a generic set.

func New

func New[T comparable]() *Set[T]

New returns a new set.

func NewFromSlice

func NewFromSlice[T comparable](slice []T) *Set[T]

NewFromSlice returns a new set from a slice.

func (*Set[T]) Add

func (s *Set[T]) Add(v T)

Add adds an element to the set

func (*Set[T]) Clear

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

Clear removes all elements from a set.

func (*Set[T]) Difference

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

Difference returns a new set which elements from current set, that does not exist in other set.

func (*Set[T]) Has

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

Has reports wether an item is in this set.

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

Intersect returns a new set which contains elements found in both sets only.

func (*Set[T]) Remove

func (s *Set[T]) Remove(v T)

Remove removes an element from a set. It does nothing when the element doesn't exist.

func (*Set[T]) Size

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

Size returns the number of elements in a set.

func (*Set[T]) String

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

func (*Set[T]) ToSlice

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

ToSlice converts a set to a slice and returns it. Note that the elements in the slice have no defined order.

func (*Set[T]) Union

func (s *Set[T]) Union(other *Set[T]) *Set[T]

Union returns a new set containing the combined elements from both sets.

Jump to

Keyboard shortcuts

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