summaryrefslogtreecommitdiff
path: root/search/gomap.go
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-21 20:54:55 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-21 20:54:55 +0000
commite80cca57e072cf902f3e91ebe05f1ab8fbd55af8 (patch)
tree9a9abe1f49698a8c36594afcc439af5038d2727f /search/gomap.go
parent7815c3d006b64d5a6a6664e7c2c96c9c27f29c45 (diff)
add gomap for search
Diffstat (limited to 'search/gomap.go')
-rw-r--r--search/gomap.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/search/gomap.go b/search/gomap.go
new file mode 100644
index 0000000..6749b0d
--- /dev/null
+++ b/search/gomap.go
@@ -0,0 +1,36 @@
+package search
+
+type GoMap map[int]int
+
+func NewGoMap() GoMap {
+ return make(GoMap)
+}
+
+func (m GoMap) Empty() bool {
+ return m.Size() == 0
+}
+
+func (m GoMap) Size() int {
+ return len(m)
+}
+
+func (m GoMap) Put(key, val int) {
+ m[key] = val
+}
+
+func (m GoMap) Get(key int) (int, error) {
+ val, ok := m[key]
+ if !ok {
+ return -1, NotFound
+ }
+ return val, nil
+}
+
+func (m GoMap) Del(key int) (int, error) {
+ val, ok := m[key]
+ if !ok {
+ return -1, NotFound
+ }
+ delete(m, key)
+ return val, nil
+}