You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code currently in withAll on both mutable and immutable implementations calls toArray on IntStream which if the Stream is very large can be extremely expensive and won't take advantage of a Bag's ability to store duplicates as simply increments in a count.
Current mutable factory code:
public MutableIntBag withAll(IntStream items)
{
return this.with(items.toArray());
}
Current immutable factory code:
public ImmutableIntBag withAll(IntStream items)
{
return this.with(items.toArray());
}
It would be much better to simply iterate over the Stream and add the results to a HashBag, converting to an ImmutableBag in the immutable factory.
The text was updated successfully, but these errors were encountered:
Hi @TheJavaGuy, thanks for volunteering! Yes, refactoring this method makes sense as well. Thank you for looking around the code! I've assigned the issue to you.
For mutable Bags it’s easy fix. But for immutable ones I don’t see the way out without bigger changes. In the end the only way to create immutable bag (e.g. ImmutableIntHashBag) is either:
through constructor private ImmutableIntHashBag(int[] newElements), or
through overloaded withAll/ofAll which in the end of the chain must call constructor
To call the constructor array must be filled, and I’m back to square one :(
The code currently in
withAll
on both mutable and immutable implementations callstoArray
onIntStream
which if the Stream is very large can be extremely expensive and won't take advantage of a Bag's ability to store duplicates as simply increments in a count.Current mutable factory code:
Current immutable factory code:
It would be much better to simply iterate over the Stream and add the results to a HashBag, converting to an ImmutableBag in the immutable factory.
The text was updated successfully, but these errors were encountered: