PWGen/pwgenerator/funcs.go

34 lines
596 B
Go
Raw Normal View History

2022-03-02 06:24:55 -05:00
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
}