added CPUSorter to task to be able to sort tasks based on CPU requirement.

This commit is contained in:
Pradyumna Kaushik 2017-02-05 14:49:07 -05:00
parent 395917a97e
commit b838c53c6d

View file

@ -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).