Package org.xlattice.crypto.filters
Class KeySelector
- java.lang.Object
-
- org.xlattice.crypto.filters.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
KeySelector.BitSelector
class
KeySelector.GenericBitSelector
Extracts the k bit offsets from a key, suitable for general values of m and k.class
KeySelector.GenericWordSelector
Extracts the k word offsets from a key.static interface
KeySelector.WordSelector
-
Constructor Summary
Constructors Constructor Description KeySelector(int m, int k)
Creates a key selector for a Bloom filter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
getOffsets(byte[] key, int[] bitOffset, int[] wordOffset)
Given a key, populate the word and bit offset arrays, each of which has k elements.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.
-
-
-
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 2k
- 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 arraysbitOffset
- Out parameter of length kwordOffset
- 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 arraysbitOffset
- Out parameter of length kwordOffset
- Out parameter of length k- Since:
- 0.8.11 out parameters added
-
-