Methods to get max and min keys
I would like to get the key with the maximum and minimum number of duplicates. To do that with the current API, I have to convert it to a vec and use max_by. It would be great if HashBag had this functionality build in.
Does this not work? Any internal implementation of min/max would likely work roughly the same.
bag
.set_iter()
.fold((usize::MAX, usize::MIN), |(min, max), val| (std::cmp::min(min, val), std::cmp::max(max, val)))
Yeah this is what I want, but as an internal method.
Edit: The example you gave does not compile.
Sorry, I wrote that example on my phone. The correct example would be this:
bag
.set_iter()
.fold((usize::MAX, usize::MIN), |(min, max), (_, val)| (std::cmp::min(min, val), std::cmp::max(max, val)))
That said, my point was that you don't need to copy everything into a Vec if you only want the min and/or max. If the above example is along the lines of what you are looking for, consider opening a PR.