public abstract class KeyAnalyzer<K> extends Objectimplements Comparator <K>, Serializable
Trie keys on a bit level.
KeyAnalyzer's methods return the length of the key in bits, whether or not a bit is set, and bits per element in the key.
Additionally, a method determines if a key is a prefix of another key and returns the bit index where one key is different from another key (if the key and found key are equal than the return value is EQUAL_BIT_KEY).
| Modifier and Type | Field and Description |
|---|---|
static int |
EQUAL_BIT_KEY
Returned by
bitIndex(Object, int, int, Object, int, int) if key and found key are equal.
|
static int |
NULL_BIT_KEY
Returned by
bitIndex(Object, int, int, Object, int, int) if key's bits are all 0.
|
static int |
OUT_OF_BOUNDS_BIT_KEY
|
| Constructor and Description |
|---|
KeyAnalyzer()
|
| Modifier and Type | Method and Description |
|---|---|
abstract int |
bitIndex(K key, int offsetInBits, int lengthInBits, K other, int otherOffsetInBits, int otherLengthInBits)
Returns the n-th different bit between key and other.
|
abstract int |
bitsPerElement()
Returns the number of bits per element in the key.
|
int |
compare(K o1, K o2)
|
abstract boolean |
isBitSet(K key, int bitIndex, int lengthInBits)
Returns whether or not a bit is set.
|
abstract boolean |
isPrefix(K prefix, int offsetInBits, int lengthInBits, K key)
Determines whether or not the given prefix (from offset to length) is a prefix of the given key.
|
abstract int |
lengthInBits(K key)
Returns the length of the Key in bits.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic static final int NULL_BIT_KEY
bitIndex(Object, int, int, Object, int, int) if key's bits are all 0.
public static final int EQUAL_BIT_KEY
bitIndex(Object, int, int, Object, int, int) if key and found key are equal. This is a very very specific case and shouldn't happen on a regular basis.
public static final int OUT_OF_BOUNDS_BIT_KEY
public abstract int bitsPerElement()
public abstract int lengthInBits(K key)
key - the key
public abstract boolean isBitSet(K key, int bitIndex, int lengthInBits)
key - the key to check, may not be null
bitIndex - the bit index to check
lengthInBits - the maximum key length in bits to check
true if the bit is set in the given key and
bitIndex <
lengthInBits,
false otherwise.
public abstract int bitIndex(K key, int offsetInBits, int lengthInBits, K other, int otherOffsetInBits, int otherLengthInBits)
key - the key to use
offsetInBits - the bit offset in the key
lengthInBits - the maximum key length in bits to use
other - the other key to use
otherOffsetInBits - the bit offset in the other key
otherLengthInBits - the maximum key length in bits for the other key
public abstract boolean isPrefix(K prefix, int offsetInBits, int lengthInBits, K key)
prefix - the prefix to check
offsetInBits - the bit offset in the key
lengthInBits - the maximum key length in bits to use
key - the key to check
true if this is a valid prefix for the given key