set

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package set provides simple structure with iterator

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

func New

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

func (*Set[ST]) Clone

func (s *Set[ST]) Clone() *Set[ST]

Clone returns a new set with same elements.

func (*Set[ST]) Contains

func (s *Set[ST]) Contains(element ST) bool

Contains checks is element in the set or not.

func (*Set[ST]) Difference

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

Difference returns unique elements for that set.

func (*Set[ST]) Equal

func (s *Set[ST]) Equal(other *Set[ST]) bool

Equal return true if both sets have same elements.

func (*Set[ST]) Insert

func (s *Set[ST]) Insert(elements ...ST)

Insert adds an element to the set.

func (*Set[ST]) Intersection

func (s *Set[ST]) Intersection(set *Set[ST]) *Set[ST]

Intersection returns elements which are in both sets.

func (*Set[ST]) Len

func (s *Set[ST]) Len() int

Len returns number of items in the set.

func (*Set[ST]) ProperSubsetOf

func (s *Set[ST]) ProperSubsetOf(other *Set[ST]) bool

ProperSubsetOf checks is this set a proper subset of "other".

func (*Set[ST]) Remove

func (s *Set[ST]) Remove(elements ...ST)

Remove removes all element from the set. Missing elements do nothing.

func (*Set[T]) Seq

func (s *Set[T]) Seq() iter.Seq[T]

Seq returns value-iterator.

Example
s := New(1, 2, 3, 4)
for v := range s.Seq() {
	fmt.Println(v)
}
Output:

1
2
3
4

func (*Set[ST]) SubsetOf

func (s *Set[ST]) SubsetOf(other *Set[ST]) bool

SubsetOf checks is this set a subset of "other".

func (*Set[ST]) SymmetricDifference

func (s *Set[ST]) SymmetricDifference(other *Set[ST]) (*Set[ST], *Set[ST])

SymmetricDifference returns unique elements for both sets.

func (*Set[ST]) Union

func (s *Set[ST]) Union(set *Set[ST]) *Set[ST]

Union returns all elements of both sets.

Jump to

Keyboard shortcuts

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