Documentation ¶
Overview ¶
Package hashmap concurrent hash map
Example (Custom_map) ¶
m := NewMap[User, UserContext]() user := User{ ID: 1, Name: "alice", } userContext := make(map[string]any) userContext["sessionID"] = rand.Int() m.Put(user, userContext) if val, ok := m.Get(User{ID: 1}); ok { _ = val["sessionID"] // ... }
Output:
Example (String_map) ¶
m := NewStringMap[int]() m.Put("nine", 9) if val, ok := m.Get("nine"); ok { _ = val + 11 // ... } _ = m.GetOrDefault("twenty-three", 23) if ok := m.Contains("nine"); ok { // ... }
Output:
Index ¶
- type ConcurrentHashMap
- func New[K, V any](hf HashFunc[K], ef EqualsFunc[K]) ConcurrentHashMap[K, V]
- func NewComparableMap[K comparable, V any]() ConcurrentHashMap[K, V]
- func NewComparableMapWithCap[K comparable, V any](capacity int) (ConcurrentHashMap[K, V], error)
- func NewIntMap[V any]() ConcurrentHashMap[int, V]
- func NewIntMapWithCap[V any](capacity int) (ConcurrentHashMap[int, V], error)
- func NewMap[K Hasher, V any]() ConcurrentHashMap[K, V]
- func NewMapWithCap[K Hasher, V any](capacity int) (ConcurrentHashMap[K, V], error)
- func NewStringMap[V any]() ConcurrentHashMap[string, V]
- func NewStringMapWithCap[V any](capacity int) (ConcurrentHashMap[string, V], error)
- func NewWithCap[K, V any](capacity int, hf HashFunc[K], ef EqualsFunc[K]) (ConcurrentHashMap[K, V], error)
- func (m *ConcurrentHashMap[K, V]) Contains(key K) bool
- func (m *ConcurrentHashMap[K, V]) Get(key K) (V, bool)
- func (m *ConcurrentHashMap[K, V]) GetOrDefault(key K, defVal V) V
- func (m *ConcurrentHashMap[K, V]) Put(key K, val V)
- func (m *ConcurrentHashMap[K, V]) Remove(key K) (V, bool)
- func (m *ConcurrentHashMap[K, V]) Size() int
- type ConcurrentHashSet
- func NewComparableSet[T comparable]() ConcurrentHashSet[T]
- func NewComparableSetWithCap[T comparable](capacity int) (ConcurrentHashSet[T], error)
- func NewHasherSet[T Hasher]() ConcurrentHashSet[T]
- func NewHasherSetWithCap[T Hasher](capacity int) (ConcurrentHashSet[T], error)
- func NewSet[T any](hf HashFunc[T], ef EqualsFunc[T]) ConcurrentHashSet[T]
- func NewSetWithCap[T any](capacity int, hf HashFunc[T], ef EqualsFunc[T]) (ConcurrentHashSet[T], error)
- type EqualsFunc
- type HashFunc
- type Hasher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentHashMap ¶
type ConcurrentHashMap[K, V any] struct { // contains filtered or unexported fields }
func New ¶
func New[K, V any](hf HashFunc[K], ef EqualsFunc[K]) ConcurrentHashMap[K, V]
func NewComparableMap ¶
func NewComparableMap[K comparable, V any]() ConcurrentHashMap[K, V]
func NewComparableMapWithCap ¶
func NewComparableMapWithCap[K comparable, V any](capacity int) (ConcurrentHashMap[K, V], error)
func NewIntMap ¶
func NewIntMap[V any]() ConcurrentHashMap[int, V]
func NewIntMapWithCap ¶
func NewIntMapWithCap[V any](capacity int) (ConcurrentHashMap[int, V], error)
func NewMap ¶
func NewMap[K Hasher, V any]() ConcurrentHashMap[K, V]
func NewMapWithCap ¶
func NewMapWithCap[K Hasher, V any](capacity int) (ConcurrentHashMap[K, V], error)
func NewStringMap ¶
func NewStringMap[V any]() ConcurrentHashMap[string, V]
func NewStringMapWithCap ¶
func NewStringMapWithCap[V any](capacity int) (ConcurrentHashMap[string, V], error)
func NewWithCap ¶
func NewWithCap[K, V any](capacity int, hf HashFunc[K], ef EqualsFunc[K]) (ConcurrentHashMap[K, V], error)
func (*ConcurrentHashMap[K, V]) Contains ¶
func (m *ConcurrentHashMap[K, V]) Contains(key K) bool
Contains returns if there is an entry mapped by the given key.
func (*ConcurrentHashMap[K, V]) Get ¶
func (m *ConcurrentHashMap[K, V]) Get(key K) (V, bool)
Get returns value of the entry mapped by given key. If there is mopping by given key, it returns false.
func (*ConcurrentHashMap[K, V]) GetOrDefault ¶
func (m *ConcurrentHashMap[K, V]) GetOrDefault(key K, defVal V) V
GetOrDefault returns the value of the entry mapped by the given key. If there is mopping by the given key, it returns default value argument.
func (*ConcurrentHashMap[K, V]) Put ¶
func (m *ConcurrentHashMap[K, V]) Put(key K, val V)
Put maps the given key to the value, and saves the entry. In case of there is already an entry mapped by the given key, it updates the value of the entry.
func (*ConcurrentHashMap[K, V]) Remove ¶
func (m *ConcurrentHashMap[K, V]) Remove(key K) (V, bool)
Remove removes the entry mapped by the given key and returns value of removed entry and true. In case of there is entry by the given key, It returns nil and false.
func (*ConcurrentHashMap[K, V]) Size ¶
func (m *ConcurrentHashMap[K, V]) Size() int
Size returns the count of entries in the map
type ConcurrentHashSet ¶
type ConcurrentHashSet[T any] struct { // contains filtered or unexported fields }
func NewComparableSet ¶
func NewComparableSet[T comparable]() ConcurrentHashSet[T]
func NewComparableSetWithCap ¶
func NewComparableSetWithCap[T comparable](capacity int) (ConcurrentHashSet[T], error)
func NewHasherSet ¶
func NewHasherSet[T Hasher]() ConcurrentHashSet[T]
func NewHasherSetWithCap ¶
func NewHasherSetWithCap[T Hasher](capacity int) (ConcurrentHashSet[T], error)
func NewSet ¶
func NewSet[T any](hf HashFunc[T], ef EqualsFunc[T]) ConcurrentHashSet[T]
func NewSetWithCap ¶
func NewSetWithCap[T any](capacity int, hf HashFunc[T], ef EqualsFunc[T]) (ConcurrentHashSet[T], error)
func (*ConcurrentHashSet[T]) Contains ¶
func (s *ConcurrentHashSet[T]) Contains(t T) bool
func (*ConcurrentHashSet[T]) Put ¶
func (s *ConcurrentHashSet[T]) Put(t T)
func (*ConcurrentHashSet[T]) Remove ¶
func (s *ConcurrentHashSet[T]) Remove(t T) bool