@@ -28,20 +28,15 @@ import (
28
28
// for PathElementSet and SetNodeMap, so we could probably share the
29
29
// code.
30
30
type PathElementValueMap struct {
31
- members sortedPathElementValues
31
+ valueMap PathElementMap
32
32
}
33
33
34
34
func MakePathElementValueMap (size int ) PathElementValueMap {
35
35
return PathElementValueMap {
36
- members : make ( sortedPathElementValues , 0 , size ),
36
+ valueMap : MakePathElementMap ( size ),
37
37
}
38
38
}
39
39
40
- type pathElementValue struct {
41
- PathElement PathElement
42
- Value value.Value
43
- }
44
-
45
40
type sortedPathElementValues []pathElementValue
46
41
47
42
// Implement the sort interface; this would permit bulk creation, which would
@@ -55,6 +50,38 @@ func (spev sortedPathElementValues) Swap(i, j int) { spev[i], spev[j] = spev[j],
55
50
// Insert adds the pathelement and associated value in the map.
56
51
// If insert is called twice with the same PathElement, the value is replaced.
57
52
func (s * PathElementValueMap ) Insert (pe PathElement , v value.Value ) {
53
+ s .valueMap .Insert (pe , v )
54
+ }
55
+
56
+ // Get retrieves the value associated with the given PathElement from the map.
57
+ // (nil, false) is returned if there is no such PathElement.
58
+ func (s * PathElementValueMap ) Get (pe PathElement ) (value.Value , bool ) {
59
+ v , ok := s .valueMap .Get (pe )
60
+ if ! ok {
61
+ return nil , false
62
+ }
63
+ return v .(value.Value ), true
64
+ }
65
+
66
+ // PathElementValueMap is a map from PathElement to interface{}.
67
+ type PathElementMap struct {
68
+ members sortedPathElementValues
69
+ }
70
+
71
+ type pathElementValue struct {
72
+ PathElement PathElement
73
+ Value interface {}
74
+ }
75
+
76
+ func MakePathElementMap (size int ) PathElementMap {
77
+ return PathElementMap {
78
+ members : make (sortedPathElementValues , 0 , size ),
79
+ }
80
+ }
81
+
82
+ // Insert adds the pathelement and associated value in the map.
83
+ // If insert is called twice with the same PathElement, the value is replaced.
84
+ func (s * PathElementMap ) Insert (pe PathElement , v interface {}) {
58
85
loc := sort .Search (len (s .members ), func (i int ) bool {
59
86
return ! s .members [i ].PathElement .Less (pe )
60
87
})
@@ -73,7 +100,7 @@ func (s *PathElementValueMap) Insert(pe PathElement, v value.Value) {
73
100
74
101
// Get retrieves the value associated with the given PathElement from the map.
75
102
// (nil, false) is returned if there is no such PathElement.
76
- func (s * PathElementValueMap ) Get (pe PathElement ) (value. Value , bool ) {
103
+ func (s * PathElementMap ) Get (pe PathElement ) (interface {} , bool ) {
77
104
loc := sort .Search (len (s .members ), func (i int ) bool {
78
105
return ! s .members [i ].PathElement .Less (pe )
79
106
})
0 commit comments