org.ardverk.collection
Interface KeyAnalyzer<K>

All Superinterfaces:
java.util.Comparator<K>, java.io.Serializable
All Known Implementing Classes:
AbstractKeyAnalyzer, ByteArrayKeyAnalyzer, ByteKeyAnalyzer, CharacterKeyAnalyzer, CharArrayKeyAnalyzer, IntegerKeyAnalyzer, LongKeyAnalyzer, ShortKeyAnalyzer, StringKeyAnalyzer

public interface KeyAnalyzer<K>
extends java.util.Comparator<K>, java.io.Serializable

Defines the interface to analyze 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).


Field Summary
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
           
 
Method Summary
 int bitIndex(K key, int offsetInBits, int lengthInBits, K other, int otherOffsetInBits, int otherLengthInBits)
          Returns the n-th different bit between key and found.
 int bitsPerElement()
          Returns the number of bits per element in the key.
 boolean isBitSet(K key, int bitIndex, int lengthInBits)
          Returns whether or not a bit is set
 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.
 int lengthInBits(K key)
          Returns the length of the Key in bits.
 
Methods inherited from interface java.util.Comparator
compare, equals
 

Field Detail

NULL_BIT_KEY

static final int NULL_BIT_KEY
Returned by bitIndex(Object, int, int, Object, int, int) if key's bits are all 0

See Also:
Constant Field Values

EQUAL_BIT_KEY

static final int EQUAL_BIT_KEY
Returned by 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

See Also:
Constant Field Values

OUT_OF_BOUNDS_BIT_KEY

static final int OUT_OF_BOUNDS_BIT_KEY
See Also:
Constant Field Values
Method Detail

bitsPerElement

int bitsPerElement()
Returns the number of bits per element in the key. This is only useful for variable-length keys, such as Strings.


lengthInBits

int lengthInBits(K key)
Returns the length of the Key in bits.


isBitSet

boolean isBitSet(K key,
                 int bitIndex,
                 int lengthInBits)
Returns whether or not a bit is set


bitIndex

int bitIndex(K key,
             int offsetInBits,
             int lengthInBits,
             K other,
             int otherOffsetInBits,
             int otherLengthInBits)
Returns the n-th different bit between key and found. This starts the comparison in key at 'keyStart' and goes for 'keyLength' bits, and compares to the found key starting at 'foundStart' and going for 'foundLength' bits.


isPrefix

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.



Copyright © 2005-2009 Roger Kapsi, Sam Berlin. All Rights Reserved.