hashset

package
v0.0.0-...-749c54f Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package hashset implements a set data structure based on hash table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[K comparable](s1, s2 *HashSet[K]) bool

Equal reports whether two sets contain the same elements

Types

type HashSet

type HashSet[K comparable] struct {
	// contains filtered or unexported fields
}

HashSet holds a set of unique elements

func Collect

func Collect[K comparable](seq iter.Seq[K]) *HashSet[K]

Collect creates a new set from an iterator

func Difference

func Difference[K comparable](s1, s2 *HashSet[K]) *HashSet[K]

Difference returns a new set that contains elements that are in the first set but not in the second set

func Intersection

func Intersection[K comparable](s1, s2 *HashSet[K]) *HashSet[K]

Intersection returns a new set that contains common elements from two sets

func New

func New[K comparable]() *HashSet[K]

New creates and initialize a new HashSet

func Union

func Union[K comparable](s1, s2 *HashSet[K]) *HashSet[K]

Union returns a new set that contains all elements from two sets

func (*HashSet[K]) Add

func (s *HashSet[K]) Add(key K)

Add adds an element to the set If an element already exists in the set, it is ignored.

func (*HashSet[K]) All

func (s *HashSet[K]) All() iter.Seq[K]

All is an iterator over the elements in the set

func (*HashSet[K]) Clear

func (s *HashSet[K]) Clear()

Clear removes all elements from the set

func (*HashSet[K]) Contains

func (s *HashSet[K]) Contains(key K) bool

Contains report whether an element exists in the set

func (*HashSet[K]) Empty

func (s *HashSet[K]) Empty() bool

Empty reports whether the set is empty

func (*HashSet[K]) Len

func (s *HashSet[K]) Len() int

Len returns the number of elements in the set

func (*HashSet[K]) Remove

func (s *HashSet[K]) Remove(key K)

Remove removes an element from the set. If an element does not exist in the set, it is ignored.

Jump to

Keyboard shortcuts

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