Documentation
¶
Index ¶
- type HashSet
- func (hs *HashSet[T]) Add(v T)
- func (hs *HashSet[T]) AddCol(ac cog.Collection[T])
- func (hs *HashSet[T]) Adds(vs ...T)
- func (hs *HashSet[T]) Clear()
- func (hs *HashSet[T]) Contain(v T) bool
- func (hs *HashSet[T]) ContainCol(ac cog.Collection[T]) bool
- func (hs *HashSet[T]) ContainIter(it cog.Iterator[T]) bool
- func (hs *HashSet[T]) Contains(vs ...T) bool
- func (hs *HashSet[T]) Difference(a *HashSet[T]) *HashSet[T]
- func (hs *HashSet[T]) Each(f func(int, T) bool)
- func (hs *HashSet[T]) Intersection(a *HashSet[T]) *HashSet[T]
- func (hs *HashSet[T]) IsEmpty() bool
- func (hs *HashSet[T]) Len() int
- func (hs *HashSet[T]) MarshalJSON() ([]byte, error)
- func (hs *HashSet[T]) Remove(v T)
- func (hs *HashSet[T]) RemoveCol(ac cog.Collection[T])
- func (hs *HashSet[T]) RemoveFunc(f func(T) bool)
- func (hs *HashSet[T]) RemoveIter(it cog.Iterator[T])
- func (hs *HashSet[T]) Removes(vs ...T)
- func (hs *HashSet[T]) RetainCol(ac cog.Collection[T])
- func (hs *HashSet[T]) RetainFunc(f func(T) bool)
- func (hs *HashSet[T]) Retains(vs ...T)
- func (hs *HashSet[T]) String() string
- func (hs *HashSet[T]) UnmarshalJSON(data []byte) error
- func (hs *HashSet[T]) Values() []T
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]) AddCol ¶
func (hs *HashSet[T]) AddCol(ac cog.Collection[T])
AddCol adds all items of another collection
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 ¶
ContainIter Test to see if the collection contains all items of iterator 'it'
func (*HashSet[T]) Difference ¶
Difference Find the difference btween two sets
func (*HashSet[T]) Intersection ¶
Intersection Find the intersection of two sets
func (*HashSet[T]) MarshalJSON ¶
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 ¶
RemoveFunc remove all items that function f returns true
func (*HashSet[T]) RemoveIter ¶
RemoveIter remove all items in the iterator it
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 ¶
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]) UnmarshalJSON ¶
UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, hs)