Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-823

BloomFilter: Optimize ArrayCountingBloomFilter.ForEachBitMap

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Done
    • 4.5.0-M1
    • 4.5.0-M1
    • Collection

    Description

       
       
      Member

      aherbert on 27 Feb

      This converts all the non zero indices to a bitmap long[] array. But to do so requires using the forEachIndex method with a conditional boolean check on each loop iteration. I wonder if this should be brought inline for efficiency:

           @Override
          public boolean forEachBitMap(LongPredicate consumer) {
              Objects.requireNonNull(consumer, "consumer");
              long[] result = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
              for (int i = 0; i < counts.length; i++) {
                  if (counts[i] != 0) {
                      // Avoids a second check on the predicate result in forEachIndex
                      BitMap.set(result, i);
                  }
              }
              return BitMapProducer.fromBitMapArray(result).forEachBitMap(consumer);
          }
      
      

      Or better yet, avoid the long[] array:

              int blocksm1 = BitMap.numberOfBitMaps(shape.getNumberOfBits()) - 1;
              int i = 0;
              long value;
              for (int j = 0; j < blocksm1; j++) {
                  value = 0;
                  for (int k = 0; k < Long.SIZE; k++) {
                      if (counts[i++] != 0) {
                          value |= BitMap.getLongBit(k);
                      }
                  }
                  if (!consumer.test(value)) {
                      return false;
                  }
              }
              // Final block
              value = 0;
              for (int k = 0; i < counts.length; k++) {
                  if (counts[i++] != 0) {
                      value |= BitMap.getLongBit(k);
                  }
              }
              return consumer.test(value);
      

      Attachments

        Issue Links

          Activity

            People

              claude Claude Warren
              claude Claude Warren
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m