count-invert
count-invert is a Rust crate providing utility functions for counting the occurrences of elements in a vector and inverting a HashMap based on those counts. This crate leverages the itertools crate to offer robust and efficient functionalities for common data manipulation tasks.
Features
- Convert a vector into a
HashMapwith element counts. - Invert a
HashMapto map counts to vectors of elements. - Combine both functionalities to create a
HashMapmapping counts to vectors of elements directly from a vector.
Installation
Add count-invert to your Cargo.toml:
[]
= "0.1.0"
Usage
Here's how to use the count-invert crate:
into_counts
Convert a vector into a HashMap where the keys are the elements and the values are their counts.
use into_counts;
use HashMap;
let vec = vec!;
let counts: = into_counts;
println!; // Output: {1: 1, 2: 2, 3: 3}
invert_map
Invert a HashMap such that the keys become the values and the values become the keys.
use invert_map;
use HashMap;
let mut map = new;
map.insert;
map.insert;
map.insert;
let inverted: = invert_map;
println!; // Output: {2: [1, 2], 3: [3]}
into_count_map
Convert a vector into a HashMap where the keys are the counts of elements and the values are vectors of elements with those counts.
use into_count_map;
use HashMap;
let vec = vec!;
let count_map: = into_count_map;
println!; // Output: {1: [1], 2: [2], 3: [3]}
Contributing
Contributions are welcome! Please submit pull requests or open issues to suggest improvements or report bugs.
License
This project is licensed under the MIT License. See the LICENSE file for details.