Sort reorders a slice of nodes based on the specified ordering criteria. The result is sorted in decreasing order for (absolute) numeric quantities, alphabetically for text, and increasing for addresses.
(o NodeOrder)
| 956 | // numeric quantities, alphabetically for text, and increasing for |
| 957 | // addresses. |
| 958 | func (ns Nodes) Sort(o NodeOrder) error { |
| 959 | var s nodeSorter |
| 960 | |
| 961 | switch o { |
| 962 | case FlatNameOrder: |
| 963 | s = nodeSorter{ns, |
| 964 | func(l, r *Node) bool { |
| 965 | if iv, jv := abs64(l.Flat), abs64(r.Flat); iv != jv { |
| 966 | return iv > jv |
| 967 | } |
| 968 | equal, leftLess := l.Info.comparePrintableName(r.Info) |
| 969 | if !equal { |
| 970 | return leftLess |
| 971 | } |
| 972 | if iv, jv := abs64(l.Cum), abs64(r.Cum); iv != jv { |
| 973 | return iv > jv |
| 974 | } |
| 975 | return compareNodes(l, r) |
| 976 | }, |
| 977 | } |
| 978 | case FlatCumNameOrder: |
| 979 | s = nodeSorter{ns, |
| 980 | func(l, r *Node) bool { |
| 981 | if iv, jv := abs64(l.Flat), abs64(r.Flat); iv != jv { |
| 982 | return iv > jv |
| 983 | } |
| 984 | if iv, jv := abs64(l.Cum), abs64(r.Cum); iv != jv { |
| 985 | return iv > jv |
| 986 | } |
| 987 | equal, leftLess := l.Info.comparePrintableName(r.Info) |
| 988 | if !equal { |
| 989 | return leftLess |
| 990 | } |
| 991 | return compareNodes(l, r) |
| 992 | }, |
| 993 | } |
| 994 | case NameOrder: |
| 995 | s = nodeSorter{ns, |
| 996 | func(l, r *Node) bool { |
| 997 | if iv, jv := l.Info.Name, r.Info.Name; iv != jv { |
| 998 | return iv < jv |
| 999 | } |
| 1000 | return compareNodes(l, r) |
| 1001 | }, |
| 1002 | } |
| 1003 | case FileOrder: |
| 1004 | s = nodeSorter{ns, |
| 1005 | func(l, r *Node) bool { |
| 1006 | if iv, jv := l.Info.File, r.Info.File; iv != jv { |
| 1007 | return iv < jv |
| 1008 | } |
| 1009 | if iv, jv := l.Info.StartLine, r.Info.StartLine; iv != jv { |
| 1010 | return iv < jv |
| 1011 | } |
| 1012 | return compareNodes(l, r) |
| 1013 | }, |
| 1014 | } |
| 1015 | case AddressOrder: |
no test coverage detected