-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.go
67 lines (55 loc) · 1.12 KB
/
dictionary.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/cheekybits/genny/generic"
)
type Key generic.Type
type Value generic.Type
type ValueDictionary struct {
data map[Key][5]Value
}
func NewValueDictionary() *ValueDictionary {
return &ValueDictionary{
data: map[Key][5]Value{},
}
}
func (s *ValueDictionary) Set(key Key, value [5]Value) {
if s.data == nil {
s.data = map[Key][5]Value{}
}
s.data[key] = value
}
func (s *ValueDictionary) Delete(key Key) bool {
_, ok := s.data[key]
if ok {
delete(s.data, key)
}
return ok
}
func (s *ValueDictionary) Has(key Key) bool {
_, result := s.data[key]
return result
}
func (s *ValueDictionary) Get(key Key) [5]Value {
result, _ := s.data[key]
return result
}
func (s *ValueDictionary) Clear() {
s.data = map[Key][5]Value{}
}
func (s *ValueDictionary) Size() int {
return len(s.data)
}
func (s *ValueDictionary) Keys() []Key {
keys := make([]Key, len(s.data))
for k := range s.data {
keys = append(keys, k)
}
return keys
}
func (s *ValueDictionary) Values() [][5]Value {
values := make([][5]Value, len(s.data))
for _, v := range s.data {
values = append(values, v)
}
return values
}