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

Better spliterator implementation for BitSet.stream()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b147

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: