set

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 7 Imported by: 332

Documentation

Index

Constants

View Source
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

func (ms *MultiSet[T]) Contains(element T) bool

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

func (ms *MultiSet[T]) Size() int

Size returns the amount of elements in the MultiSet

func (*MultiSet[T]) String

func (ms *MultiSet[T]) String() string

String returns s string representation of the MultiSet

func (*MultiSet[T]) Traversal

func (ms *MultiSet[T]) Traversal(visitor visitor.Visitor[T])

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

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

Clear clears the set

func (*Set[T]) Contains

func (s *Set[T]) Contains(element T) bool

Contains returns true if the passed element is in the Set. otherwise returns false.

func (*Set[T]) Diff

func (s *Set[T]) Diff(other *Set[T]) *Set[T]

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

func (s *Set[T]) Erase(element T)

Erase erases an element from the set

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

func (s *Set[T]) Insert(element T)

Insert inserts an element to the set

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

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

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

Size returns the amount of element in the set

func (*Set[T]) String

func (s *Set[T]) String() string

String returns a string representation of the set

func (*Set[T]) Traversal

func (s *Set[T]) Traversal(visitor visitor.Visitor[T])

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

func (s *Set[T]) Union(other *Set[T]) *Set[T]

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

Jump to

Keyboard shortcuts

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