Skip to content

Commit 5b82272

Browse files
Add some sanity checking on table input
1 parent 745e808 commit 5b82272

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

examples/make_tables.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{HashMap, HashSet};
22
use std::iter::Iterator;
33

44
fn main() {
@@ -70,6 +70,7 @@ fn main() {
7070
}
7171

7272
fn print_encode_table(alphabet: &[u8], const_name: &str, indent_depth: usize) {
73+
check_alphabet(alphabet);
7374
println!("#[rustfmt::skip]");
7475
println!(
7576
"{:width$}pub const {}: &[u8; 64] = &[",
@@ -95,6 +96,7 @@ fn print_encode_table(alphabet: &[u8], const_name: &str, indent_depth: usize) {
9596
}
9697

9798
fn print_decode_table(alphabet: &[u8], const_name: &str, indent_depth: usize) {
99+
check_alphabet(alphabet);
98100
// map of alphabet bytes to 6-bit morsels
99101
let mut input_to_morsel = HashMap::<u8, u8>::new();
100102

@@ -140,3 +142,10 @@ fn print_decode_table(alphabet: &[u8], const_name: &str, indent_depth: usize) {
140142
}
141143
println!("{:width$}];", "", width = indent_depth);
142144
}
145+
146+
fn check_alphabet(alphabet: &[u8]) {
147+
assert_eq!(64, alphabet.len());
148+
let mut set: HashSet<u8> = HashSet::new();
149+
set.extend(alphabet);
150+
assert_eq!(64, set.len());
151+
}

0 commit comments

Comments
 (0)