Skip to content
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

Merged
merged 11 commits into from
Nov 20, 2024
Merged

🐛 添加base70转bitmap字符校验 #213

merged 11 commits into from
Nov 20, 2024

Conversation

phidiaLam
Copy link
Member

No description provided.

@phidiaLam phidiaLam requested a review from Goodjooy November 7, 2024 17:12
@phidiaLam phidiaLam requested a review from Goodjooy November 8, 2024 14:49
Copy link
Contributor

@Goodjooy Goodjooy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

话说这边有单元测试吗?怎么确保修改后还是正确的?

Comment on lines 8 to 23
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);
Copy link
Contributor

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_indexiter_mut, 然后和index_to_charzip

Comment on lines 8 to 23
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);
Copy link
Contributor

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_indexiter_mut, 然后和index_to_charzip

@phidiaLam phidiaLam merged commit e6c00f6 into master Nov 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants