34 lines
596 B
Go
34 lines
596 B
Go
package pwgenerator
|
|
|
|
import (
|
|
"sort"
|
|
)
|
|
|
|
// sortDedupe sorts a slice of runes and deduplicates them.
|
|
func sortDedupe(charset *CharSet) {
|
|
|
|
var vals map[Char]bool = make(map[Char]bool)
|
|
var sorted CharSet
|
|
var idx int
|
|
|
|
// This inherently dedupes.
|
|
for _, i := range *charset {
|
|
vals[i] = true
|
|
}
|
|
|
|
// This handles sorting.
|
|
sorted = make(CharSet, len(vals))
|
|
// First we need a slice (again).
|
|
for k := range vals {
|
|
sorted[idx] = k
|
|
idx++
|
|
}
|
|
// And now we can sort...
|
|
sort.Sort(&sorted)
|
|
|
|
// And replace the original charset with the sorted, deduplicated one.
|
|
*charset = sorted
|
|
|
|
return
|
|
}
|