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

use ahash in ngram #48

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


### Changed
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the extra blank line.

## [Unreleased]

-### Changed
+### Changed

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Changed
## [Unreleased]
### Changed

- Use AHash in ngram module

Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

Surround the list with blank lines.

-### Changed
+### Changed

- Use AHash in ngram module
+ - Use AHash in ngram module

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Changed
- Use AHash in ngram module
### Changed
- Use AHash in ngram module

## [0.1.2] - 2024-04-29


Expand Down
6 changes: 3 additions & 3 deletions src/ngram.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use ahash::AHashMap;
use counter::Counter;
use std::collections::HashMap;

/// Here the tokens' type is `&[String]` rather than `&Vec<String>`
/// to fix `clippy::not_unsafe_ptr_arg_deref` error.
pub fn get_token_ngram_counter(tokens: &[String], max_order: usize) -> HashMap<&[String], usize> {
let mut count_map: HashMap<&[String], usize> = HashMap::new();
pub fn get_token_ngram_counter(tokens: &[String], max_order: usize) -> AHashMap<&[String], usize> {
let mut count_map: AHashMap<&[String], usize> = AHashMap::new();
for order in 1..=max_order {
for start_index in 0..(tokens.len().saturating_sub(order - 1)) {
let ngram = &tokens[start_index..(start_index + order)];
Expand Down
Loading