org.xlattice.crypto.filters

## Class KeySelector.GenericBitSelector

- java.lang.Object
- - org.xlattice.crypto.filters.KeySelector.GenericBitSelector

- All Implemented Interfaces:
    KeySelector.BitSelector
  Enclosing class:
    KeySelector

      public class KeySelector.GenericBitSelector
      extends Object
      implements KeySelector.BitSelector

  Generic implementation of BitSelector for extracting bit offsets from cryptographic keys.

  This implementation uses a 5-bit stride algorithm to extract k bit positions from key data. It's suitable for general values of m (filter size) and k (number of hash functions) within reasonable bounds.

  Algorithm overview:
  - Processes key data in 5-bit increments
  - Uses bit manipulation to extract specific bit positions
  - Handles cases where bits span across byte boundaries
  - Employs lookup tables (UNMASK/MASK) for efficient bit operations

  The 5-bit stride is chosen as it provides good distribution while keeping implementation complexity manageable. Each hash function will examine bits that are 5 positions apart in the key.

  Thread Safety: This implementation is thread-safe as it operates only on method parameters and local variables.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericBitSelector()` Default constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `getBitSelectors(byte[] b, int offset, int length, int[] bitOffset)` Extracts k bit offsets from key data using 5-bit stride algorithm.

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

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

- - ### Constructor Detail

    - #### GenericBitSelector

          public GenericBitSelector()

      Default constructor.

  - ### Method Detail

    - #### getBitSelectors

          public void getBitSelectors(byte[] b,
                                      int offset,
                                      int length,
                                      int[] bitOffset)

      Extracts k bit offsets from key data using 5-bit stride algorithm.

      This method processes the key data byte by byte, extracting bit positions at 5-bit intervals. For each bit position, it calculates which byte contains the bit and extracts the appropriate bits using bit masking and shifting operations.

      Algorithm details:
      - Tracks current bit position across byte boundaries
      - Uses UNMASK array to isolate right-aligned bits
      - Uses MASK array to isolate left-aligned bits
      - Handles cases where bits span multiple bytes

      Specified by:
        `getBitSelectors` in interface `KeySelector.BitSelector`
      Parameters:
        `b` - key data as byte array
        `offset` - starting position within key array
        `length` - number of bytes to process
        `bitOffset` - output array of length k to store calculated bit offsets