Crates.io | elements-frequency |
lib.rs | elements-frequency |
version | 0.5.1 |
source | src |
created_at | 2021-07-28 03:15:57.393209 |
updated_at | 2021-11-13 20:41:10.578132 |
description | Finds the frequency of elements in a list. |
homepage | |
repository | https://codeberg.org/ino/rusty-algos/src/branch/master/problems/elements-frequency |
max_upload_size | |
id | 428157 |
size | 6,990 |
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.
Time Complexity: O(N)
Space Complexity: O(N)
Version Note: Remove unnecessary dependency from toml.
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.
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 }
}