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 Iterator
- func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int
- func (it *Iterator[T]) Get() (value T, found bool)
- func (it *Iterator[T]) GetAt(i int) (value T, found bool)
- func (it *Iterator[T]) Index() (index int, found bool)
- func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBegin() bool
- func (it *Iterator[T]) IsEnd() bool
- func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
- func (it *Iterator[T]) IsFirst() bool
- func (it *Iterator[T]) IsLast() bool
- func (it *Iterator[T]) IsValid() bool
- func (it *Iterator[T]) MoveBy(n int) bool
- func (it *Iterator[T]) MoveTo(i int) bool
- func (it *Iterator[T]) Next() bool
- func (it *Iterator[T]) NextN(i int) bool
- func (it *Iterator[T]) Previous() bool
- func (it *Iterator[T]) PreviousN(n int) bool
- func (it *Iterator[T]) Set(value T) bool
- func (it *Iterator[T]) SetAt(i int, value T) bool
- func (it *Iterator[T]) Size() int
- type Set
- func (set *Set[T]) Add(items ...T)
- func (s *Set[T]) Begin(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (set *Set[T]) Clear()
- func (set *Set[T]) Contains(items ...T) bool
- func (s *Set[T]) End(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (s *Set[T]) First(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (set *Set[T]) FromJSON(data []byte) error
- func (set *Set[T]) GetValues() []T
- func (set *Set[T]) IsEmpty() bool
- func (s *Set[T]) Last(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (set *Set[T]) MakeDifferenceWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MakeIntersectionWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MakeUnionWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) NewIterator(position int, size int, comparator utils.Comparator[T]) *Iterator[T]
- func (set *Set[T]) Remove(comparator utils.Comparator[T], items ...T)
- func (set *Set[T]) Size() int
- func (set *Set[T]) ToJSON() ([]byte, error)
- func (set *Set[T]) ToString() string
- func (set *Set[T]) UnmarshalJSON(bytes []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T comparable] struct { // contains filtered or unexported fields }
func (*Iterator[T]) DistanceTo ¶ added in v0.10.0
func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int
func (*Iterator[T]) IsAfter ¶ added in v0.10.0
func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
func (*Iterator[T]) IsBefore ¶ added in v0.10.0
func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
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](values ...T) *Set[T]
New instantiates a new empty set and adds the passed values, if any, to the set
func NewFromIterator ¶ added in v0.10.0
func NewFromIterator[T comparable](begin ds.ReadCompForIndexIterator[T]) *Set[T]
NewFromIterator instantiates a new set containing the elements provided by the passed iterator.
func NewFromIterators ¶ added in v0.10.0
func NewFromIterators[T comparable](begin ds.ReadCompForIndexIterator[T], end ds.CompIndexIterator) *Set[T]
NewFromIterators instantiates a new set containing the elements provided by first, until it is equal to end. end is a sentinel and not included.
func NewFromSlice ¶ added in v0.10.0
func NewFromSlice[T comparable](slice []T) *Set[T]
NewFromMap instantiates a new set from the provided slice.
func (*Set[T]) Add ¶
func (set *Set[T]) Add(items ...T)
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]) Begin ¶ added in v0.10.0
func (s *Set[T]) Begin(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
Begin returns an initialized, reversed iterator, which points to one element before it's first. Unless Next() is called, the iterator is in an invalid state.
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]) End ¶ added in v0.10.0
func (s *Set[T]) End(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
End returns an initialized,reversed iterator, which points to one element afrer it's last. Unless Previous() is called, the iterator is in an invalid state.
func (*Set[T]) First ¶ added in v0.10.0
func (s *Set[T]) First(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
First returns an initialized, reversed iterator, which points to it's first element.
func (*Set[T]) GetValues ¶ added in v0.3.0
func (set *Set[T]) GetValues() []T
Values returns all items in the set.
func (*Set[T]) Last ¶ added in v0.10.0
func (s *Set[T]) Last(comparator utils.Comparator[T]) ds.ReadWriteOrdCompBidRandCollIterator[int, T]
Last returns an initialized, reversed iterator, which points to it's last element.
func (*Set[T]) MakeDifferenceWith ¶ added in v0.3.0
Difference returns the difference between two sets. The new set consists of all elements that are in "set" but not in "other". Ref: https://proofwiki.org/wiki/Definition:Set_Difference
func (*Set[T]) MakeIntersectionWith ¶ added in v0.3.0
Intersection returns the intersection between two sets. The new set consists of all elements that are both in "set" and "other". Ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)
func (*Set[T]) MakeUnionWith ¶ added in v0.3.0
Union returns the union of two sets. The new set consists of all elements that are in "set" or "other" (possibly both). Ref: https://en.wikipedia.org/wiki/Union_(set_theory)
func (*Set[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Set[T]) NewIterator ¶ added in v0.10.0
func (*Set[T]) Remove ¶
func (set *Set[T]) Remove(comparator utils.Comparator[T], items ...T)
Remove removes the items (one or more) from the set. Slow operation, worst-case O(n^2).
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler