The stream source for BitSet.stream is derived from an iterator.
A SIZED/SUBSIZED spliterator can be implemented if cardinality is calculated at each split down to say the byte level, after which there is no more splitting.
An alternative is to use the max number of possible bits (i.e. the number of words used) as a size estimate and then filter out the 0 bits, for example functionally equivalent to say:
IntStream.range(0, words.length * BITS_PER_WORD).filter(BitStream::get)
A SIZED/SUBSIZED spliterator is good but in this case the size may be expensive to calculate initially and on each split if the bit set is large.
A spliterator that estimates the size is not as good (still better than from an iterator) but less expensive to calculate initially and on each split.
The two approaches could be combined depending on the number of words. If the number of words is below a certain threshold the former can be used, otherwise the latter.
A SIZED/SUBSIZED spliterator can be implemented if cardinality is calculated at each split down to say the byte level, after which there is no more splitting.
An alternative is to use the max number of possible bits (i.e. the number of words used) as a size estimate and then filter out the 0 bits, for example functionally equivalent to say:
IntStream.range(0, words.length * BITS_PER_WORD).filter(BitStream::get)
A SIZED/SUBSIZED spliterator is good but in this case the size may be expensive to calculate initially and on each split if the bit set is large.
A spliterator that estimates the size is not as good (still better than from an iterator) but less expensive to calculate initially and on each split.
The two approaches could be combined depending on the number of words. If the number of words is below a certain threshold the former can be used, otherwise the latter.
- duplicates
-
JDK-8012985 More parallel-friendly spliterator implementations
-
- Closed
-
- relates to
-
JDK-8170159 Improve the performance of BitSet traversal
-
- Resolved
-