fix(table): move table of syndromes into global static variable

This commit is contained in:
doryan 2024-08-10 00:36:27 +04:00
parent 94f050f8ca
commit 6682a66958

View File

@ -5,6 +5,17 @@ use crate::{
model::models::*,
};
static SYNDROMES: LazyLock<HashMap<usize, (bool, bool, bool)>> = LazyLock::new(|| {
HashMap::from([
(1, (false, true, true)),
(2, (false, false, true)),
(3, (true, false, true)),
(4, (false, true, false)),
(5, (true, true, false)),
(6, (true, false, false)),
(7, (false, false, false)),
])
});
pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String> {
let length_of_code: usize = mode.clone() as usize;
@ -51,15 +62,6 @@ pub fn hamming_encrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_of_code: usize) {
let mut general_length: usize = length_of_code;
let syndromes: HashMap<usize, (bool, bool, bool)> = HashMap::from([
(1, (false, true, true)),
(2, (false, false, true)),
(3, (true, false, true)),
(4, (false, true, false)),
(5, (true, true, false)),
(6, (true, false, false)),
(7, (false, false, false)),
]);
let mut errors: String = String::new();