Documentation ¶
Overview ¶
Package chmap concurrent hash map
Example (Custom_map) ¶
m := New[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 := NewString[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 Hasher, v any]() ConcurrentHashMap[k, v]
- func NewString[v any]() ConcurrentHashMap[string, v]
- func NewStringWithCap[v any](capacity int) (chm ConcurrentHashMap[string, v], err error)
- func NewWithCap[k Hasher, v any](capacity int) (chm ConcurrentHashMap[k, v], err error)
- func NewWithCapAndFuncs[k, v any](capacity int, hf HashFunc[k], ef EqualsFunc[k]) (chm ConcurrentHashMap[k, v], err error)
- func NewWithFuncs[k, v any](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 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 }
ConcurrentHashMap thread-safe string:any map
func New ¶
func New[k Hasher, v any]() ConcurrentHashMap[k, v]
New returns ConcurrentHashMap with default capacity.
func NewString ¶
func NewString[v any]() ConcurrentHashMap[string, v]
NewString returns string type key ConcurrentHashMap with default capacity.
func NewStringWithCap ¶
func NewStringWithCap[v any](capacity int) (chm ConcurrentHashMap[string, v], err error)
NewStringWithCap returns string type key ConcurrentHashMap with given capacity.
func NewWithCap ¶
func NewWithCap[k Hasher, v any](capacity int) (chm ConcurrentHashMap[k, v], err error)
NewWithCap returns ConcurrentHashMap with given capacity.
func NewWithCapAndFuncs ¶
func NewWithCapAndFuncs[k, v any](capacity int, hf HashFunc[k], ef EqualsFunc[k]) (chm ConcurrentHashMap[k, v], err error)
NewWithCapAndFuncs returns ConcurrentHashMap with the given capacity and funcs.
func NewWithFuncs ¶
func NewWithFuncs[k, v any](hf HashFunc[k], ef EqualsFunc[k]) (ConcurrentHashMap[k, v], error)
NewWithFuncs returns ConcurrentHashMap with the given funcs and default capacity.
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