Class KeySelector


  • public class KeySelector
    extends Object
    Given a key, populates arrays determining word and bit offsets into a Bloom filter.
    Author:
    Jim Dixon BloomSHA1.java and KeySelector.java are BSD licensed from the xlattice app - http://xlattice.sourceforge.net/ minor tweaks by jrandom, exposing unsynchronized access and allowing larger M and K. changes released into the public domain. As of 0.8.11, bitoffset and wordoffset out parameters moved from fields to selector arguments, to allow concurrency. ALl methods are now thread-safe.
    • Constructor Detail

      • KeySelector

        public KeySelector​(int m,
                           int k)
        Creates a key selector for a Bloom filter. When a key is presented to the getOffsets() method, the k 'hash function' values are extracted and used to populate bitOffset and wordOffset arrays which specify the k flags to be set or examined in the filter.
        Parameters:
        m - size of the filter as a power of 2
        k - number of 'hash functions' Note that if k and m are too big, the GenericWordSelector blows up - The max for 32-byte keys is m=23 and k=11. The precise restriction appears to be: ((5k + (k-1)(m-5)) / 8) + 2 < keySizeInBytes It isn't clear how to fix this.
    • Method Detail

      • getOffsets

        public void getOffsets​(byte[] key,
                               int[] bitOffset,
                               int[] wordOffset)
        Given a key, populate the word and bit offset arrays, each of which has k elements.
        Parameters:
        key - cryptographic key used in populating the arrays
        bitOffset - Out parameter of length k
        wordOffset - Out parameter of length k
        Since:
        0.8.11 out parameters added
      • getOffsets

        public void getOffsets​(byte[] key,
                               int off,
                               int len,
                               int[] bitOffset,
                               int[] wordOffset)
        Given a key, populate the word and bit offset arrays, each of which has k elements.
        Parameters:
        key - cryptographic key used in populating the arrays
        bitOffset - Out parameter of length k
        wordOffset - Out parameter of length k
        Since:
        0.8.11 out parameters added