This trait converts the keys of a HashMap into a HashSet. The keys must implement the Eq, Hash,
and Clone traits to be stored in a HashSet. The function will return a HashSet
containing all the unique keys from the HashMap. For example, if the HashMap contains the pairs (1, “a”), (2, “b”),
and (3, “a”),
the resulting HashSet will contain 1, 2, and 3, because those are the unique keys in the HashMap.
Example usage:
let mut map = HashMap::new();
map.insert(1, “a”);
map.insert(2, “b”);
map.insert(3, “a”);
let key_set = map.h_hashmap_keys_to_hashset();
The result will be a HashSet containing 1, 2, and 3, because those are the unique keys in the HashMap.
This trait converts the values of a HashMap into a HashSet. The values must implement the Eq, Hash,
and Clone traits to be stored in a HashSet. The function will return a HashSet containing all the unique values
from the HashMap. For example, if the HashMap contains the pairs (1, “a”), (2, “b”), and (3, “a”),
the resulting HashSet will contain “a” and “b”, because “a” is duplicated in the values of the HashMap.
Example usage:
let mut map = HashMap::new();
map.insert(1, “a”);
map.insert(2, “b”);
map.insert(3, “a”);
let value_set = map.h_hashmap_values_to_hashset();
The result will be a HashSet containing “a” and “b”, because those are the unique values in the HashMap.
this trait converts a list of values into a HashSet.
The values must implement the Eq, Hash, and Clone traits to be stored in a HashSet.
The function will return a tuple of (HashSet containing all the unique values from the list, number of duplicates removed).
For example, if the list contains [“a”, “b”, “a”, “c”],
the result will be (HashSet containing “a”, “b”, “c”, 1), because “a” was duplicated.
Example usage:
let values = vec![“a”, “b”, “a”, “c”];
let (value_set, dupes) = values.h_list_to_hashset();
value_set will contain “a”, “b”, “c”, and dupes will be 1.
This function converts a list of keys and a list of values into a HashMap.
The keys and values must implement the Eq, Hash, and Clone traits to be stored in a HashMap.
The function will return a Result containing a HashMap where each key from the list of keys is associated with the corresponding value
from the list of values, or a vector of errors if issues are found (length mismatch or duplicate keys).
For example, if the list of keys is [1, 2, 3] and the list of values is [“a”, “b”, “c”],
the resulting HashMap will contain the pairs (1, “a”), (2, “b”), and (3, “c”).
If lengths don’t match or there are duplicate keys, it returns errors.
Example usage:
let keys = vec![1, 2, 3];
let values = vec![“a”, “b”, “c”];
let map = h_list_to_hashmap(&keys, &values);
The result will be Ok(HashMap) containing the pairs (1, “a”), (2, “b”), and (3, “c”).