Documentation ¶
Index ¶
- Variables
- type Map
- func (m *Map[K, V]) Begin() *MapIterator[K, V]
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Contains(key K) bool
- func (m *Map[K, V]) Erase(key K)
- func (m *Map[K, V]) EraseIter(iter iterator.ConstKvIterator[K, V])
- func (m *Map[K, V]) Find(key K) *MapIterator[K, V]
- func (m *Map[K, V]) First() *MapIterator[K, V]
- func (m *Map[K, V]) Get(key K) (V, error)
- func (m *Map[K, V]) Insert(key K, value V)
- func (m *Map[K, V]) Last() *MapIterator[K, V]
- func (m *Map[K, V]) LowerBound(key K) *MapIterator[K, V]
- func (m *Map[K, V]) Size() int
- func (m *Map[K, V]) Traversal(visitor visitor.KvVisitor[K, V])
- func (m *Map[K, V]) UpperBound(key K) *MapIterator[K, V]
- type MapIterator
- func (iter *MapIterator[K, V]) Clone() iterator.ConstIterator[V]
- func (iter *MapIterator[K, V]) Equal(other iterator.ConstIterator[V]) bool
- func (iter *MapIterator[K, V]) IsValid() bool
- func (iter *MapIterator[K, V]) Key() K
- func (iter *MapIterator[K, V]) Next() iterator.ConstIterator[V]
- func (iter *MapIterator[K, V]) Prev() iterator.ConstBidIterator[V]
- func (iter *MapIterator[K, V]) SetValue(val V)
- func (iter *MapIterator[K, V]) Value() V
- type MultiMap
- func (mm *MultiMap[K, V]) Begin() *MapIterator[K, V]
- func (mm *MultiMap[K, V]) Clear()
- func (mm *MultiMap[K, V]) Contains(key K) bool
- func (mm *MultiMap[K, V]) Erase(key K)
- func (mm *MultiMap[K, V]) Find(key K) *MapIterator[K, V]
- func (mm *MultiMap[K, V]) First() *MapIterator[K, V]
- func (mm *MultiMap[K, V]) Get(key K) (V, error)
- func (mm *MultiMap[K, V]) Insert(key K, value V)
- func (mm *MultiMap[K, V]) Last() *MapIterator[K, V]
- func (mm *MultiMap[K, V]) LowerBound(key K) *MapIterator[K, V]
- func (mm *MultiMap[K, V]) Size() int
- func (mm *MultiMap[K, V]) Traversal(visitor visitor.KvVisitor[K, V])
- func (mm *MultiMap[K, V]) UpperBound(key K) *MapIterator[K, V]
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrorNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K, V any] struct { // contains filtered or unexported fields }
Map uses RbTress for internal data structure, and every key can must bee unique.
func New ¶
func New[K, V any](cmp comparator.Comparator[K], opts ...Option) *Map[K, V]
New creates a new map
func (*Map[K, V]) Begin ¶
func (m *Map[K, V]) Begin() *MapIterator[K, V]
Begin returns the first node's iterator
func (*Map[K, V]) Contains ¶
Contains returns true if the key is in the map. otherwise returns false.
func (*Map[K, V]) Erase ¶
func (m *Map[K, V]) Erase(key K)
Erase erases the node by the passed key from the map if the key in the Map
func (*Map[K, V]) EraseIter ¶
func (m *Map[K, V]) EraseIter(iter iterator.ConstKvIterator[K, V])
EraseIter erases the node that iterator iter point to from the map
func (*Map[K, V]) Find ¶
func (m *Map[K, V]) Find(key K) *MapIterator[K, V]
Find finds a node by the passed key and returns its iterator
func (*Map[K, V]) First ¶
func (m *Map[K, V]) First() *MapIterator[K, V]
First returns the first node's iterator
func (*Map[K, V]) Get ¶
Get returns the value of the passed key if the key is in the map, otherwise returns nil
func (*Map[K, V]) Insert ¶
func (m *Map[K, V]) Insert(key K, value V)
Insert inserts a key-value to the map
func (*Map[K, V]) Last ¶
func (m *Map[K, V]) Last() *MapIterator[K, V]
Last returns the last node's iterator
func (*Map[K, V]) LowerBound ¶
func (m *Map[K, V]) LowerBound(key K) *MapIterator[K, V]
LowerBound finds a node that its key is equal or greater than the passed key and returns its iterator
func (*Map[K, V]) Traversal ¶
Traversal traversals elements in the map, it will not stop until to the end or the visitor returns false
func (*Map[K, V]) UpperBound ¶ added in v1.1.0
func (m *Map[K, V]) UpperBound(key K) *MapIterator[K, V]
UpperBound finds a node that its key is greater than the passed key and returns its iterator
type MapIterator ¶
type MapIterator[K, V any] struct { // contains filtered or unexported fields }
MapIterator is a map iterator
func (*MapIterator[K, V]) Clone ¶
func (iter *MapIterator[K, V]) Clone() iterator.ConstIterator[V]
Clone clones the iterator to a new MapIterator
func (*MapIterator[K, V]) Equal ¶
func (iter *MapIterator[K, V]) Equal(other iterator.ConstIterator[V]) bool
Equal returns true if the iterator is equal to the passed iterator, otherwise returns false
func (*MapIterator[K, V]) IsValid ¶
func (iter *MapIterator[K, V]) IsValid() bool
IsValid returns true if the iterator is valid, otherwise returns false
func (*MapIterator[K, V]) Key ¶
func (iter *MapIterator[K, V]) Key() K
Key returns the node's key of the iterator point to
func (*MapIterator[K, V]) Next ¶
func (iter *MapIterator[K, V]) Next() iterator.ConstIterator[V]
Next moves the pointer of the iterator to the next node, and returns itself
func (*MapIterator[K, V]) Prev ¶
func (iter *MapIterator[K, V]) Prev() iterator.ConstBidIterator[V]
Prev moves the pointer of the iterator to the previous node, and returns itseft
func (*MapIterator[K, V]) SetValue ¶
func (iter *MapIterator[K, V]) SetValue(val V)
SetValue sets the node's value of the iterator point to
func (*MapIterator[K, V]) Value ¶
func (iter *MapIterator[K, V]) Value() V
Value returns the node's value of the iterator point to
type MultiMap ¶
type MultiMap[K, V any] struct { // contains filtered or unexported fields }
MultiMap uses RbTress for internal data structure, and keys can bee repeated.
func NewMultiMap ¶
func NewMultiMap[K, V any](cmp comparator.Comparator[K], opts ...Option) *MultiMap[K, V]
NewMultiMap creates a new MultiMap
func (*MultiMap[K, V]) Begin ¶
func (mm *MultiMap[K, V]) Begin() *MapIterator[K, V]
Begin returns the first node's iterator
func (*MultiMap[K, V]) Contains ¶
Contains returns true if the passed value is in the MultiMap. otherwise returns false.
func (*MultiMap[K, V]) Erase ¶
func (mm *MultiMap[K, V]) Erase(key K)
Erase erases the key in the MultiMap
func (*MultiMap[K, V]) Find ¶
func (mm *MultiMap[K, V]) Find(key K) *MapIterator[K, V]
Find finds the node by the passed key in the MultiMap and returns its iterator
func (*MultiMap[K, V]) First ¶
func (mm *MultiMap[K, V]) First() *MapIterator[K, V]
First returns the first node's iterator
func (*MultiMap[K, V]) Get ¶
Get returns the first node's value by the passed key if the key is in the MultiMap, otherwise returns nil
func (*MultiMap[K, V]) Insert ¶
func (mm *MultiMap[K, V]) Insert(key K, value V)
Insert inserts a key-value to the MultiMap
func (*MultiMap[K, V]) Last ¶
func (mm *MultiMap[K, V]) Last() *MapIterator[K, V]
Last returns the last node's iterator
func (*MultiMap[K, V]) LowerBound ¶
func (mm *MultiMap[K, V]) LowerBound(key K) *MapIterator[K, V]
LowerBound find the first node that its key is equal or greater than the passed key in the MultiMap, and returns its iterator
func (*MultiMap[K, V]) Traversal ¶
Traversal traversals elements in the MultiMap, it will not stop until to the end of the MultiMap or the visitor returns false
func (*MultiMap[K, V]) UpperBound ¶ added in v1.1.0
func (mm *MultiMap[K, V]) UpperBound(key K) *MapIterator[K, V]
UpperBound find the first node that its key is greater than the passed key in the MultiMap, 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 a map goroutine-safe Note that iterators are not goroutine safe, and it is useless to turn on the setting option here. so don't use iterator in multi goroutines