| Crates.io | character_frequency |
| lib.rs | character_frequency |
| version | 0.2.0 |
| created_at | 2022-05-21 22:43:24.345716+00 |
| updated_at | 2023-02-18 13:15:41.452734+00 |
| description | Simple library for counting character frequencies in a string concurrently |
| homepage | |
| repository | https://github.com/Tikitikitikidesuka/character_frequency |
| max_upload_size | |
| id | 590915 |
| size | 41,403 |
A Rust library for counting character frequencies over multiple threads
character_frequencies(text: &str) -> HashMap<char, usize>
Returns a map with the frequencies counted on the text parameter.
It will run on as many threads as cpu's are available.character_frequencies_with_n_threads(text: &str, threads: usize) -> HashMap<char, usize>:
Returns a map with the frequencies counted on the text parameter.
It will run on the specified ammount of threads.character_frequencies_w_case(text: &str,case:CaseSense) -> HashMap<char, usize>
Same as character_frequencies() but with Case Sensitive countingcharacter_frequencies_with_n_threads_w_case(text: &str,case:CaseSense) -> HashMap<char, usize>
Same as character_frequencies_with_n_threads() but with Case Sensitive countingCaseSense::InsensitiveASCIIOnly - Converts ASCII characters to lowercase before counting. This is the default.CaseSense::Insensitive - Converts all UTF8 characters to lowercase before counting. If the Unicode
character's lowercase version is a string, not a character, it panics.CaseSense::Sensitive - Doesn't convert any characters to lowercase before counting.This example counts the character frequencies of Hello, World! and print them afterwards:
use character_frequency::*;
let frequency_map = character_frequencies("Hello, World!");
println!("Character frequencies:");
for (character, frequency) in frequency_map {
print!("\'{}\': {},", character, frequency);
}
//Character frequencies:
//'r': 1 'd': 1 'o': 2 '!': 1 ',': 1 ' ': 1 'e': 1 'h': 1 'w': 1 'l': 3
This does the same but with case sensitivity.
let frequency_map = character_frequencies_w_case("Hello WORLD",CaseSense::Sensitive);
println!("Character frequencies:");
for (character, frequency) in frequency_map {
print!("\'{}\': {},", character, frequency);
}
//Character frequencies:
//'R': 1 'D': 1 'O': 1 'o': 1 ' ': 1 'e': 1 'H': 1 'W': 1 'l': 2 'L': 1