added function to initial list of Pairs from a map[string]float64. Removed unnecessary import.

This commit is contained in:
Pradyumna Kaushik 2017-02-22 20:07:48 -05:00
parent de4e4c0141
commit 64de61ac4e

View file

@ -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]