Method to sort keys in map.

This commit is contained in:
Andrey Smirnov
2014-01-21 13:36:09 +04:00
parent e183ddb981
commit e21506d373
2 changed files with 18 additions and 0 deletions
+13
View File
@@ -2,6 +2,7 @@ package utils
import (
"fmt"
"sort"
)
// StringsIsSubset checks that subset is strict subset of full, and returns
@@ -62,3 +63,15 @@ func StrSliceHasItem(s []string, item string) bool {
}
return false
}
// StrMapSortedKeys returns keys of map[string]string sorted
func StrMapSortedKeys(m map[string]string) []string {
keys := make(sort.StringSlice, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
sort.Strings(keys)
return keys
}