16 lines
348 B
Go
16 lines
348 B
Go
package markov
|
|
|
|
import "sort"
|
|
|
|
// sortedKeys returns the map's keys in a stable order, so that sampling
|
|
// depends only on the supplied rng and not on Go's randomised map
|
|
// iteration.
|
|
func sortedKeys(m map[string]int) []string {
|
|
keys := make([]string, 0, len(m))
|
|
for k := range m {
|
|
keys = append(keys, k)
|
|
}
|
|
sort.Strings(keys)
|
|
return keys
|
|
}
|