-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
test
committed
Aug 26, 2018
1 parent
41498ba
commit d5ea22b
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package types | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
type ProcessNameSorter struct { | ||
processes []ProcessInfo | ||
} | ||
|
||
func NewwProcessNameSorter(processes []ProcessInfo) *ProcessNameSorter { | ||
return &ProcessNameSorter{processes: processes} | ||
} | ||
|
||
func (pns *ProcessNameSorter) Len() int { | ||
return len(pns.processes) | ||
} | ||
|
||
func (pns *ProcessNameSorter) Less(i, j int) bool { | ||
return strings.Compare(pns.processes[i].Name, pns.processes[j].Name) < 0 | ||
} | ||
|
||
func (pns *ProcessNameSorter) Swap(i, j int) { | ||
info := pns.processes[i] | ||
pns.processes[i] = pns.processes[j] | ||
pns.processes[j] = info | ||
} | ||
|
||
func SortProcessInfos(processes []ProcessInfo) { | ||
sorter := NewwProcessNameSorter(processes) | ||
sort.Sort(sorter) | ||
} |