shannon-entropy

Crates.ioshannon-entropy
lib.rsshannon-entropy
version1.0.0
sourcesrc
created_at2016-03-08 23:41:17.099436
updated_at2020-03-05 17:54:22.975969
descriptionA simple library to calculate the Shannon entropy of a string
homepage
repositoryhttps://github.com/insanitybit/shannon-entropy
max_upload_size
id4405
size19,866
Colin (insanitybit)

documentation

README

Build Status Coverage Status

shannon-entropy

A rust library to calculate the Shannon entropy of a string.

Usage

Available on crates.io

Add this to your Cargo.toml

[dependencies]
shannon-entropy = "0.2"

Example

fn main() {
  let test_strings = vec![
                          ("hello world", 2.8453512),
                          ("hello worldd", 2.8553884),
                          ("a", 0.0),
                          ("", 0.0),
                          ];

  for (test, answer) in test_strings {
      let entropy: f32 = shannon_entropy(test);
      assert_eq!(entropy, answer);
  }  
}
Commit count: 18

cargo fmt