Skip to content

Commit 206c625

Browse files
committed
make sure charset does not contain duplicates
1 parent 2432006 commit 206c625

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

aces.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func NewCoding(charset []rune) (*Coding, error) {
125125
"\n want: a power of 2 (nearest is", 1<<numOfBits, "which is", math.Abs(float64(len(charset)-1<<numOfBits)), "away)"),
126126
)
127127
}
128+
seen := make(map[rune]bool)
129+
for _, r := range charset {
130+
if seen[r] {
131+
return nil, errors.New("charset contains duplicates")
132+
}
133+
seen[r] = true
134+
}
128135
return &Coding{charset: charset, numOfBits: numOfBits}, nil
129136
}
130137

0 commit comments

Comments
 (0)