org.xlattice.crypto.filters
Class KeySelector

java.lang.Object
  extended byorg.xlattice.crypto.filters.KeySelector

public class KeySelector
extends java.lang.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.

Nested Class Summary
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
           
 
Field Summary
static int[] MASK
          AND with byte to zero out index-many bits
static int TWO_UP_15
           
static int[] UNMASK
          AND with byte to expose index-many bits
 
Constructor Summary
KeySelector(int m, int k, int[] bitOffset, int[] wordOffset)
          Creates a key selector for a Bloom filter.
 
Method Summary
(package private)  java.lang.String btoh(byte b)
           
 void getOffsets(byte[] key)
          Given a key, populate the word and bit offset arrays, each of which has k elements.
(package private)  java.lang.String itoh(int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNMASK

public static final int[] UNMASK
AND with byte to expose index-many bits


MASK

public static final int[] MASK
AND with byte to zero out index-many bits


TWO_UP_15

public static final int TWO_UP_15
See Also:
Constant Field Values
Constructor Detail

KeySelector

public KeySelector(int m,
                   int k,
                   int[] bitOffset,
                   int[] wordOffset)
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'
bitOffset - array of k bit offsets (offset of flag bit in word)
wordOffset - array of k word offsets (offset of word flag is in)
Method Detail

getOffsets

public void getOffsets(byte[] key)
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

itoh

java.lang.String itoh(int i)

btoh

java.lang.String btoh(byte b)