added CPUSorter to task to be able to sort tasks based on CPU requirement.
This commit is contained in:
parent
395917a97e
commit
b838c53c6d
1 changed files with 16 additions and 0 deletions
16
def/task.go
16
def/task.go
|
@ -65,6 +65,7 @@ func (tsk *Task) SetTaskID(taskID string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// Sorter implements sort.Sort interface to sort tasks by Watts requirement.
|
||||
type WattsSorter []Task
|
||||
|
||||
func (slice WattsSorter) Len() int {
|
||||
|
@ -79,6 +80,21 @@ func (slice WattsSorter) Swap(i, j int) {
|
|||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
// Sorter implements sort.Sort interface to sort tasks by CPU requirement.
|
||||
type CPUSorter []Task
|
||||
|
||||
func (slice CPUSorter) Len() int {
|
||||
return len(slice)
|
||||
}
|
||||
|
||||
func (slice CPUSorter) Less(i, j int) bool {
|
||||
return slice[i].CPU < slice[j].CPU
|
||||
}
|
||||
|
||||
func (slice CPUSorter) Swap(i, j int) {
|
||||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
// Compare two tasks.
|
||||
func Compare(task1 *Task, task2 *Task) bool {
|
||||
// If comparing the same pointers (checking the addresses).
|
||||
|
|
Reference in a new issue