public abstract class KeyAnalyzer<K> extends Object implements 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, wait
equals
public 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 keypublic abstract boolean isBitSet(K key, int bitIndex, int lengthInBits)
key
- the key to check, may not be nullbitIndex
- the bit index to checklengthInBits
- the maximum key length in bits to checktrue
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 useoffsetInBits
- the bit offset in the keylengthInBits
- the maximum key length in bits to useother
- the other key to useotherOffsetInBits
- the bit offset in the other keyotherLengthInBits
- the maximum key length in bits for the other keypublic abstract boolean isPrefix(K prefix, int offsetInBits, int lengthInBits, K key)
prefix
- the prefix to checkoffsetInBits
- the bit offset in the keylengthInBits
- the maximum key length in bits to usekey
- the key to checktrue
if this is a valid prefix for the given keypublic int compare(K o1, K o2)
compare
in interface Comparator<K>
Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.