Documentation ¶
Index ¶
- Constants
- type MultiSet
- func (ms *MultiSet[T]) Begin() *SetIterator[T]
- func (ms *MultiSet[T]) Clear()
- func (ms *MultiSet[T]) Contains(element T) bool
- func (ms *MultiSet[T]) Erase(element T)
- func (ms *MultiSet[T]) Find(element T) *SetIterator[T]
- func (ms *MultiSet[T]) First() *SetIterator[T]
- func (ms *MultiSet[T]) Insert(element T)
- func (ms *MultiSet[T]) Last() *SetIterator[T]
- func (ms *MultiSet[T]) LowerBound(element T) *SetIterator[T]
- func (ms *MultiSet[T]) Size() int
- func (ms *MultiSet[T]) String() string
- func (ms *MultiSet[T]) Traversal(visitor visitor.Visitor[T])
- func (ms *MultiSet[T]) UpperBound(element T) *SetIterator[T]
- type Option
- type Options
- type Set
- func (s *Set[T]) Begin() *SetIterator[T]
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(element T) bool
- func (s *Set[T]) Diff(other *Set[T]) *Set[T]
- func (s *Set[T]) Erase(element T)
- func (s *Set[T]) Find(element T) *SetIterator[T]
- func (s *Set[T]) First() *SetIterator[T]
- func (s *Set[T]) Insert(element T)
- func (s *Set[T]) Intersect(other *Set[T]) *Set[T]
- func (s *Set[T]) Last() *SetIterator[T]
- func (s *Set[T]) LowerBound(element T) *SetIterator[T]
- func (s *Set[T]) Size() int
- func (s *Set[T]) String() string
- func (s *Set[T]) Traversal(visitor visitor.Visitor[T])
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- func (s *Set[T]) UpperBound(element T) *SetIterator[T]
- type SetIterator
- func (iter *SetIterator[T]) Clone() iterator.ConstIterator[T]
- func (iter *SetIterator[T]) Equal(other iterator.ConstIterator[T]) bool
- func (iter *SetIterator[K]) IsValid() bool
- func (iter *SetIterator[T]) Next() iterator.ConstIterator[T]
- func (iter *SetIterator[T]) Prev() iterator.ConstBidIterator[T]
- func (iter *SetIterator[T]) Value() T
Constants ¶
const (
Empty = true
)
constants definition
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MultiSet ¶
type MultiSet[T any] struct { // contains filtered or unexported fields }
MultiSet uses RbTress for internal data structure, and keys can bee repeated.
func NewMultiSet ¶
func NewMultiSet[T any](cmp comparator.Comparator[T], opts ...Option) *MultiSet[T]
NewMultiSet creates a new MultiSet
func (*MultiSet[T]) Begin ¶
func (ms *MultiSet[T]) Begin() *SetIterator[T]
Begin returns the iterator with the minimum element in the MultiSet
func (*MultiSet[T]) Clear ¶
func (ms *MultiSet[T]) Clear()
Clear clears all elements in the MultiSet
func (*MultiSet[T]) Contains ¶
Contains returns true if the passed element is in the MultiSet. otherwise returns false.
func (*MultiSet[T]) Erase ¶
func (ms *MultiSet[T]) Erase(element T)
Erase erases all node with passed element in the MultiSet
func (*MultiSet[T]) Find ¶
func (ms *MultiSet[T]) Find(element T) *SetIterator[T]
Find finds the first element that is equal to the passed element in the MultiSet, and returns its iterator
func (*MultiSet[T]) First ¶
func (ms *MultiSet[T]) First() *SetIterator[T]
First returns the iterator with the minimum element in the MultiSet
func (*MultiSet[T]) Insert ¶
func (ms *MultiSet[T]) Insert(element T)
Insert inserts an element to the MultiSet
func (*MultiSet[T]) Last ¶
func (ms *MultiSet[T]) Last() *SetIterator[T]
Last returns the iterator with the maximum element in the MultiSet
func (*MultiSet[T]) LowerBound ¶
func (ms *MultiSet[T]) LowerBound(element T) *SetIterator[T]
LowerBound finds the first element that is equal to or greater than the passed element in the MultiSet, and returns its iterator
func (*MultiSet[T]) Traversal ¶
Traversal traversals elements in the MultiSet, it will not stop until to the end of the MultiSet or the visitor returns false
func (*MultiSet[T]) UpperBound ¶ added in v1.1.0
func (ms *MultiSet[T]) UpperBound(element T) *SetIterator[T]
UpperBound finds the first element that is greater than the passed element in the MultiSet, and returns its iterator
type Option ¶
type Option func(option *Options)
Option is a function type used to set Options
func WithGoroutineSafe ¶
func WithGoroutineSafe() Option
WithGoroutineSafe is used to set the set goroutine-safe Note that iterators are not goroutine safe, and it is useless to turn on the setting option here. so don't use iterators in multi goroutines
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options holds the Set's options
type Set ¶
type Set[T any] struct { // contains filtered or unexported fields }
Set uses RbTress for internal data structure, and every key can must bee unique.
func New ¶
func New[T any](cmp comparator.Comparator[T], opts ...Option) *Set[T]
New creates a new set
func (*Set[T]) Begin ¶
func (s *Set[T]) Begin() *SetIterator[T]
Begin returns the iterator with the minimum element in the set
func (*Set[T]) Contains ¶
Contains returns true if the passed element is in the Set. otherwise returns false.
func (*Set[T]) Diff ¶
Diff returns a new set with the elements in the set s but not in the passed set Please ensure s set and other set uses the same keyCmp
func (*Set[T]) Find ¶
func (s *Set[T]) Find(element T) *SetIterator[T]
Find finds the element's node in the set, and return its iterator
func (*Set[T]) First ¶
func (s *Set[T]) First() *SetIterator[T]
First returns the iterator with the minimum element in the set
func (*Set[T]) Intersect ¶
Intersect returns a new set with the common elements in the set s and the passed set Please ensure s set and other set uses the same keyCmp
func (*Set[T]) Last ¶
func (s *Set[T]) Last() *SetIterator[T]
Last returns the iterator with the maximum element in the set
func (*Set[T]) LowerBound ¶
func (s *Set[T]) LowerBound(element T) *SetIterator[T]
LowerBound finds the first element that equal or greater than the passed element in the set, and returns its iterator
func (*Set[T]) Traversal ¶
Traversal traversals elements in the set, it will not stop until to the end of the set or the visitor returns false
func (*Set[T]) Union ¶
Union returns a new set with the all elements in the set s and the passed set Please ensure s set and other set uses the same keyCmp
func (*Set[T]) UpperBound ¶ added in v1.1.0
func (s *Set[T]) UpperBound(element T) *SetIterator[T]
UpperBound finds the first element that greater than the passed element in the set, and returns its iterator
type SetIterator ¶
type SetIterator[T any] struct { // contains filtered or unexported fields }
SetIterator is an iterator implementation of set
func (*SetIterator[T]) Clone ¶
func (iter *SetIterator[T]) Clone() iterator.ConstIterator[T]
Clone clones the iterator into a new SetIterator
func (*SetIterator[T]) Equal ¶
func (iter *SetIterator[T]) Equal(other iterator.ConstIterator[T]) bool
Equal returns true if the iterator is equal to the passed iterator
func (*SetIterator[K]) IsValid ¶
func (iter *SetIterator[K]) IsValid() bool
IsValid returns true if the iterator is valid, otherwise returns false
func (*SetIterator[T]) Next ¶
func (iter *SetIterator[T]) Next() iterator.ConstIterator[T]
Next moves the pointer of the iterator to the next node and returns itself
func (*SetIterator[T]) Prev ¶
func (iter *SetIterator[T]) Prev() iterator.ConstBidIterator[T]
Prev moves the pointer of the iterator to the previous node and returns itself
func (*SetIterator[T]) Value ¶
func (iter *SetIterator[T]) Value() T
Value returns the element of the iterator point to