From 9e620eaede16c12e3216cd84c6434202fe80e839 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Sat, 26 Aug 2017 15:39:45 -0400 Subject: [PATCH] changed def.TaskSorter(...) to def.SortTasks(...) for semantics. Now, def.SortTasks(...) also sorts the tasks instead of returning just a func (i, j int) bool {}. Removed TODO from the README associated with this PR --- README.md | 1 - def/taskUtils.go | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c59816d..2e0ee06 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ To Do: * Have a centralised logFile that can be filtered by identifier. All electron logs should go into this file. * Make def.Task an interface for further modularization and flexibility. * Convert def#WattsToConsider(...) to be a receiver of def.Task and change the name of it to Watts(...). - * Have a generic sorter for task resources instead of having one for each kind of resource. * **Critical** -- Add software requirements to the README.md (Mesos version, RAPL version, PCP version, Go version...) * **Critical** -- Retrofit to use Go 1.8 sorting techniques. Use def/taskUtils.go for reference. * Handle powerclass not configured on a node condition. As of now, an assumption is made that the powerclass is configured diff --git a/def/taskUtils.go b/def/taskUtils.go index 2a318dc..d36875d 100644 --- a/def/taskUtils.go +++ b/def/taskUtils.go @@ -119,9 +119,8 @@ func labelAndOrder(clusters map[int][]Task, numberOfClusters int, taskObservatio // Be able to sort an array of tasks based on any of the tasks' resources. // Retrieve a sorter (same signature as 'Less' function in sort.Interface) for the given sorting criteria. -type TasksToSort []Task -func (ts TasksToSort) TaskSorter(sb sortBy) func (i, j int) bool { - return func (i, j int) bool { +func SortTasks(ts []Task, sb sortBy) { + sort.SliceStable(ts, func (i, j int) bool { return sb(&ts[i]) <= sb(&ts[j]) - } + }) }