Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8072784

Better spliterator implementation for BitSet.stream()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • None
    • b147

      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.

            psandoz Paul Sandoz
            psandoz Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: