Giter Site home page Giter Site logo

character_frequency's Introduction

Character Frequency

A Rust library for counting character frequencies over multiple threads

Functions

  • 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 counting
  • character_frequencies_with_n_threads_w_case(text: &str,case:CaseSense) -> HashMap<char, usize> Same as character_frequencies_with_n_threads() but with Case Sensitive counting

Enums

  • CaseSense::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.

Example

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

character_frequency's People

Contributors

donbright avatar tikitikitikidesuka avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

donbright

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.