com.ibm.util
Class CharTrie
java.lang.Object
|
+--com.ibm.util.CharTrie
- public final class CharTrie
- extends java.lang.Object
Class to manipulate and generate a trie.
This is useful for ICU data in primitive types.
Provides a compact way to store information that is indexed by Unicode
values, such as character properties, types, keyboard values, etc. This is
very useful when you have a block of Unicode data that contains significant
values while the rest of the Unicode data is unused in the application or
when you have a lot of redundance, such as where all 21,000 Han ideographs
have the same value. However, lookup is much faster than a hash table.
A trie of any primitive data type serves two purposes:
- Fast access of the indexed values.
- Smaller memory footprint.
A trie is composed of 2 index array and value array. Combining the 2 index
array, we could get the indicies of Unicode characters to the value array.
The first index array will contain indexes corresponding to the first 11
bits of a 21 bit codepoint, the second index array will contain indexes
corresponding to the next 6 bits of the code point. The last array will
contain the values. Hence to access the value of a codepoint, we can use the
following program
int firstindex = ch >> FIRST_11_BITS_SHIFT;
int secondindex = index1[firstindex] +
(ch >> NEXT_6_BITS_SHIFT) & NEXT_6_BITS_MASK;
int thirdindex = index2[secondindex] + ch & LAST_FOUR_BITS_MASK;
f(ch) = value[thirdindex];
- Version:
- $Revision: 1.2 $
- Author:
- Syn Wee Quek
Constructor Summary |
CharTrie(char[] array)
constructor |
CharTrie(int[] stage1,
int[] stage2,
char[] stage3)
constructor that assigns trie the argument values. |
Method Summary |
char |
getValue(int index)
Getting the trie data corresponding to the argument index. |
java.lang.String |
toString()
Converts trie to a readable format |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
CharTrie
public CharTrie(char[] array)
- constructor
- Parameters:
array
- of data to be populated into trie
CharTrie
public CharTrie(int[] stage1,
int[] stage2,
char[] stage3)
- constructor that assigns trie the argument values. Arrays are not
duplicated.
- Parameters:
stage1
- array of the first set of indexesstage2
- array of the second set of indexesstage3
- array of data
getValue
public char getValue(int index)
- Getting the trie data corresponding to the argument index.
- Parameters:
index
- to be manipulated into corresponding trie index- Returns:
- trie value at index
toString
public java.lang.String toString()
- Converts trie to a readable format
- Overrides:
toString
in class java.lang.Object
- Returns:
- string version of the trie
Copyright (c) 2001 IBM Corporation and others.