diff --git a/def/task.go b/def/task.go index 62ab993..ce59cd4 100644 --- a/def/task.go +++ b/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).