Class MutableCodePointTrie
- All Implemented Interfaces:
Cloneable
,Iterable<CodePointMap.Range>
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.ibm.icu.util.CodePointMap
CodePointMap.Range, CodePointMap.RangeOption, CodePointMap.StringIterator, CodePointMap.ValueFilter
-
Constructor Summary
ConstructorsConstructorDescriptionMutableCodePointTrie
(int initialValue, int errorValue) Constructs a mutable trie that initially maps each Unicode code point to the same value. -
Method Summary
Modifier and TypeMethodDescriptionbuildImmutable
(CodePointTrie.Type type, CodePointTrie.ValueWidth valueWidth) Compacts the data and builds an immutableCodePointTrie
according to the parameters.clone()
Clones this mutable trie.static MutableCodePointTrie
Creates a mutable trie with the same contents as theCodePointMap
.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].Methods inherited from class com.ibm.icu.util.CodePointMap
getRange, iterator, stringIterator
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MutableCodePointTrie
public MutableCodePointTrie(int initialValue, int errorValue) Constructs a mutable trie that initially maps each Unicode code point to the same value. It uses 32-bit data values untilbuildImmutable(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 resultingCodePointTrie
.- Parameters:
initialValue
- the initial value that is set for all code pointserrorValue
- the value for out-of-range code points and ill-formed UTF-8/16
-
-
Method Details
-
clone
Clones this mutable trie. -
fromCodePointMap
Creates a mutable trie with the same contents as theCodePointMap
.- Parameters:
map
- the source map or trie- Returns:
- the mutable trie
-
get
public int get(int c) Returns the value for a code point as stored in the map, with range checking. Returns an implementation-defined error value if c is not in the range 0..U+10FFFF.- Specified by:
get
in classCodePointMap
- Parameters:
c
- the code point- Returns:
- the map value, or an implementation-defined error value if the code point is not in the range 0..U+10FFFF
-
getRange
Sets the range object to a range of code points beginning with the start parameter. The range start is the same as the start input parameter (even if there are preceding code points that have the same value). The range end is the last code point such that all those from start to there have the same value. Returns false if start is not 0..U+10FFFF. Can be used to efficiently iterate over all same-value ranges in a map. (This is normally faster than iterating over code points and get()ting each value, but may be much slower than a data structure that stores ranges directly.)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.
- Specified by:
getRange
in classCodePointMap
- Parameters:
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 value- Returns:
- true if start is 0..U+10FFFF; otherwise no new range is fetched
-
set
public void set(int c, int value) Sets a value for a code point.- Parameters:
c
- the code pointvalue
- the value
-
setRange
public void setRange(int start, int end, int value) Sets a value for each code point [start..end]. Faster and more space-efficient than setting the value for each code point separately.- Parameters:
start
- the first code point to get the valueend
- the last code point to get the value (inclusive)value
- the value
-
buildImmutable
Compacts the data and builds an immutableCodePointTrie
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.
- Parameters:
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 first- See Also:
-