Top Description Fields Constructors Methods
com.ibm.icu.impl

public Class IntTrieBuilder

extends TrieBuilder
Class Inheritance
Imports
java.io.DataOutputStream, .IOException, .OutputStream, java.util.Arrays, com.ibm.icu.lang.UCharacter, com.ibm.icu.text.UTF16

Builder 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: This is a direct port from the ICU4C version
Author
Syn Wee Quek

Field Summary

Modifier and TypeField and Description
protected int[]
protected int
private int
Inherited from com.ibm.icu.impl.TrieBuilder:
BMP_INDEX_LENGTH_DATA_BLOCK_LENGTHDATA_GRANULARITY_INDEX_SHIFT_m_dataCapacity_m_dataLength_m_index_m_indexLength_m_isCompacted_m_isLatin1Linear_m_map_MASK_MAX_DATA_LENGTH_MAX_INDEX_LENGTH_OPTIONS_DATA_IS_32_BIT_OPTIONS_INDEX_SHIFT_OPTIONS_LATIN1_IS_LINEAR_SHIFT_SURROGATE_BLOCK_COUNT_

Constructor Summary

AccessConstructor and Description
public
IntTrieBuilder(IntTrieBuilder table)

Copy constructor

public
IntTrieBuilder(int[]
data to be filled into table
aliasdata
,
int
maximum data length allowed in table
maxdatalength
,
int
initial data value
initialvalue
,
int leadunitvalue, boolean
is latin 1 to be linear
latin1linear
)

Constructs a build table

Method Summary

Modifier and TypeMethod and Description
private int
private void
compact(boolean
flag
overlap
)

Compact a folded build-time trie.

private void
fillBlock(int block, int start, int limit, int value, boolean overwrite)

private static final int
findSameDataBlock(int[]
array
data
,
int dataLength, int otherBlock, int step)

Find the same data block

private final void
fold(TrieBuilder.DataManipulate
fold implementation
manipulate
)

Fold the normalization data for supplementary code points into a compact area on top of the BMP-part of the trie index, with the lead surrogates indexing this compact area.

private int

Returns:

-1 if no new data block available (out of memory in data array)
getDataBlock
(int
codepoint to look for
ch
)

No error checking for illegal arguments.

public int

Returns:

the 32 bit data
getValue
(int
codepoint which data is to be retrieved
ch
)

Gets a 32 bit data from the table data

public int

Returns:

the 32 bit data value.
getValue
(int
code point for which data is to be retrieved.
ch
,
boolean[]
Output parameter, inBlockZero[0] returns true if the char maps into block zero, otherwise false.
inBlockZero
)

Get a 32 bit data from the table data

public IntTrie

Returns:

a new trie
serialize
(TrieBuilder.DataManipulate
builder raw fold method implementation
datamanipulate
,
Trie.DataManipulate
result trie fold method
triedatamanipulate
)

Serializes the build table with 32 bit data

public int

Returns:

the number of bytes written to the output stream.
serialize
(OutputStream
the output stream to which the seriaized trie will be written. If nul, the function still returns the size of the serialized Trie.
os
,
boolean
If true, reduce the data size to 16 bits. The resulting serialized form can then be used to create a CharTrie.
reduceTo16Bits
,
TrieBuilder.DataManipulate
builder raw fold method implementation
datamanipulate
)

Serializes the build table to an output stream.

public boolean

Returns:

false if a failure occurred (illegal argument or data array overrun)
setRange
(int
the first code point to get the value
start
,
int
one past the last code point to get the value
limit
,
int
the value
value
,
boolean
flag for whether old non-initial values are to be overwritten
overwrite
)

Set a value in a range of code points [start..limit].

public boolean

Returns:

true if the set is successful, otherwise if the table has been compacted return false
setValue
(int
codepoint which data is to be set
ch
,
int
to set
value
)

Sets a 32 bit data in the table data

Inherited from com.ibm.icu.impl.TrieBuilder:
equal_intfindSameIndexBlockfindUnusedBlocksisInZeroBlock

Field Detail

m_data_back to summary
protected int[] m_data_
m_initialValue_back to summary
protected int m_initialValue_
m_leadUnitValue_back to summary
private int m_leadUnitValue_

Constructor Detail

IntTrieBuilderback to summary
public IntTrieBuilder(IntTrieBuilder table)

Copy constructor

IntTrieBuilderback to summary
public IntTrieBuilder(int[] aliasdata, int maxdatalength, int initialvalue, int leadunitvalue, boolean latin1linear)

Constructs a build table

Parameters
aliasdata:int[]

data to be filled into table

maxdatalength:int

maximum data length allowed in table

initialvalue:int

initial data value

latin1linear:boolean

is latin 1 to be linear

Method Detail

allocDataBlockback to summary
private int allocDataBlock()
compactback to summary
private void compact(boolean overlap)

Compact a folded build-time trie. The compaction - removes blocks that are identical with earlier ones - overlaps adjacent blocks as much as possible (if overlap == true) - moves blocks in steps of the data granularity - moves and overlaps blocks that overlap with multiple values in the overlap region It does not - try to move and overlap blocks that are not already adjacent

Parameters
overlap:boolean

flag

fillBlockback to summary
private void fillBlock(int block, int start, int limit, int value, boolean overwrite)
ICU Status
Internal ICU component.
findSameDataBlockback to summary
private static final int findSameDataBlock(int[] data, int dataLength, int otherBlock, int step)

Find the same data block

Parameters
data:int[]

array

foldback to summary
private final void fold(TrieBuilder.DataManipulate manipulate)

Fold the normalization data for supplementary code points into a compact area on top of the BMP-part of the trie index, with the lead surrogates indexing this compact area. Duplicate the index values for lead surrogates: From inside the BMP area, where some may be overridden with folded values, to just after the BMP area, where they can be retrieved for code point lookups.

Parameters
manipulate:TrieBuilder.DataManipulate

fold implementation

getDataBlockback to summary
private int getDataBlock(int ch)

No error checking for illegal arguments.

Parameters
ch:int

codepoint to look for

Returns:int

-1 if no new data block available (out of memory in data array)

getValueback to summary
public int getValue(int ch)

Gets a 32 bit data from the table data

Parameters
ch:int

codepoint which data is to be retrieved

Returns:int

the 32 bit data

getValueback to summary
public int getValue(int ch, boolean[] inBlockZero)

Get a 32 bit data from the table data

Parameters
ch:int

code point for which data is to be retrieved.

inBlockZero:boolean[]

Output parameter, inBlockZero[0] returns true if the char maps into block zero, otherwise false.

Returns:int

the 32 bit data value.

serializeback to summary
public IntTrie serialize(TrieBuilder.DataManipulate datamanipulate, Trie.DataManipulate triedatamanipulate)

Serializes the build table with 32 bit data

Parameters
datamanipulate:TrieBuilder.DataManipulate

builder raw fold method implementation

triedatamanipulate:Trie.DataManipulate

result trie fold method

Returns:IntTrie

a new trie

serializeback to summary
public int serialize(OutputStream os, boolean reduceTo16Bits, TrieBuilder.DataManipulate datamanipulate) throws IOException

Serializes the build table to an output stream. Compacts the build-time trie after all values are set, and then writes the serialized form onto an output stream. After this, this build-time Trie can only be serialized again and/or closed; no further values can be added. This function is the rough equivalent of utrie_seriaize() in ICU4C.

Parameters
os:OutputStream

the output stream to which the seriaized trie will be written. If nul, the function still returns the size of the serialized Trie.

reduceTo16Bits:boolean

If true, reduce the data size to 16 bits. The resulting serialized form can then be used to create a CharTrie.

datamanipulate:TrieBuilder.DataManipulate

builder raw fold method implementation

Returns:int

the number of bytes written to the output stream.

setRangeback to summary
public boolean setRange(int start, int limit, int value, boolean overwrite)

Set a value in a range of code points [start..limit]. All code points c with start <= c < limit will get the value if overwrite is true or if the old value is 0.

Parameters
start:int

the first code point to get the value

limit:int

one past the last code point to get the value

value:int

the value

overwrite:boolean

flag for whether old non-initial values are to be overwritten

Returns:boolean

false if a failure occurred (illegal argument or data array overrun)

setValueback to summary
public boolean setValue(int ch, int value)

Sets a 32 bit data in the table data

Parameters
ch:int

codepoint which data is to be set

value:int

to set

Returns:boolean

true if the set is successful, otherwise if the table has been compacted return false