-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkeyspool.go
55 lines (46 loc) · 1.06 KB
/
keyspool.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
package gson
type mkeyshead struct {
head *mkeysnode
}
func (b *mkeyshead) getmkeys(size int) *mkeysnode {
if node := b.head; node != nil {
if len(node.keys) < size {
node.keys = make([]string, 0, size)
}
node.keys = node.keys[:0]
b.head = node.next
return node
}
node := &mkeysnode{keys: make([]string, 0, size), next: nil}
return node
}
func (b *mkeyshead) putmkeys(node *mkeysnode) {
node.next = b.head
b.head = node
}
type mkeysnode struct {
keys []string
next *mkeysnode
}
// sort JSON property objects based on property names.
func (m *mkeysnode) sortProps1(val map[string]interface{}) []string {
for k := range val {
m.keys = append(m.keys, k)
}
m.keys = sortStrings(m.keys)
return m.keys
}
func (m *mkeysnode) sortProps2(val map[string]uint64) []string {
for k := range val {
m.keys = append(m.keys, k)
}
m.keys = sortStrings(m.keys)
return m.keys
}
func (m *mkeysnode) sortProps3(val [][2]interface{}) []string {
for _, item := range val {
m.keys = append(m.keys, item[0].(string))
}
m.keys = sortStrings(m.keys)
return m.keys
}