-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.go
30 lines (27 loc) · 1.09 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package structures
import "errors"
var (
MapKeyNotFound = errors.New("key was not found")
MapDuplicateKey = errors.New("key already exists")
)
// Concurrent map implementation
type Map[K comparable, V any] interface {
// Add stores a new value by the given key or will error if the key already exists
Add(key K, val V) error
// Contains returns a whether the given key is contained in the hashmap or not.
Contains(key K) bool
// Delete deletes a value by key, if key does not exist an error will be returned.
Delete(key K) error
// Get returns the value by key, if key does not exist an error will be returned.
Get(key K) (V, error)
// GetOrDefault returns the value by key, if key does not exist def will be returned.
GetOrDefault(key K, def V) V
// GetOrDefault returns the value by key, if key does not exist def will be returned and stored.
GetOrSet(key K, def V) V
// Set stores val as a new value by key
Set(key K, val V) error
// ShadowCopy returns a new map with the current map as its shadow
ShadowCopy() Map[K, V]
// ToMap converts the map instance to a native map
ToMap() map[K]V
}