There are a large number of elements saved in a HashBag
(of Eclipse Collections framework). Now all elements with less than k occurrences should be removed.
This could be done with:
bag.removeAll(bag.selectByOccurrences(n->n<k));
Downside is, this creates a temporary bag instance which in our case consumes much memory.
So I'm looking for an in-place removal approach, e.g. with an iterator. The iterator returned by iterator()
iterates n times over an element with n occurrences which isn't suitable CPU wise. Better would be iterating over all distinct keys of the underlying ObjectIntMap
. In the source code you can find a method AbstractHashBag.getKeysView()
but it's protected. Is there a way to access it via public API or any other ideas to remove such elements in-place?