-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 添加base70转bitmap字符校验 #213
The head ref may contain hidden characters: "fix-base70\u6821\u9A8C"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
话说这边有单元测试吗?怎么确保修改后还是正确的?
libs/bitmap-convert/src/base70.rs
Outdated
const BASE_70: &str = | ||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~._()!*"; | ||
// 字符转下标 | ||
static CHAR_TO_INDEX: LazyLock<[u8; 127]> = LazyLock::new(|| { | ||
let mut char_to_index: [u8; 127] = [0; 127]; | ||
let index_to_char = BASE_70.chars().collect::<Vec<char>>(); | ||
for (i, c) in index_to_char.iter().enumerate() { | ||
char_to_index[*c as usize] = i as u8; | ||
} | ||
char_to_index | ||
}); | ||
// 下标转字符 | ||
static INDEX_TO_CHAR: LazyLock<Vec<char>> = | ||
LazyLock::new(|| BASE_70.chars().collect()); | ||
// 字符数量 | ||
static RADIX: LazyLock<u32> = LazyLock::new(|| INDEX_TO_CHAR.len() as u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为何不将
BASE_70
改成b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~._()!*"
,这样类型就是&'static [u8]
- 为何这边迭代器需要先 collect 到Vec 然后再转迭代器再加enumerate?
- 此外,使用enum来从0 开始写入,为何不能是 将
char_to_index
取iter_mut
, 然后和index_to_char
取zip
libs/bitmap-convert/src/base70.rs
Outdated
const BASE_70: &str = | ||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~._()!*"; | ||
// 字符转下标 | ||
static CHAR_TO_INDEX: LazyLock<[u8; 127]> = LazyLock::new(|| { | ||
let mut char_to_index: [u8; 127] = [0; 127]; | ||
let index_to_char = BASE_70.chars().collect::<Vec<char>>(); | ||
for (i, c) in index_to_char.iter().enumerate() { | ||
char_to_index[*c as usize] = i as u8; | ||
} | ||
char_to_index | ||
}); | ||
// 下标转字符 | ||
static INDEX_TO_CHAR: LazyLock<Vec<char>> = | ||
LazyLock::new(|| BASE_70.chars().collect()); | ||
// 字符数量 | ||
static RADIX: LazyLock<u32> = LazyLock::new(|| INDEX_TO_CHAR.len() as u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为何不将
BASE_70
改成b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~._()!*"
,这样类型就是&'static [u8]
- 为何这边迭代器需要先 collect 到Vec 然后再转迭代器再加enumerate?
- 此外,使用enum来从0 开始写入,为何不能是 将
char_to_index
取iter_mut
, 然后和index_to_char
取zip
No description provided.