All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.roaringbitmap.insights.BitmapAnalyser Maven / Gradle / Ivy

Go to download

Roaring bitmaps are compressed bitmaps (also called bitsets) which tend to outperform conventional compressed bitmaps such as WAH or Concise.

There is a newer version: 1.3.0
Show newest version
package org.roaringbitmap.insights;

import org.roaringbitmap.ContainerPointer;
import org.roaringbitmap.RoaringBitmap;

import java.util.Collection;

public class BitmapAnalyser {

  /**
   * Analyze the internal representation of bitmap
   * @param r the bitmap
   * @return the statistics
   */
  public static BitmapStatistics analyse(RoaringBitmap r) {
    int acCount = 0;
    int acCardinalitySum = 0;
    int bcCount = 0;
    int rcCount = 0;
    ContainerPointer cp = r.getContainerPointer();
    while (cp.getContainer() != null) {
      if (cp.isBitmapContainer()) {
        bcCount += 1;
      } else if (cp.isRunContainer()) {
        rcCount += 1;
      } else {
        acCount += 1;
        acCardinalitySum += cp.getCardinality();
      }
      cp.advance();
    }
    BitmapStatistics.ArrayContainersStats acStats =
        new BitmapStatistics.ArrayContainersStats(acCount, acCardinalitySum);
    return new BitmapStatistics(acStats, bcCount, rcCount);
  }

  /**
   * Analyze the internal representation of bitmaps
   * @param bitmaps the bitmaps
   * @return the statistics
   */
  public static BitmapStatistics analyse(Collection bitmaps) {
    return bitmaps
      .stream()
      .reduce(
        BitmapStatistics.empty,
        (acc, r) -> acc.merge(BitmapAnalyser.analyse(r)),
        BitmapStatistics::merge);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy