From 64de61ac4e7397a867633235b3a5c811efb68a8f Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Wed, 22 Feb 2017 20:07:48 -0500 Subject: [PATCH] added function to initial list of Pairs from a map[string]float64. Removed unnecessary import. --- utilities/utils.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utilities/utils.go b/utilities/utils.go index 1d0dfd1..a8ca307 100644 --- a/utilities/utils.go +++ b/utilities/utils.go @@ -1,9 +1,5 @@ package utilities -import ( - "errors" -) - /* The Pair and PairList have been taken from google groups forum, https://groups.google.com/forum/#!topic/golang-nuts/FT7cjmcL7gw @@ -18,6 +14,15 @@ type Pair struct { // A slice of pairs that implements the sort.Interface to sort by value. type PairList []Pair +// Convert map[string]float64 to PairList +func GetPairList(m map[string]float64) PairList { + pl := PairList{} + for k, v := range m { + pl = append(pl, Pair{Key: k, Value: v}) + } + return pl +} + // Swap pairs in the PairList func (plist PairList) Swap(i, j int) { plist[i], plist[j] = plist[j], plist[i]