edu.wisc.ssec.mcidasv.util.trie
Class CharSequenceKeyAnalyzer

java.lang.Object
  extended by edu.wisc.ssec.mcidasv.util.trie.CharSequenceKeyAnalyzer
All Implemented Interfaces:
PatriciaTrie.KeyAnalyzer<CharSequence>, Serializable, Comparator<CharSequence>

public class CharSequenceKeyAnalyzer
extends Object
implements PatriciaTrie.KeyAnalyzer<CharSequence>

Analyzes CharSequence keys with case sensitivity. With CharSequenceKeyAnalyzer you can compare, check prefix, and determine the index of a bit.

A typical use case for a CharSequenceKeyAnalyzer is with a PatriciaTrie.

    PatriciaTrie<String, String> trie = new PatriciaTrie<String, String>(new CharSequenceKeyAnalyzer());

    trie.put("Lime", "Lime");
    trie.put("LimeWire", "LimeWire");
    trie.put("LimeRadio", "LimeRadio");
    trie.put("Lax", "Lax");
    trie.put("Lake", "Lake");
    trie.put("Lovely", "Lovely");

    System.out.println(trie.select("Lo"));
    System.out.println(trie.select("Lime"));

    System.out.println(trie.getPrefixedBy("La").toString());            

    Output:
        Lovely
        Lime
        {Lake=Lake, Lax=Lax}

 

Author:
Sam Berlin, Roger Kapsi
See Also:
Serialized Form

Field Summary
private static int[] BITS
           
private static long serialVersionUID
           
 
Fields inherited from interface edu.wisc.ssec.mcidasv.util.trie.PatriciaTrie.KeyAnalyzer
EQUAL_BIT_KEY, NULL_BIT_KEY
 
Constructor Summary
CharSequenceKeyAnalyzer()
           
 
Method Summary
 int bitIndex(CharSequence key, int keyOff, int keyLength, CharSequence found, int foundOff, int foundKeyLength)
          Returns the n-th different bit between key and found.
 int bitsPerElement()
          Returns the number of bits per element in the key.
 int compare(CharSequence o1, CharSequence o2)
           
static int[] createIntBitMask(int bitCount)
           
 boolean isBitSet(CharSequence key, int keyLength, int bitIndex)
          Returns whether or not a bit is set
 boolean isPrefix(CharSequence prefix, int offset, int length, CharSequence key)
          Determines whether or not the given prefix (from offset to length) is a prefix of the given key.
 int length(CharSequence key)
          Returns the length of the Key in bits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

BITS

private static final int[] BITS
Constructor Detail

CharSequenceKeyAnalyzer

public CharSequenceKeyAnalyzer()
Method Detail

createIntBitMask

public static final int[] createIntBitMask(int bitCount)

length

public int length(CharSequence key)
Description copied from interface: PatriciaTrie.KeyAnalyzer
Returns the length of the Key in bits.

Specified by:
length in interface PatriciaTrie.KeyAnalyzer<CharSequence>

bitIndex

public int bitIndex(CharSequence key,
                    int keyOff,
                    int keyLength,
                    CharSequence found,
                    int foundOff,
                    int foundKeyLength)
Description copied from interface: PatriciaTrie.KeyAnalyzer
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.

Specified by:
bitIndex in interface PatriciaTrie.KeyAnalyzer<CharSequence>

isBitSet

public boolean isBitSet(CharSequence key,
                        int keyLength,
                        int bitIndex)
Description copied from interface: PatriciaTrie.KeyAnalyzer
Returns whether or not a bit is set

Specified by:
isBitSet in interface PatriciaTrie.KeyAnalyzer<CharSequence>

compare

public int compare(CharSequence o1,
                   CharSequence o2)
Specified by:
compare in interface Comparator<CharSequence>

bitsPerElement

public int bitsPerElement()
Description copied from interface: PatriciaTrie.KeyAnalyzer
Returns the number of bits per element in the key. This is only useful for variable-length keys, such as Strings.

Specified by:
bitsPerElement in interface PatriciaTrie.KeyAnalyzer<CharSequence>

isPrefix

public boolean isPrefix(CharSequence prefix,
                        int offset,
                        int length,
                        CharSequence key)
Description copied from interface: PatriciaTrie.KeyAnalyzer
Determines whether or not the given prefix (from offset to length) is a prefix of the given key.

Specified by:
isPrefix in interface PatriciaTrie.KeyAnalyzer<CharSequence>