#frequency #array #algorithm #element

elements-frequency

Finds the frequency of elements in a list

3 unstable releases

0.5.1 Nov 13, 2021
0.5.0 Nov 11, 2021
0.4.0 Nov 11, 2021
0.3.0 Oct 16, 2021
0.1.5 Jul 31, 2021

#2320 in Algorithms

27 downloads per month

MIT license

5KB

What this does

Finds frequency of the unique elements present in a list (Array or Vector).

It returns a hashmap, with each unique item and its frequency as key:value pair.

Features:

  1. Parallel frequency counting. List items are equally distributed in each logical threads.
  2. Fast hashing algorithm (XxHash).
  3. Expressive and clean code.

Efficiency

Time Complexity: O(N) Space Complexity: O(N)

Version Note: Remove unnecessary dependency from toml.

User Guide

This crate exports a function frequency_finder. It takes a slice as parameter, that means you can pass a slice to an Array or Vector. It will return a hashmap that will contain each unique item and its frequency as key value pair.

The items can be anything that implements Copy! Such as, i32 or &str or others.

Quick Start

use elements_frequency::interface::frequency_finder;

fn main () {
    let myList = ["hi", "who", "me", "me", "hi"];

    let frequency_map = frequency_finder(&myList);

    println!("{:?}", frequency_map);

    // Output:

    // { "hi": 2, "me": 2, "who": 1 }
}

Dependencies

~775KB
~13K SLoC