hashset

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 4 Imported by: 1

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.Adds(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)
set.Remove(4)           // 5, 3, 2, 1 (random order)
set.Removes(2, 3)       // 1, 5 (random order)
set.Contain(1)          // true
set.Contains(1, 5)      // true
set.Contains(1, 6)      // false
_ = set.Values()        // []int{5,1} (random order)
set.Clear()             // empty
set.IsEmpty()           // true
set.Len()               // 0
Output:

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]) AddCol

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

AddCol adds all items of another collection

func (*HashSet[T]) Adds

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

Adds Adds all items of vs to the set

func (*HashSet[T]) Clear

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

Clear clears the hash set.

func (*HashSet[T]) Contain

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

Contain Test to see if the list contains the value v

func (*HashSet[T]) ContainCol

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

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

func (*HashSet[T]) ContainIter

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

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

func (*HashSet[T]) Contains

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

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

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 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]) Removes

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

Removes delete items of 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]) Retains

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

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

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