set

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	Empty = 0
)

constants definition

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiSet

type MultiSet struct {
	// contains filtered or unexported fields
}

MultiSet uses RbTress for internal data structure, and keys can bee repeated.

func NewMultiSet

func NewMultiSet(opts ...Option) *MultiSet

NewMultiSet creates a new MultiSet

func (*MultiSet) Begin

func (ms *MultiSet) Begin() *SetIterator

Begin returns the iterator with the minimum element in the MultiSet

func (*MultiSet) Clear

func (ms *MultiSet) Clear()

Clear clears all elements in the MultiSet

func (*MultiSet) Contains

func (ms *MultiSet) Contains(element interface{}) bool

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

func (*MultiSet) Erase

func (ms *MultiSet) Erase(element interface{})

Erase erases all node with passed element in the MultiSet

func (*MultiSet) Find

func (ms *MultiSet) Find(element interface{}) *SetIterator

Find finds the first element that is equal to the passed element in the MultiSet, and returns its iterator

func (*MultiSet) First

func (ms *MultiSet) First() *SetIterator

First returns the iterator with the minimum element in the MultiSet

func (*MultiSet) Insert

func (ms *MultiSet) Insert(element interface{})

Insert inserts an element to the MultiSet

func (*MultiSet) Last

func (ms *MultiSet) Last() *SetIterator

Last returns the iterator with the maximum element in the MultiSet

func (*MultiSet) LowerBound

func (ms *MultiSet) LowerBound(element interface{}) *SetIterator

LowerBound finds the first element that is equal to or greater than the passed element in the MultiSet, and returns its iterator

func (*MultiSet) Size

func (ms *MultiSet) Size() int

Size returns the amount of elements in the MultiSet

func (*MultiSet) String

func (ms *MultiSet) String() string

String returns s string representation of the MultiSet

func (*MultiSet) Traversal

func (ms *MultiSet) Traversal(visitor visitor.Visitor)

Traversal traversals elements in the MultiSet, it will not stop until to the end of the MultiSet or the visitor returns false

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

func WithKeyComparator

func WithKeyComparator(cmp comparator.Comparator) Option

WithKeyComparator is used to set the key comparator for a set

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options holds the Set's options

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set uses RbTress for internal data structure, and every key can must bee unique.

func New

func New(opts ...Option) *Set

New creates a new set

func (*Set) Begin

func (s *Set) Begin() *SetIterator

Begin returns the iterator with the minimum element in the set

func (*Set) Clear

func (s *Set) Clear()

Clear clears the set

func (*Set) Contains

func (s *Set) Contains(element interface{}) bool

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

func (*Set) Diff

func (s *Set) Diff(other *Set) *Set

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

func (s *Set) Erase(element interface{})

Erase erases an element from the set

func (*Set) Find

func (s *Set) Find(element interface{}) *SetIterator

Find finds the element's node in the set, and return its iterator

func (*Set) First

func (s *Set) First() *SetIterator

First returns the iterator with the minimum element in the set

func (*Set) Insert

func (s *Set) Insert(element interface{})

Insert inserts an element to the set

func (*Set) Intersect

func (s *Set) Intersect(other *Set) *Set

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) Last

func (s *Set) Last() *SetIterator

Last returns the iterator with the maximum element in the set

func (*Set) LowerBound

func (s *Set) LowerBound(element interface{}) *SetIterator

LowerBound finds the first element that equal or greater than the passed element in the set, and returns its iterator

func (*Set) Size

func (s *Set) Size() int

Size returns the amount of element in the set

func (*Set) String

func (s *Set) String() string

String returns a string representation of the set

func (*Set) Traversal

func (s *Set) Traversal(visitor visitor.Visitor)

Traversal traversals elements in the set, it will not stop until to the end of the set or the visitor returns false

func (*Set) Union

func (s *Set) Union(other *Set) *Set

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

type SetIterator

type SetIterator struct {
	// contains filtered or unexported fields
}

SetIterator is an iterator implementation of set

func (*SetIterator) Clone

func (iter *SetIterator) Clone() iterator.ConstIterator

Clone clones the iterator into a new SetIterator

func (*SetIterator) Equal

func (iter *SetIterator) Equal(other iterator.ConstIterator) bool

Equal returns true if the iterator is equal to the passed iterator

func (*SetIterator) IsValid

func (iter *SetIterator) IsValid() bool

IsValid returns true if the iterator is valid, otherwise returns false

func (*SetIterator) Next

func (iter *SetIterator) Next() iterator.ConstIterator

Next moves the pointer of the iterator to the next node and returns itself

func (*SetIterator) Prev

func (iter *SetIterator) Prev() iterator.ConstBidIterator

Prev moves the pointer of the iterator to the previous node and returns itself

func (*SetIterator) Value

func (iter *SetIterator) Value() interface{}

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