public final class MutableCodePointTrie extends CodePointMap implements Cloneable
Setting values (especially ranges) and lookup is fast.
The mutable trie is only somewhat space-efficient.
It builds a compacted, immutable CodePointTrie
.
This trie can be modified while iterating over its contents. For example, it is possible to merge its values with those from another set of ranges (e.g., another @{link CodePointMap}): Iterate over those source ranges; for each of them iterate over this trie; add the source value into the value of each trie range.
CodePointMap.Range, CodePointMap.RangeOption, CodePointMap.StringIterator, CodePointMap.ValueFilter
Constructor and Description |
---|
MutableCodePointTrie(int initialValue,
int errorValue)
Constructs a mutable trie that initially maps each Unicode code point to the same value.
|
Modifier and Type | Method and Description |
---|---|
CodePointTrie |
buildImmutable(CodePointTrie.Type type,
CodePointTrie.ValueWidth valueWidth)
Compacts the data and builds an immutable
CodePointTrie according to the parameters. |
MutableCodePointTrie |
clone()
Clones this mutable trie.
|
static MutableCodePointTrie |
fromCodePointMap(CodePointMap map)
Creates a mutable trie with the same contents as the
CodePointMap . |
int |
get(int c)
Returns the value for a code point as stored in the map, with range checking.
|
boolean |
getRange(int start,
CodePointMap.ValueFilter filter,
CodePointMap.Range range)
Sets the range object to a range of code points beginning with the start parameter.
|
void |
set(int c,
int value)
Sets a value for a code point.
|
void |
setRange(int start,
int end,
int value)
Sets a value for each code point [start..end].
|
getRange, iterator, stringIterator
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public MutableCodePointTrie(int initialValue, int errorValue)
buildImmutable(com.ibm.icu.util.CodePointTrie.Type, com.ibm.icu.util.CodePointTrie.ValueWidth)
is called.
buildImmutable() takes a valueWidth parameter which
determines the number of bits in the data value in the resulting CodePointTrie
.initialValue
- the initial value that is set for all code pointserrorValue
- the value for out-of-range code points and ill-formed UTF-8/16public MutableCodePointTrie clone()
public static MutableCodePointTrie fromCodePointMap(CodePointMap map)
CodePointMap
.map
- the source map or triepublic int get(int c)
get
in class CodePointMap
c
- the code pointpublic boolean getRange(int start, CodePointMap.ValueFilter filter, CodePointMap.Range range)
If the CodePointMap.ValueFilter
parameter is not null, then
the value to be delivered is passed through that filter, and the return value is the end
of the range where all values are modified to the same actual value.
The value is unchanged if that parameter is null.
Example:
int start = 0; CodePointMap.Range range = new CodePointMap.Range(); while (map.getRange(start, null, range)) { int end = range.getEnd(); int value = range.getValue(); // Work with the range start..end and its value. start = end + 1; }
The trie can be modified between calls to this function.
getRange
in class CodePointMap
start
- range startfilter
- an object that may modify the map data value,
or null if the values from the map are to be used unmodifiedrange
- the range object that will be set to the code point range and valuepublic void set(int c, int value)
c
- the code pointvalue
- the valuepublic void setRange(int start, int end, int value)
start
- the first code point to get the valueend
- the last code point to get the value (inclusive)value
- the valuepublic CodePointTrie buildImmutable(CodePointTrie.Type type, CodePointTrie.ValueWidth valueWidth)
CodePointTrie
according to the parameters.
After this, the mutable trie will be empty.
The mutable trie stores 32-bit values until buildImmutable() is called. If values shorter than 32 bits are to be stored in the immutable trie, then the upper bits are discarded. For example, when the mutable trie contains values 0x81, -0x7f, and 0xa581, and the value width is 8 bits, then each of these is stored as 0x81 and the immutable trie will return that as an unsigned value. (Some implementations may want to make productive temporary use of the upper bits until buildImmutable() discards them.)
Not every possible set of mappings can be built into a CodePointTrie, because of limitations resulting from speed and space optimizations. Every Unicode assigned character can be mapped to a unique value. Typical data yields data structures far smaller than the limitations.
It is possible to construct extremely unusual mappings that exceed the data structure limits. In such a case this function will throw an exception.
type
- selects the trie typevalueWidth
- selects the number of bits in a trie data value; if smaller than 32 bits,
then the values stored in the trie will be truncated firstfromCodePointMap(CodePointMap)
Copyright © 2016 Unicode, Inc. and others.