Class BitSetUtil


  • public class BitSetUtil
    extends java.lang.Object
    This class provides convenience functions to manipulate BitSet and RoaringBitmap objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BLOCK_LENGTH  
    • Constructor Summary

      Constructors 
      Constructor Description
      BitSetUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static char[] arrayContainerBufferOf​(int from, int to, int cardinality, long[] words)
      Creates array container's content char buffer.
      static RoaringBitmap bitmapOf​(long[] words)
      Generate a RoaringBitmap out of a long[], each long using little-endian representation of its bits
      static RoaringBitmap bitmapOf​(java.nio.ByteBuffer bb, boolean fastRank)
      Efficiently generate a RoaringBitmap from an uncompressed byte array or ByteBuffer This method tries to minimise all kinds of memory allocation
      static RoaringBitmap bitmapOf​(java.nio.ByteBuffer bb, boolean fastRank, long[] wordsBuffer)
      Efficiently generate a RoaringBitmap from an uncompressed byte array or ByteBuffer This method tries to minimise all kinds of memory allocation
      You can provide a cached wordsBuffer for avoiding 8 KB of extra allocation on every call No reference is kept to the wordsBuffer, so it can be cached as a ThreadLocal
      static RoaringBitmap bitmapOf​(java.util.BitSet bitSet)
      Generate a RoaringBitmap out of a BitSet
      static java.util.BitSet bitsetOf​(RoaringBitmap bitmap)
      Convert a RoaringBitmap to a BitSet.
      static java.util.BitSet bitsetOfWithoutCopy​(RoaringBitmap bitmap)
      Convert a RoaringBitmap to a BitSet without copying to an intermediate array.
      static boolean equals​(java.util.BitSet bitset, RoaringBitmap bitmap)
      Compares a RoaringBitmap and a BitSet.
      static byte[] toByteArray​(RoaringBitmap bitmap)
      Returns an array of little-endian ordered bytes, given a RoaringBitmap.
      static long[] toLongArray​(RoaringBitmap bitmap)
      Returns an array of long, given a RoaringBitmap.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BitSetUtil

        public BitSetUtil()
    • Method Detail

      • bitsetOf

        public static java.util.BitSet bitsetOf​(RoaringBitmap bitmap)
        Convert a RoaringBitmap to a BitSet.

        Equivalent to calling BitSet.valueOf(BitSetUtil.toLongArray(bitmap)).

      • bitsetOfWithoutCopy

        public static java.util.BitSet bitsetOfWithoutCopy​(RoaringBitmap bitmap)
        Convert a RoaringBitmap to a BitSet without copying to an intermediate array.
      • toByteArray

        public static byte[] toByteArray​(RoaringBitmap bitmap)
        Returns an array of little-endian ordered bytes, given a RoaringBitmap.

        See BitSet.toByteArray().

      • toLongArray

        public static long[] toLongArray​(RoaringBitmap bitmap)
        Returns an array of long, given a RoaringBitmap.

        See BitSet.toLongArray().

      • arrayContainerBufferOf

        public static char[] arrayContainerBufferOf​(int from,
                                                    int to,
                                                    int cardinality,
                                                    long[] words)
        Creates array container's content char buffer.
        Parameters:
        from - first value of the range
        to - last value of the range
        cardinality - new buffer cardinality, expected to be less than 4096 and more than present values in given bitmap
        words - bitmap
        Returns:
        array container's content char buffer
      • bitmapOf

        public static RoaringBitmap bitmapOf​(java.util.BitSet bitSet)
        Generate a RoaringBitmap out of a BitSet
        Parameters:
        bitSet - original bitset (will not be modified)
        Returns:
        roaring bitmap equivalent to BitSet
      • bitmapOf

        public static RoaringBitmap bitmapOf​(long[] words)
        Generate a RoaringBitmap out of a long[], each long using little-endian representation of its bits
        Parameters:
        words - array of longs (will not be modified)
        Returns:
        roaring bitmap
        See Also:
        for an equivalent
      • bitmapOf

        public static RoaringBitmap bitmapOf​(java.nio.ByteBuffer bb,
                                             boolean fastRank)
        Efficiently generate a RoaringBitmap from an uncompressed byte array or ByteBuffer This method tries to minimise all kinds of memory allocation
        Parameters:
        bb - the uncompressed bitmap
        fastRank - if set, returned bitmap is of type FastRankRoaringBitmap
        Returns:
        roaring bitmap
      • bitmapOf

        public static RoaringBitmap bitmapOf​(java.nio.ByteBuffer bb,
                                             boolean fastRank,
                                             long[] wordsBuffer)
        Efficiently generate a RoaringBitmap from an uncompressed byte array or ByteBuffer This method tries to minimise all kinds of memory allocation
        You can provide a cached wordsBuffer for avoiding 8 KB of extra allocation on every call No reference is kept to the wordsBuffer, so it can be cached as a ThreadLocal
        Parameters:
        bb - the uncompressed bitmap
        fastRank - if set, returned bitmap is of type FastRankRoaringBitmap
        wordsBuffer - buffer of length BLOCK_LENGTH
        Returns:
        roaring bitmap
      • equals

        public static boolean equals​(java.util.BitSet bitset,
                                     RoaringBitmap bitmap)
        Compares a RoaringBitmap and a BitSet. They are equal if and only if they contain the same set of integers.
        Parameters:
        bitset - first object to be compared
        bitmap - second object to be compared
        Returns:
        whether they are equals