Package org.apache.commons.collections4.bloomfilter

# Class BitMaps

java.lang.Object
org.apache.commons.collections4.bloomfilter.BitMaps

public class BitMaps extends Object
Contains functions to convert `int` indices into Bloom filter bit positions and visa versa.

The functions view an array of longs as a collection of bit maps each containing 64 bits. The bits are arranged in memory as a little-endian long value. This matches the requirements of the BitMapExtractor interface.

Since:
  4.5.0-M2

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `contains(long[] bitMaps, int bitIndex)`
  Checks if the specified index bit is enabled in the array of bit maps.
  `static long`
  `getLongBit(int bitIndex)`
  Gets the filter bit mask for the specified bit index assuming the filter is using 64-bit longs to store bits starting at index 0.
  `static int`
  `getLongIndex(int bitIndex)`
  Gets the filter index for the specified bit index assuming the filter is using 64-bit longs to store bits starting at index 0.
  `static int`
  `mod(long dividend, int divisor)`
  Performs a modulus calculation on an unsigned long and a positive integer divisor.
  `static int`
  `numberOfBitMaps(int numberOfBits)`
  Calculates the number of bit maps (longs) required for the numberOfBits parameter.
  `static void`
  `set(long[] bitMaps, int bitIndex)`
  Sets the bit in the bit maps.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### contains

    public static boolean contains(long[] bitMaps, int bitIndex)
    Checks if the specified index bit is enabled in the array of bit maps.

    If the bit specified by bitIndex is not in the bit map false is returned.

    Parameters:
      `bitMaps` - The array of bit maps.
      `bitIndex` - The index of the bit to locate.
    Returns:
      `true` if the bit is enabled, `false` otherwise.
    Throws:
      `IndexOutOfBoundsException` - if bitIndex specifies a bit not in the range being tracked.

  - ### getLongBit

    public static long getLongBit(int bitIndex)
    Gets the filter bit mask for the specified bit index assuming the filter is using 64-bit longs to store bits starting at index 0. The returned value is a `long` with only 1 bit set.

    The index is assumed to be positive. For a positive index the result will match `1L << (bitIndex % 64)`.

    If the input is negative the behavior is not defined.

    Parameters:
      `bitIndex` - The bit index (assumed to be positive)
    Returns:
      The filter bit

  - ### getLongIndex

    public static int getLongIndex(int bitIndex)
    Gets the filter index for the specified bit index assuming the filter is using 64-bit longs to store bits starting at index 0.

    The index is assumed to be positive. For a positive index the result will match `bitIndex / 64`.

    The divide is performed using bit shifts. If the input is negative the behavior is not defined.

    Parameters:
      `bitIndex` - The bit index (assumed to be positive)
    Returns:
      The index of the bit map in an array of bit maps.

  - ### mod

    public static int mod(long dividend, int divisor)
    Performs a modulus calculation on an unsigned long and a positive integer divisor.

    This method computes the same result as `Long.remainderUnsigned(long, long)` but assumes that the divisor is an integer in the range 1 to 231 - 1 inclusive, that is a strictly positive integer size.

    If the divisor is negative the behavior is not defined.

    Parameters:
      `dividend` - An unsigned long value to calculate the modulus of.
      `divisor` - The divisor for the modulus calculation, must be strictly positive.
    Returns:
      The remainder or modulus value.
    Throws:
      `ArithmeticException` - if the divisor is zero
    See Also:
      - `Long.remainderUnsigned(long, long)`

  - ### numberOfBitMaps

    public static int numberOfBitMaps(int numberOfBits)
    Calculates the number of bit maps (longs) required for the numberOfBits parameter.

    If the input is negative the behavior is not defined.

    Parameters:
      `numberOfBits` - The number of bits to store in the array of bit maps.
    Returns:
      The number of bit maps necessary.

  - ### set

    public static void set(long[] bitMaps, int bitIndex)
    Sets the bit in the bit maps.

    Does not perform range checking

    Parameters:
      `bitMaps` - The array of bit maps.
      `bitIndex` - The index of the bit to set.
    Throws:
      `IndexOutOfBoundsException` - if bitIndex specifies a bit not in the range being tracked.