linkedhashset

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: BSD-2-Clause, ISC Imports: 7 Imported by: 0

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

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

DistanceTo implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Get added in v0.10.0

func (it *Iterator[T]) Get() (value T, found bool)

Get implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) GetAt added in v0.10.0

func (it *Iterator[T]) GetAt(i int) (value T, found bool)

GetAt implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() (index int, found bool)

Index implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsAfter added in v0.10.0

func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool

IsAfter implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsBefore added in v0.10.0

func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool

IsBefore implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsBegin added in v0.10.0

func (it *Iterator[T]) IsBegin() bool

IsBegin implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsEnd added in v0.10.0

func (it *Iterator[T]) IsEnd() bool

IsEnd implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsEqual added in v0.10.0

func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool

IsEqual implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsFirst added in v0.10.0

func (it *Iterator[T]) IsFirst() bool

IsFirst implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsLast added in v0.10.0

func (it *Iterator[T]) IsLast() bool

IsLast implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsValid added in v0.10.0

func (it *Iterator[T]) IsValid() bool

IsValid implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) MoveBy added in v0.10.0

func (it *Iterator[T]) MoveBy(n int)

MoveBy implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) MoveTo added in v0.10.0

func (it *Iterator[T]) MoveTo(i int) bool

MoveTo implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Next

func (it *Iterator[T]) Next()

Next implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) NextN added in v0.10.0

func (it *Iterator[T]) NextN(i int)

NextN implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Previous added in v0.10.0

func (it *Iterator[T]) Previous()

Previous implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) PreviousN added in v0.10.0

func (it *Iterator[T]) PreviousN(n int)

PreviousN implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Set added in v0.10.0

func (it *Iterator[T]) Set(value T) bool

Set implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) SetAt added in v0.10.0

func (it *Iterator[T]) SetAt(i int, value T) bool

SetAt implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Size added in v0.10.0

func (it *Iterator[T]) Size() int

Size implements ds.ReadWriteOrdCompBidRandCollIterator

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](it ds.ReadCompForIndexIterator[int, 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](first ds.ReadCompForIndexIterator[int, T], end ds.CompIndexIterator[int]) *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]) Clear

func (set *Set[T]) Clear()

Clear clears all values in the set.

func (*Set[T]) Contains

func (set *Set[T]) Contains(items ...T) bool

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

func (set *Set[T]) FromJSON(data []byte) error

FromJSON populates the set from the input JSON representation.

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]) IsEmpty added in v0.3.0

func (set *Set[T]) IsEmpty() bool

Empty returns true if set does not contain any elements.

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

func (set *Set[T]) MakeDifferenceWith(other sets.Set[T]) sets.Set[T]

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

func (set *Set[T]) MakeIntersectionWith(other sets.Set[T]) sets.Set[T]

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

func (set *Set[T]) MakeUnionWith(other sets.Set[T]) sets.Set[T]

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

func (set *Set[T]) MarshalJSON() ([]byte, error)

MarshalJSON @implements json.Marshaler

func (*Set[T]) NewIterator added in v0.10.0

func (m *Set[T]) NewIterator(s *Set[T], position int, comparator utils.Comparator[T]) *Iterator[T]

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

func (set *Set[T]) Size() int

Size returns number of elements within the set.

func (*Set[T]) ToJSON

func (set *Set[T]) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the set.

func (*Set[T]) ToString added in v0.3.0

func (set *Set[T]) ToString() string

String returns a string representation of container

func (*Set[T]) UnmarshalJSON

func (set *Set[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON @implements json.Unmarshaler

Jump to

Keyboard shortcuts

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