summaryrefslogtreecommitdiff
path: root/search/gomap.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-02 20:22:13 +0300
committerPaul Buetow <paul@buetow.org>2023-04-02 20:22:13 +0300
commit0c6d4ed2e499e3e17165e43803d0d1c6dd0956d9 (patch)
tree6d6a5df53d1dd3e655d24f0423f24bc52ad9784c /search/gomap.go
parentf78ba2cdc6840dbc52a27a2f9fac28f3b61e8b7b (diff)
initial generics
Diffstat (limited to 'search/gomap.go')
-rw-r--r--search/gomap.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/search/gomap.go b/search/gomap.go
index 6749b0d..c8912d9 100644
--- a/search/gomap.go
+++ b/search/gomap.go
@@ -1,35 +1,39 @@
package search
-type GoMap map[int]int
+import (
+ "codeberg.org/snonux/algorithms/ds"
+)
-func NewGoMap() GoMap {
- return make(GoMap)
+type GoMap[K,V ds.Number] map[K]V
+
+func NewGoMap[K,V ds.Number] () GoMap[K,V] {
+ return make(GoMap[K,V])
}
-func (m GoMap) Empty() bool {
+func (m GoMap[K,V]) Empty() bool {
return m.Size() == 0
}
-func (m GoMap) Size() int {
+func (m GoMap[K,V]) Size() int {
return len(m)
}
-func (m GoMap) Put(key, val int) {
+func (m GoMap[K,V]) Put(key K, val V) {
m[key] = val
}
-func (m GoMap) Get(key int) (int, error) {
+func (m GoMap[K,V]) Get(key K) (V, error) {
val, ok := m[key]
if !ok {
- return -1, NotFound
+ return 0, NotFound
}
return val, nil
}
-func (m GoMap) Del(key int) (int, error) {
+func (m GoMap[K,V]) Del(key K) (V, error) {
val, ok := m[key]
if !ok {
- return -1, NotFound
+ return 0, NotFound
}
delete(m, key)
return val, nil