Documentation ¶
Index ¶
- type Iterator
- func (iterator *Iterator[T]) Begin()
- func (iterator *Iterator[T]) End()
- func (iterator *Iterator[T]) First() bool
- func (iterator *Iterator[T]) Index() int
- func (iterator *Iterator[T]) Last() bool
- func (iterator *Iterator[T]) Next() bool
- func (iterator *Iterator[T]) NextTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Prev() bool
- func (iterator *Iterator[T]) PrevTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Value() T
- type Set
- func (set *Set[K]) Add(items ...K)
- func (set *Set[K]) All(f func(index int, value K) bool) bool
- func (set *Set[K]) Any(f func(index int, value K) bool) bool
- func (set *Set[K]) Clear()
- func (set *Set[K]) Contains(items ...K) bool
- func (set *Set[T]) Difference(another *Set[T]) *Set[T]
- func (set *Set[K]) Each(f func(index int, value K))
- func (set *Set[K]) Empty() bool
- func (set *Set[K]) Find(f func(index int, value K) bool) (int, K)
- func (set *Set[K]) FromJSON(data []byte) error
- func (set *Set[K]) Intersection(another *Set[K]) *Set[K]
- func (set *Set[T]) Iterator() Iterator[T]
- func (set *Set[K]) Map(f func(index int, value K) K) *Set[K]
- func (set *Set[K]) MarshalJSON() ([]byte, error)
- func (set *Set[K]) Remove(items ...K)
- func (set *Set[K]) Select(f func(index int, value interface{}) bool) *Set[K]
- func (set *Set[K]) Size() int
- func (set *Set[K]) String() string
- func (set *Set[_]) ToJSON() ([]byte, error)
- func (set *Set[K]) Union(another *Set[K]) *Set[K]
- func (set *Set[K]) UnmarshalJSON(bytes []byte) error
- func (set *Set[K]) Values() []K
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T constraints.Ordered] struct { // contains filtered or unexported fields }
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Iterator[T]) Begin ¶
func (iterator *Iterator[T]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator[T]) End ¶
func (iterator *Iterator[T]) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator[T]) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator[T]) Last ¶
Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator[T]) NextTo ¶
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) Prev ¶
Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) PrevTo ¶
PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
type Set ¶
type Set[K constraints.Ordered] struct { // contains filtered or unexported fields }
Set holds elements in a red-black tree
func New ¶
func New[K constraints.Ordered](values ...K) *Set[K]
NewWith instantiates a new empty set with the custom comparator.
func NewWith ¶
func NewWith[K constraints.Ordered](comparator utils.Comparator[K], values ...K) *Set[K]
NewWith instantiates a new empty set with the custom comparator.
func (*Set[K]) Add ¶
func (set *Set[K]) Add(items ...K)
Add adds the items (one or more) to the set.
func (*Set[K]) All ¶
All passes each element of the container to the given function and returns true if the function returns true for all elements.
func (*Set[K]) Any ¶
Any passes each element of the container to the given function and returns true if the function ever returns true for any element.
func (*Set[K]) Contains ¶
Contains checks weather 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]) Difference ¶
Difference returns the difference between two sets. The two sets should have the same comparators, otherwise the result is empty set. 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[K]) Each ¶
Each calls the given function once for each element, passing that element's index and value.
func (*Set[K]) Find ¶
Find passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.
func (*Set[K]) Intersection ¶
Intersection returns the intersection between two sets. The new set consists of all elements that are both in "set" and "another". The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)
func (*Set[K]) Map ¶
Map invokes the given function once for each element and returns a container containing the values returned by the given function.
func (*Set[K]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Set[K]) Remove ¶
func (set *Set[K]) Remove(items ...K)
Remove removes the items (one or more) from the set.
func (*Set[K]) Select ¶
Select returns a new container containing all elements for which the given function returns a true value.
func (*Set[K]) Union ¶
Union returns the union of two sets. The new set consists of all elements that are in "set" or "another" (possibly both). The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Union_(set_theory)
func (*Set[K]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler