APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.icu.impl

pack-priv abstract Class Trie2

extends Object
implements Iterable<Trie2.Range>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Known Direct Subclasses
jdk.internal.icu.impl.Trie2_16
Imports
java.io.IOException, java.nio.ByteBuffer, .ByteOrder, java.util.Iterator, .NoSuchElementException

This is the interface and common implementation of a Unicode Trie2. It is a kind of compressed table that maps from Unicode code points (0..0x10ffff) to 16- or 32-bit integer values. It works best when there are ranges of characters with the same value, which is generally the case with Unicode character properties. This is the second common version of a Unicode trie (hence the name Trie2).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Trie2.Range

When iterating over the contents of a Trie2, Elements of this type are produced.

pack-priv class
Trie2.Trie2Iterator

Implementation class for an iterator over a Trie2.

pack-priv static class
Trie2.UTrie2Header

Trie2 data structure in serialized form: UTrie2Header header; uint16_t index[header.index2Length]; uint16_t data[header.shiftedDataLength<<2]; -- or uint32_t data[...] For Java, this is read from the stream into an instance of UTrie2Header.

public static interface
Trie2.ValueMapper

When iterating over the contents of a Trie2, an instance of TrieValueMapper may be used to remap the values from the Trie2.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int[]
pack-priv int
pack-priv int
private static Trie2.ValueMapper
pack-priv int
errorValue

Value returned for out-of-range code points and illegal UTF-8.

pack-priv Trie2.UTrie2Header
pack-priv int
pack-priv int
pack-priv char[]
pack-priv int
pack-priv int
pack-priv int
pack-priv static final int
UTRIE2_BAD_UTF8_DATA_OFFSET

The illegal-UTF-8 data block follows the ASCII block, at offset 128=0x80.

pack-priv static final int
UTRIE2_DATA_BLOCK_LENGTH

Number of entries in a data block.

pack-priv static final int
UTRIE2_DATA_GRANULARITY

The alignment size of a data block.

pack-priv static final int
UTRIE2_DATA_MASK

Mask for getting the lower bits for the in-data-block offset.

pack-priv static final int
UTRIE2_INDEX_1_OFFSET

The index-1 table, only used for supplementary code points, at offset 2112=0x840.

pack-priv static final int
UTRIE2_INDEX_2_BLOCK_LENGTH

Number of entries in an index-2 block.

pack-priv static final int
UTRIE2_INDEX_2_BMP_LENGTH

Count the lengths of both BMP pieces.

pack-priv static final int
UTRIE2_INDEX_2_MASK

Mask for getting the lower bits for the in-index-2-block offset.

pack-priv static final int
UTRIE2_INDEX_SHIFT

Shift size for shifting left the index array values.

pack-priv static final int
pack-priv static final int
UTRIE2_LSCP_INDEX_2_OFFSET

The part of the index-2 table for U+D800..U+DBFF stores values for lead surrogate code _units_ not code _points_.

pack-priv static final int
UTRIE2_OMITTED_BMP_INDEX_1_LENGTH

Number of index-1 entries for the BMP.

pack-priv static final int
UTRIE2_OPTIONS_VALUE_BITS_MASK

Trie2 constants, defining shift widths, index array lengths, etc. These are needed for the runtime macros but users can treat these as implementation details and skip to the actual public API further below.

pack-priv static final int
UTRIE2_SHIFT_1

Shift size for getting the index-1 table offset.

pack-priv static final int
UTRIE2_SHIFT_1_2

Difference between the two shift sizes, for getting an index-1 offset from an index-2 offset.

pack-priv static final int
UTRIE2_SHIFT_2

Shift size for getting the index-2 table offset.

pack-priv static final int
pack-priv static final int
UTRIE2_UTF8_2B_INDEX_2_OFFSET

The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static Trie2

Returns:

An unserialized Trie2, ready for use.
createFromSerialized
(ByteBuffer
a byte buffer to the serialized form of a UTrie2.
bytes
)

Create a Trie2 from its serialized form.

public abstract int

Returns:

the value
get
(int
the code point
codePoint
)

Get the value for a code point as stored in the Trie2.

public abstract int

Returns:

the value
getFromU16SingleLead
(char
the code point or lead surrogate value.
c
)

Get the trie value for a UTF-16 code unit.

private static int
hashByte(int h, int b)

private static int
hashInt(int h, int i)

private static int
hashUChar32(int h, int c)

private static int
public Iterator<Trie2.Range>

Returns:

an Iterator
iterator
()

Implements java.lang.Iterable.iterator.

Create an iterator over the value ranges in this Trie2.

public Iterator<Trie2.Range>

Returns:

an Iterator
iterator
(Trie2.ValueMapper
provides a function to remap values obtained from the Trie2.
mapper
)

Create an iterator over the value ranges from this Trie2.

pack-priv int

Returns:

The last contiguous character with the same value.
rangeEnd
(int start, int limitp, int val)

Find the last character in a contiguous range of characters with the same Trie2 value as the input character.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

data16back to summary
pack-priv int data16
data32back to summary
pack-priv int[] data32
dataLengthback to summary
pack-priv int dataLength
dataNullOffsetback to summary
pack-priv int dataNullOffset
defaultValueMapperback to summary
private static Trie2.ValueMapper defaultValueMapper
errorValueback to summary
pack-priv int errorValue

Value returned for out-of-range code points and illegal UTF-8.

highStartback to summary
pack-priv int highStart
highValueIndexback to summary
pack-priv int highValueIndex
indexback to summary
pack-priv char[] index
index2NullOffsetback to summary
pack-priv int index2NullOffset
indexLengthback to summary
pack-priv int indexLength
initialValueback to summary
pack-priv int initialValue
UTRIE2_BAD_UTF8_DATA_OFFSETback to summary
pack-priv static final int UTRIE2_BAD_UTF8_DATA_OFFSET

The illegal-UTF-8 data block follows the ASCII block, at offset 128=0x80. Used with linear access for single bytes 0..0xbf for simple error handling. Length 64=0x40, not UTRIE2_DATA_BLOCK_LENGTH.

UTRIE2_DATA_BLOCK_LENGTHback to summary
pack-priv static final int UTRIE2_DATA_BLOCK_LENGTH

Number of entries in a data block. 32=0x20

UTRIE2_DATA_GRANULARITYback to summary
pack-priv static final int UTRIE2_DATA_GRANULARITY

The alignment size of a data block. Also the granularity for compaction.

UTRIE2_DATA_MASKback to summary
pack-priv static final int UTRIE2_DATA_MASK

Mask for getting the lower bits for the in-data-block offset.

UTRIE2_INDEX_1_OFFSETback to summary
pack-priv static final int UTRIE2_INDEX_1_OFFSET

The index-1 table, only used for supplementary code points, at offset 2112=0x840. Variable length, for code points up to highStart, where the last single-value range starts. Maximum length 512=0x200=0x100000>>UTRIE2_SHIFT_1. (For 0x100000 supplementary code points U+10000..U+10ffff.) The part of the index-2 table for supplementary code points starts after this index-1 table. Both the index-1 table and the following part of the index-2 table are omitted completely if there is only BMP data.

UTRIE2_INDEX_2_BLOCK_LENGTHback to summary
pack-priv static final int UTRIE2_INDEX_2_BLOCK_LENGTH

Number of entries in an index-2 block. 64=0x40

UTRIE2_INDEX_2_BMP_LENGTHback to summary
pack-priv static final int UTRIE2_INDEX_2_BMP_LENGTH

Count the lengths of both BMP pieces. 2080=0x820

UTRIE2_INDEX_2_MASKback to summary
pack-priv static final int UTRIE2_INDEX_2_MASK

Mask for getting the lower bits for the in-index-2-block offset.

UTRIE2_INDEX_SHIFTback to summary
pack-priv static final int UTRIE2_INDEX_SHIFT

Shift size for shifting left the index array values. Increases possible data size with 16-bit index values at the cost of compactability. This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY.

UTRIE2_LSCP_INDEX_2_LENGTHback to summary
pack-priv static final int UTRIE2_LSCP_INDEX_2_LENGTH
UTRIE2_LSCP_INDEX_2_OFFSETback to summary
pack-priv static final int UTRIE2_LSCP_INDEX_2_OFFSET

The part of the index-2 table for U+D800..U+DBFF stores values for lead surrogate code _units_ not code _points_. Values for lead surrogate code _points_ are indexed with this portion of the table. Length=32=0x20=0x400>>UTRIE2_SHIFT_2. (There are 1024=0x400 lead surrogates.)

UTRIE2_OMITTED_BMP_INDEX_1_LENGTHback to summary
pack-priv static final int UTRIE2_OMITTED_BMP_INDEX_1_LENGTH

Number of index-1 entries for the BMP. 32=0x20 This part of the index-1 table is omitted from the serialized form.

UTRIE2_OPTIONS_VALUE_BITS_MASKback to summary
pack-priv static final int UTRIE2_OPTIONS_VALUE_BITS_MASK

Trie2 constants, defining shift widths, index array lengths, etc. These are needed for the runtime macros but users can treat these as implementation details and skip to the actual public API further below.

UTRIE2_SHIFT_1back to summary
pack-priv static final int UTRIE2_SHIFT_1

Shift size for getting the index-1 table offset.

UTRIE2_SHIFT_1_2back to summary
pack-priv static final int UTRIE2_SHIFT_1_2

Difference between the two shift sizes, for getting an index-1 offset from an index-2 offset. 6=11-5

UTRIE2_SHIFT_2back to summary
pack-priv static final int UTRIE2_SHIFT_2

Shift size for getting the index-2 table offset.

UTRIE2_UTF8_2B_INDEX_2_LENGTHback to summary
pack-priv static final int UTRIE2_UTF8_2B_INDEX_2_LENGTH
UTRIE2_UTF8_2B_INDEX_2_OFFSETback to summary
pack-priv static final int UTRIE2_UTF8_2B_INDEX_2_OFFSET

The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820. Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2.

Constructor Detail

Trie2back to summary
pack-priv Trie2()

Method Detail

createFromSerializedback to summary
public static Trie2 createFromSerialized(ByteBuffer bytes) throws IOException

Create a Trie2 from its serialized form. Inverse of utrie2_serialize(). Reads from the current position and leaves the buffer after the end of the trie. The serialized format is identical between ICU4C and ICU4J, so this function will work with serialized Trie2s from either. The actual type of the returned Trie2 will be either Trie2_16 or Trie2_32, depending on the width of the data. To obtain the width of the Trie2, check the actual class type of the returned Trie2. Or use the createFromSerialized() function of Trie2_16 or Trie2_32, which will return only Tries of their specific type/size. The serialized Trie2 on the stream may be in either little or big endian byte order. This allows using serialized Tries from ICU4C without needing to consider the byte order of the system that created them.

Parameters
bytes:ByteBuffer

a byte buffer to the serialized form of a UTrie2.

Returns:Trie2

An unserialized Trie2, ready for use.

Exceptions
IOException:
if a read error occurs in the buffer.
IllegalArgumentException:
if the stream does not contain a serialized Trie2.
getback to summary
public abstract int get(int codePoint)

Get the value for a code point as stored in the Trie2.

Parameters
codePoint:int

the code point

Returns:int

the value

getFromU16SingleLeadback to summary
public abstract int getFromU16SingleLead(char c)

Get the trie value for a UTF-16 code unit. A Trie2 stores two distinct values for input in the lead surrogate range, one for lead surrogates, which is the value that will be returned by this function, and a second value that is returned by Trie2.get(). For code units outside of the lead surrogate range, this function returns the same result as Trie2.get(). This function, together with the alternate value for lead surrogates, makes possible very efficient processing of UTF-16 strings without first converting surrogate pairs to their corresponding 32 bit code point values. At build-time, enumerate the contents of the Trie2 to see if there is non-trivial (non-initialValue) data for any of the supplementary code points associated with a lead surrogate. If so, then set a special (application-specific) value for the lead surrogate code _unit_, with Trie2Writable.setForLeadSurrogateCodeUnit(). At runtime, use Trie2.getFromU16SingleLead(). If there is non-trivial data and the code unit is a lead surrogate, then check if a trail surrogate follows. If so, assemble the supplementary code point and look up its value with Trie2.get(); otherwise reset the lead surrogate's value or do a code point lookup for it. If there is only trivial data for lead and trail surrogates, then processing can often skip them. For example, in normalization or case mapping all characters that do not have any mappings are simply copied as is.

Parameters
c:char

the code point or lead surrogate value.

Returns:int

the value

hashByteback to summary
private static int hashByte(int h, int b)
hashIntback to summary
private static int hashInt(int h, int i)
hashUChar32back to summary
private static int hashUChar32(int h, int c)
initHashback to summary
private static int initHash()
iteratorback to summary
public Iterator<Trie2.Range> iterator()

Implements java.lang.Iterable.iterator.

Create an iterator over the value ranges in this Trie2. Values from the Trie2 are not remapped or filtered, but are returned as they are stored in the Trie2.

Returns:Iterator<Trie2.Range>

an Iterator

iteratorback to summary
public Iterator<Trie2.Range> iterator(Trie2.ValueMapper mapper)

Create an iterator over the value ranges from this Trie2. Values from the Trie2 are passed through a caller-supplied remapping function, and it is the remapped values that determine the ranges that will be produced by the iterator.

Parameters
mapper:Trie2.ValueMapper

provides a function to remap values obtained from the Trie2.

Returns:Iterator<Trie2.Range>

an Iterator

rangeEndback to summary
pack-priv int rangeEnd(int start, int limitp, int val)

Find the last character in a contiguous range of characters with the same Trie2 value as the input character.

Returns:int

The last contiguous character with the same value.

jdk.internal.icu.impl back to summary

public Class Trie2.Range

extends Object
Class Inheritance

When iterating over the contents of a Trie2, Elements of this type are produced. The iterator will return one item for each contiguous range of codepoints having the same value. When iterating, the same Trie2EnumRange object will be reused and returned for each range. If you need to retain complete iteration results, clone each returned Trie2EnumRange, or save the range in some other way, before advancing to the next iteration step.

Field Summary

Modifier and TypeField and Description
public int
public boolean
public int
public int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object other)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

endCodePointback to summary
public int endCodePoint
leadSurrogateback to summary
public boolean leadSurrogate
startCodePointback to summary
public int startCodePoint
valueback to summary
public int value

Constructor Detail

Rangeback to summary
public Range()

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
jdk.internal.icu.impl back to summary

pack-priv Class Trie2.Trie2Iterator

extends Object
implements Iterator<Trie2.Range>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Implementation class for an iterator over a Trie2. Iteration over a Trie2 first returns all of the ranges that are indexed by code points, then returns the special alternate values for the lead surrogates
ICU Status
Internal ICU component.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private int
private Trie2.ValueMapper
private int
private Trie2.Range

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Trie2.Range
next()

Implements java.util.Iterator.next.

The main next() function for Trie2 iterators

private int
rangeEndLS(char startingLS)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

doingCodePointsback to summary
private boolean doingCodePoints
doLeadSurrogatesback to summary
private boolean doLeadSurrogates
limitCPback to summary
private int limitCP
mapperback to summary
private Trie2.ValueMapper mapper
nextStartback to summary
private int nextStart
returnValueback to summary
private Trie2.Range returnValue

Constructor Detail

Trie2Iteratorback to summary
pack-priv Trie2Iterator(Trie2.ValueMapper vm)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

nextback to summary
public Trie2.Range next()

Implements java.util.Iterator.next.

The main next() function for Trie2 iterators

rangeEndLSback to summary
private int rangeEndLS(char startingLS)
jdk.internal.icu.impl back to summary

pack-priv Class Trie2.UTrie2Header

extends Object
Class Inheritance

Trie2 data structure in serialized form: UTrie2Header header; uint16_t index[header.index2Length]; uint16_t data[header.shiftedDataLength<<2]; -- or uint32_t data[...] For Java, this is read from the stream into an instance of UTrie2Header. (The C version just places a struct over the raw serialized data.)
ICU Status
Internal ICU component.

Field Summary

Modifier and TypeField and Description
pack-priv int
dataNullOffset

Null index and data blocks, not shifted.

pack-priv int
index2NullOffset

Null index and data blocks, not shifted.

pack-priv int
indexLength

UTRIE2_INDEX_1_OFFSET..UTRIE2_MAX_INDEX_LENGTH (uint16_t)

pack-priv int
options

options bit field (uint16_t): 15..

pack-priv int
shiftedDataLength

(UTRIE2_DATA_START_OFFSET..UTRIE2_MAX_DATA_LENGTH)>>UTRIE2_INDEX_SHIFT (uint16_t)

pack-priv int
shiftedHighStart

First code point of the single-value range ending with U+10ffff, rounded up and then shifted right by UTRIE2_SHIFT_1.

pack-priv int
signature

"Tri2" in big-endian US-ASCII (0x54726932)

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataNullOffsetback to summary
pack-priv int dataNullOffset

Null index and data blocks, not shifted. (uint16_t)

index2NullOffsetback to summary
pack-priv int index2NullOffset

Null index and data blocks, not shifted. (uint16_t)

indexLengthback to summary
pack-priv int indexLength

UTRIE2_INDEX_1_OFFSET..UTRIE2_MAX_INDEX_LENGTH (uint16_t)

optionsback to summary
pack-priv int options

options bit field (uint16_t): 15.. 4 reserved (0) 3.. 0 UTrie2ValueBits valueBits

shiftedDataLengthback to summary
pack-priv int shiftedDataLength

(UTRIE2_DATA_START_OFFSET..UTRIE2_MAX_DATA_LENGTH)>>UTRIE2_INDEX_SHIFT (uint16_t)

shiftedHighStartback to summary
pack-priv int shiftedHighStart

First code point of the single-value range ending with U+10ffff, rounded up and then shifted right by UTRIE2_SHIFT_1. (uint16_t)

signatureback to summary
pack-priv int signature

"Tri2" in big-endian US-ASCII (0x54726932)

Constructor Detail

UTrie2Headerback to summary
pack-priv UTrie2Header()
jdk.internal.icu.impl back to summary

public Interface Trie2.ValueMapper


When iterating over the contents of a Trie2, an instance of TrieValueMapper may be used to remap the values from the Trie2. The remapped values will be used both in determining the ranges of codepoints and as the value to be returned for each range. Example of use, with an anonymous subclass of TrieValueMapper: ValueMapper m = new ValueMapper() { int map(int in) {return in & 0x1f;}; } for (Iterator iter = trie.iterator(m); i.hasNext(); ) { Trie2EnumRange r = i.next(); ... // Do something with the range r. }

Method Summary

Modifier and TypeMethod and Description
public int
map(int originalVal)

Method Detail

mapback to summary
public int map(int originalVal)