Skip to content

Commit

Permalink
make sure charset does not contain duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Nov 24, 2022
1 parent 2432006 commit 206c625
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aces.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func NewCoding(charset []rune) (*Coding, error) {
"\n want: a power of 2 (nearest is", 1<<numOfBits, "which is", math.Abs(float64(len(charset)-1<<numOfBits)), "away)"),
)
}
seen := make(map[rune]bool)
for _, r := range charset {
if seen[r] {
return nil, errors.New("charset contains duplicates")
}
seen[r] = true
}
return &Coding{charset: charset, numOfBits: numOfBits}, nil
}

Expand Down

0 comments on commit 206c625

Please sign in to comment.