Documentation
¶
Overview ¶
Package linkedhashset is a set that preserves insertion-order.
It is backed by a hash table to store values and doubly-linked list to store ordering.
Note that insertion-order is not affected if an element is re-inserted into the set.
Structure is not thread safe.
References: http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29
Index ¶
- type Set
- func (set *Set[T]) Add(item T) bool
- func (set *Set[T]) Append(items ...T) int
- func (set *Set[T]) Clear()
- func (set *Set[T]) Clone() container.Set[T]
- func (set *Set[T]) Contains(items ...T) bool
- func (set *Set[T]) ContainsAny(val ...T) bool
- func (set *Set[T]) ContainsAnyElement(other container.Set[T]) bool
- func (set *Set[T]) ContainsOne(item T) bool
- func (set *Set[T]) Difference(another container.Set[T]) container.Set[T]
- func (set *Set[T]) Equal(other container.Set[T]) bool
- func (set *Set[T]) Intersect(another container.Set[T]) container.Set[T]
- func (set *Set[T]) IsEmpty() bool
- func (set *Set[T]) IsProperSubset(other container.Set[T]) bool
- func (set *Set[T]) IsProperSuperset(other container.Set[T]) bool
- func (set *Set[T]) IsSubset(other container.Set[T]) bool
- func (set *Set[T]) IsSuperset(other container.Set[T]) bool
- func (set *Set[T]) Iter() iter.Seq[T]
- func (set *Set[T]) Len() int
- func (set *Set[T]) MarshalJSON() ([]byte, error)
- func (set *Set[T]) Pop() (v T, ok bool)
- func (set *Set[T]) Remove(item T)
- func (set *Set[T]) RemoveAll(items ...T)
- func (set *Set[T]) String() string
- func (set *Set[T]) SymmetricDifference(another container.Set[T]) container.Set[T]
- func (set *Set[T]) ToSlice() []T
- func (set *Set[T]) Union(another container.Set[T]) container.Set[T]
- func (set *Set[T]) UnmarshalJSON(data []byte) error
- func (set *Set[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set holds elements in go's native map.
func New ¶
func New[T comparable]() *Set[T]
New instantiates a new empty set and adds the passed values, if any, to the set.
func NewFrom ¶ added in v0.9.0
func NewFrom[T comparable](values ...T) *Set[T]
NewFrom instantiates a new empty set and adds the passed values, if any, to the set.
func NewWith ¶ added in v0.9.0
func NewWith[T comparable](size int, values ...T) *Set[T]
NewWith instantiates a new empty set and adds the passed values, if any, to the set.
func (*Set[T]) Add ¶
Add adds the items (one or more) to the set. Note that insertion-order is not affected if an element is re-inserted into the set.
func (*Set[T]) Append ¶ added in v0.9.0
Append adds the items (one or more) to the set. Note that insertion-order is not affected if an element is re-inserted into the set.
func (*Set[T]) Clone ¶ added in v0.9.0
Clone returns a clone of the set using the same implementation, duplicating all keys.
func (*Set[T]) Contains ¶
Contains check if items (one or more) are present in the set. All items have to be present in the set for the method to return true. Returns true if no arguments are passed at all, i.e. set is always superset of empty set.
func (*Set[T]) ContainsAny ¶ added in v0.9.0
ContainsAny returns whether at least one of the given items are in the set.
func (*Set[T]) ContainsAnyElement ¶ added in v0.9.0
ContainsAnyElement returns whether at least one of the given element are in the set.
func (*Set[T]) ContainsOne ¶ added in v0.9.0
ContainsOne check if item is present in the set.
func (*Set[T]) Difference ¶
Difference returns the difference between two sets. The new set consists of all elements that are in "set" but not in "another". Ref: https://proofwiki.org/wiki/Definition:Set_Difference
func (*Set[T]) Intersect ¶ added in v0.9.0
Intersect returns the intersection between two sets. The new set consists of all elements that are both in "set" and "another". Ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)
func (*Set[T]) IsProperSubset ¶ added in v0.9.0
IsProperSubset returns whether this set is a proper subset of the other set.
func (*Set[T]) IsProperSuperset ¶ added in v0.9.0
IsProperSuperset returns whether this set is a proper superset of the other set.
func (*Set[T]) IsSubset ¶ added in v0.9.0
IsSubset returns whether this set is a subset of the other set.
func (*Set[T]) IsSuperset ¶ added in v0.9.0
IsSuperset returns whether this set is a superset of the other set.
func (*Set[T]) Iter ¶ added in v0.4.1
Iter returns an iterator over the values of the set, in insertion order.
func (*Set[T]) MarshalJSON ¶
MarshalJSON outputs the JSON representation of the set.
func (*Set[T]) Remove ¶
func (set *Set[T]) Remove(item T)
Remove removes the item from the set. This operation is now O(1) on average due to direct element access.
func (*Set[T]) RemoveAll ¶ added in v0.9.0
func (set *Set[T]) RemoveAll(items ...T)
RemoveAll removes the items (one or more) from the set. This operation is now O(1) on average due to direct element access.
func (*Set[T]) SymmetricDifference ¶ added in v0.9.0
SymmetricDifference returns the symmetric difference between two sets. The new set consists of all elements that are in "set" or "another" but not in both. Ref: https://proofwiki.org/wiki/Definition:Set_Difference
func (*Set[T]) ToSlice ¶ added in v0.9.0
func (set *Set[T]) ToSlice() []T
ToSlice returns all items in the set as a slice.
func (*Set[T]) Union ¶
Union returns the union of two sets. The new set consists of all elements that are in "set" or "another" (possibly both). Ref: https://en.wikipedia.org/wiki/Union_(set_theory)
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON populates the set from the input JSON representation.