Documentation ¶
Overview ¶
Package hashmap provides a lock-free and thread-safe HashMap.
Index ¶
- type List
- func (l *List[Key, Value]) Add(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (element *ListElement[Key, Value], existed bool, inserted bool)
- func (l *List[Key, Value]) AddOrUpdate(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (*ListElement[Key, Value], bool)
- func (l *List[Key, Value]) Delete(element *ListElement[Key, Value])
- func (l *List[Key, Value]) First() *ListElement[Key, Value]
- func (l *List[Key, Value]) Len() int
- type ListElement
- type Map
- func (m *Map[Key, Value]) Del(key Key) bool
- func (m *Map[Key, Value]) FillRate() int
- func (m *Map[Key, Value]) Get(key Key) (Value, bool)
- func (m *Map[Key, Value]) GetOrInsert(key Key, value Value) (Value, bool)
- func (m *Map[Key, Value]) Grow(newSize uintptr)
- func (m *Map[Key, Value]) Insert(key Key, value Value) bool
- func (m *Map[Key, Value]) Len() int
- func (m *Map[Key, Value]) Range(f func(Key, Value) bool)
- func (m *Map[Key, Value]) Set(key Key, value Value)
- func (m *Map[Key, Value]) SetHasher(hasher func(Key) uintptr)
- func (m *Map[Key, Value]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[Key comparable, Value any] struct { // contains filtered or unexported fields }
List is a sorted linked list.
func NewList ¶
func NewList[Key comparable, Value any]() *List[Key, Value]
NewList returns an initialized list.
func (*List[Key, Value]) Add ¶
func (l *List[Key, Value]) Add(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (element *ListElement[Key, Value], existed bool, inserted bool)
Add adds an item to the list and returns false if an item for the hash existed. searchStart = nil will start to search at the head item.
func (*List[Key, Value]) AddOrUpdate ¶
func (l *List[Key, Value]) AddOrUpdate(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (*ListElement[Key, Value], bool)
AddOrUpdate adds or updates an item to the list.
func (*List[Key, Value]) Delete ¶
func (l *List[Key, Value]) Delete(element *ListElement[Key, Value])
Delete deletes an element from the list.
func (*List[Key, Value]) First ¶
func (l *List[Key, Value]) First() *ListElement[Key, Value]
First returns the first item of the list.
type ListElement ¶
type ListElement[Key comparable, Value any] struct { // contains filtered or unexported fields }
ListElement is an element of a list.
func (*ListElement[Key, Value]) Next ¶
func (e *ListElement[Key, Value]) Next() *ListElement[Key, Value]
Next returns the item on the right.
func (*ListElement[Key, Value]) Value ¶
func (e *ListElement[Key, Value]) Value() Value
Value returns the value of the list item.
type Map ¶ added in v1.0.7
type Map[Key hashable, Value any] struct { // contains filtered or unexported fields }
Map implements a read optimized hash map.
func NewSized ¶ added in v1.0.2
NewSized returns a new map instance with a specific initialization size.
func (*Map[Key, Value]) Del ¶ added in v1.0.7
Del deletes the key from the map and returns whether the key was deleted.
func (*Map[Key, Value]) FillRate ¶ added in v1.0.7
FillRate returns the fill rate of the map as a percentage integer.
func (*Map[Key, Value]) Get ¶ added in v1.0.7
Get retrieves an element from the map under given hash key.
func (*Map[Key, Value]) GetOrInsert ¶ added in v1.0.7
GetOrInsert returns the existing value for the key if present. Otherwise, it stores and returns the given value. The returned bool is true if the value was loaded, false if stored.
func (*Map[Key, Value]) Grow ¶ added in v1.0.7
Grow resizes the map to a new size, the size gets rounded up to next power of 2. To double the size of the map use newSize 0. This function returns immediately, the resize operation is done in a goroutine. No resizing is done in case of another resize operation already being in progress.
func (*Map[Key, Value]) Insert ¶ added in v1.0.7
Insert sets the value under the specified key to the map if it does not exist yet. If a resizing operation is happening concurrently while calling Insert, the item might show up in the map after the resize operation is finished. Returns true if the item was inserted or false if it existed.
func (*Map[Key, Value]) Range ¶ added in v1.0.7
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (*Map[Key, Value]) Set ¶ added in v1.0.7
func (m *Map[Key, Value]) Set(key Key, value Value)
Set sets the value under the specified key to the map. An existing item for this key will be overwritten. If a resizing operation is happening concurrently while calling Set, the item might show up in the map after the resize operation is finished.