-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.go
More file actions
57 lines (46 loc) · 814 Bytes
/
node.go
File metadata and controls
57 lines (46 loc) · 814 Bytes
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
package godot
import (
"fmt"
"sort"
"strings"
)
// Node Node
type Node struct {
Name string
Attr NodeAttr
}
// Nodes Nodes
type Nodes struct {
Nodes []*Node
}
// Len Len
func (n *Nodes) Len() int {
return len(n.Nodes)
}
// Swap Swap
func (n *Nodes) Swap(i, j int) {
n.Nodes[i], n.Nodes[j] = n.Nodes[j], n.Nodes[i]
}
// Less Less
func (n *Nodes) Less(i, j int) bool {
return n.Nodes[i].Name < n.Nodes[j].Name
}
// Sort Sort
func (n *Nodes) Sort() []*Node {
sort.Sort(n)
return n.Nodes
}
// NodeAttr NodeAttr
type NodeAttr map[string]string
// String String
func (attr NodeAttr) String() string {
list := []string{}
for k, v := range attr {
list = append(list, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(list, ",")
}
// Len Len
func (attr NodeAttr) Len() int {
return len(attr)
}