com.ibm.util
Class ByteTrie

java.lang.Object
  |
  +--com.ibm.util.ByteTrie

public final class ByteTrie
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:

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.1 $
Author:
Syn Wee Quek

Constructor Summary
ByteTrie(byte[] array)
          constructor
ByteTrie(int[] stage1, int[] stage2, byte[] stage3)
          constructor that assigns trie the argument values.
 
Method Summary
 int getValue(int index)
          Getting the trie data corresponding to the argument index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteTrie

public ByteTrie(byte[] array)
constructor
Parameters:
array - of data to be populated into trie

ByteTrie

public ByteTrie(int[] stage1,
                int[] stage2,
                byte[] stage3)
constructor that assigns trie the argument values. Arrays are not duplicated.
Parameters:
stage1 - array of the first set of indexes
stage2 - array of the second set of indexes
stage3 - array of data
Method Detail

getValue

public int 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


Copyright (c) 1998-2000 IBM Corporation and others.