1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Grouping Elements (Generic, Hashable, Keyed)
//!
//! Groups elements of a slice by a key function, returning a map from key to vector of elements.
//!
//! # Type Parameters
//! * `T`: The element type. Must implement `Clone`.
//! * `K`: The key type. Must implement `Eq` + `Hash`.
//!
//! # Arguments
//! * `slice` - The slice to group.
//! * `key_fn` - Function to extract the key from each element.
//!
//! # Returns
//! * `HashMap<K, Vec<T>>` - A map from key to vectors of elements.
//!
//! # Example
//! ```rust
//! use pofk_algorithm::set_algorithms::grouping_elements::grouping_elements;
//! let arr = ["apple", "apricot", "banana", "blueberry"];
//! let groups = grouping_elements(&arr, |s| s.chars().next().unwrap());
//! assert_eq!(groups[&'a'], vec!["apple", "apricot"]);
//! assert_eq!(groups[&'b'], vec!["banana", "blueberry"]);
//! ```
use HashMap;