hashset

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashSet

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

HashSet an unordered collection of unique values. The zero value for HashSet is an empty set ready to use. http://en.wikipedia.org/wiki/Set_(computer_science%29)

Example
set := NewHashSet[int]()
set.Add(1)                // 1
set.AddAll(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)
set.Remove(4)             // 5, 3, 2, 1 (random order)
set.RemoveAll(2, 3)       // 1, 5 (random order)
set.Contains(1)           // true
set.ContainsAll(1, 5)     // true
set.ContainsAll(1, 6)     // false
_ = set.Values()          // []int{5,1} (random order)
set.Clear()               // empty
set.IsEmpty()             // true
set.Len()                 // 0

func NewHashSet

func NewHashSet[T comparable](vs ...T) *HashSet[T]

NewHashSet Create a new hash set

func (*HashSet[T]) Add

func (hs *HashSet[T]) Add(v T)

Add Add the item v to the set

func (*HashSet[T]) AddAll added in v1.0.27

func (hs *HashSet[T]) AddAll(vs ...T)

AddAll AddAll all items of vs to the set

func (*HashSet[T]) AddCol

func (hs *HashSet[T]) AddCol(ac cog.Collection[T])

AddCol adds all items of another collection

func (*HashSet[T]) Clear

func (hs *HashSet[T]) Clear()

Clear clears the hash set.

func (*HashSet[T]) Contains

func (hs *HashSet[T]) Contains(v T) bool

Contains Test to see if the list contains the value v

func (*HashSet[T]) ContainsAll added in v1.0.27

func (hs *HashSet[T]) ContainsAll(vs ...T) bool

ContainsAll Test to see if the collection contains all items of vs

func (*HashSet[T]) ContainsAny added in v1.2.9

func (hs *HashSet[T]) ContainsAny(vs ...T) bool

ContainsAll Test to see if the collection contains any item of vs

func (*HashSet[T]) ContainsCol added in v1.0.27

func (hs *HashSet[T]) ContainsCol(ac cog.Collection[T]) bool

ContainsCol Test to see if the collection contains all items of another collection

func (*HashSet[T]) ContainsIter added in v1.0.27

func (hs *HashSet[T]) ContainsIter(it cog.Iterator[T]) bool

ContainsIter Test to see if the collection contains all items of iterator 'it'

func (*HashSet[T]) Difference

func (hs *HashSet[T]) Difference(a *HashSet[T]) *HashSet[T]

Difference Find the difference btween two sets

func (*HashSet[T]) Each

func (hs *HashSet[T]) Each(f func(int, T) bool)

Each Call f for each item in the set

func (*HashSet[T]) Intersection

func (hs *HashSet[T]) Intersection(a *HashSet[T]) *HashSet[T]

Intersection Find the intersection of two sets

func (*HashSet[T]) IsEmpty

func (hs *HashSet[T]) IsEmpty() bool

IsEmpty returns true if the set's length == 0

func (*HashSet[T]) Len

func (hs *HashSet[T]) Len() int

Len Return the number of items in the set

func (*HashSet[T]) MarshalJSON

func (hs *HashSet[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements type json.Marshaler interface, so can be called in json.Marshal(hs)

func (*HashSet[T]) Remove

func (hs *HashSet[T]) Remove(v T)

Remove remove all items with associated value v

func (*HashSet[T]) RemoveAll added in v1.0.27

func (hs *HashSet[T]) RemoveAll(vs ...T)

RemoveAll delete items of vs

func (*HashSet[T]) RemoveCol

func (hs *HashSet[T]) RemoveCol(ac cog.Collection[T])

RemoveCol remove all of this collection's elements that are also contained in the specified collection

func (*HashSet[T]) RemoveFunc

func (hs *HashSet[T]) RemoveFunc(f func(T) bool)

RemoveFunc remove all items that function f returns true

func (*HashSet[T]) RemoveIter

func (hs *HashSet[T]) RemoveIter(it cog.Iterator[T])

RemoveIter remove all items in the iterator it

func (*HashSet[T]) RetainAll added in v1.0.27

func (hs *HashSet[T]) RetainAll(vs ...T)

RetainAll Retains only the elements in this collection that are contained in the argument array vs.

func (*HashSet[T]) RetainCol

func (hs *HashSet[T]) RetainCol(ac cog.Collection[T])

RetainCol Retains only the elements in this collection that are contained in the specified collection.

func (*HashSet[T]) RetainFunc

func (hs *HashSet[T]) RetainFunc(f func(T) bool)

RetainFunc Retains all items that function f returns true

func (*HashSet[T]) Seq added in v1.0.27

func (hs *HashSet[T]) Seq() iter.Seq[T]

Seq returns a iter.Seq[T] for range

func (*HashSet[T]) String

func (hs *HashSet[T]) String() string

String print the set to string

func (*HashSet[T]) UnmarshalJSON

func (hs *HashSet[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, hs)

func (*HashSet[T]) Values

func (hs *HashSet[T]) Values() []T

Values returns a slice contains all the items of the set hs

Jump to

Keyboard shortcuts

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