|
||||
Warning, file /include/unicode/umutablecptrie.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2017 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 0004 // umutablecptrie.h (split out of ucptrie.h) 0005 // created: 2018jan24 Markus W. Scherer 0006 0007 #ifndef __UMUTABLECPTRIE_H__ 0008 #define __UMUTABLECPTRIE_H__ 0009 0010 #include "unicode/utypes.h" 0011 0012 #include "unicode/ucpmap.h" 0013 #include "unicode/ucptrie.h" 0014 #include "unicode/utf8.h" 0015 0016 #if U_SHOW_CPLUSPLUS_API 0017 #include "unicode/localpointer.h" 0018 #endif // U_SHOW_CPLUSPLUS_API 0019 0020 U_CDECL_BEGIN 0021 0022 /** 0023 * \file 0024 * \brief C API: This file defines a mutable Unicode code point trie. 0025 * 0026 * @see UCPTrie 0027 * @see UMutableCPTrie 0028 */ 0029 0030 /** 0031 * Mutable Unicode code point trie. 0032 * Fast map from Unicode code points (U+0000..U+10FFFF) to 32-bit integer values. 0033 * For details see https://icu.unicode.org/design/struct/utrie 0034 * 0035 * Setting values (especially ranges) and lookup is fast. 0036 * The mutable trie is only somewhat space-efficient. 0037 * It builds a compacted, immutable UCPTrie. 0038 * 0039 * This trie can be modified while iterating over its contents. 0040 * For example, it is possible to merge its values with those from another 0041 * set of ranges (e.g., another mutable or immutable trie): 0042 * Iterate over those source ranges; for each of them iterate over this trie; 0043 * add the source value into the value of each trie range. 0044 * 0045 * @see UCPTrie 0046 * @see umutablecptrie_buildImmutable 0047 * @stable ICU 63 0048 */ 0049 typedef struct UMutableCPTrie UMutableCPTrie; 0050 0051 /** 0052 * Creates a mutable trie that initially maps each Unicode code point to the same value. 0053 * It uses 32-bit data values until umutablecptrie_buildImmutable() is called. 0054 * umutablecptrie_buildImmutable() takes a valueWidth parameter which 0055 * determines the number of bits in the data value in the resulting UCPTrie. 0056 * You must umutablecptrie_close() the trie once you are done using it. 0057 * 0058 * @param initialValue the initial value that is set for all code points 0059 * @param errorValue the value for out-of-range code points and ill-formed UTF-8/16 0060 * @param pErrorCode an in/out ICU UErrorCode 0061 * @return the trie 0062 * @stable ICU 63 0063 */ 0064 U_CAPI UMutableCPTrie * U_EXPORT2 0065 umutablecptrie_open(uint32_t initialValue, uint32_t errorValue, UErrorCode *pErrorCode); 0066 0067 /** 0068 * Clones a mutable trie. 0069 * You must umutablecptrie_close() the clone once you are done using it. 0070 * 0071 * @param other the trie to clone 0072 * @param pErrorCode an in/out ICU UErrorCode 0073 * @return the trie clone 0074 * @stable ICU 63 0075 */ 0076 U_CAPI UMutableCPTrie * U_EXPORT2 0077 umutablecptrie_clone(const UMutableCPTrie *other, UErrorCode *pErrorCode); 0078 0079 /** 0080 * Closes a mutable trie and releases associated memory. 0081 * 0082 * @param trie the trie 0083 * @stable ICU 63 0084 */ 0085 U_CAPI void U_EXPORT2 0086 umutablecptrie_close(UMutableCPTrie *trie); 0087 0088 /** 0089 * Creates a mutable trie with the same contents as the UCPMap. 0090 * You must umutablecptrie_close() the mutable trie once you are done using it. 0091 * 0092 * @param map the source map 0093 * @param pErrorCode an in/out ICU UErrorCode 0094 * @return the mutable trie 0095 * @stable ICU 63 0096 */ 0097 U_CAPI UMutableCPTrie * U_EXPORT2 0098 umutablecptrie_fromUCPMap(const UCPMap *map, UErrorCode *pErrorCode); 0099 0100 /** 0101 * Creates a mutable trie with the same contents as the immutable one. 0102 * You must umutablecptrie_close() the mutable trie once you are done using it. 0103 * 0104 * @param trie the immutable trie 0105 * @param pErrorCode an in/out ICU UErrorCode 0106 * @return the mutable trie 0107 * @stable ICU 63 0108 */ 0109 U_CAPI UMutableCPTrie * U_EXPORT2 0110 umutablecptrie_fromUCPTrie(const UCPTrie *trie, UErrorCode *pErrorCode); 0111 0112 /** 0113 * Returns the value for a code point as stored in the trie. 0114 * 0115 * @param trie the trie 0116 * @param c the code point 0117 * @return the value 0118 * @stable ICU 63 0119 */ 0120 U_CAPI uint32_t U_EXPORT2 0121 umutablecptrie_get(const UMutableCPTrie *trie, UChar32 c); 0122 0123 /** 0124 * Returns the last code point such that all those from start to there have the same value. 0125 * Can be used to efficiently iterate over all same-value ranges in a trie. 0126 * (This is normally faster than iterating over code points and get()ting each value, 0127 * but much slower than a data structure that stores ranges directly.) 0128 * 0129 * The trie can be modified between calls to this function. 0130 * 0131 * If the UCPMapValueFilter function pointer is not NULL, then 0132 * the value to be delivered is passed through that function, and the return value is the end 0133 * of the range where all values are modified to the same actual value. 0134 * The value is unchanged if that function pointer is NULL. 0135 * 0136 * See the same-signature ucptrie_getRange() for a code sample. 0137 * 0138 * @param trie the trie 0139 * @param start range start 0140 * @param option defines whether surrogates are treated normally, 0141 * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL 0142 * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL 0143 * @param filter a pointer to a function that may modify the trie data value, 0144 * or NULL if the values from the trie are to be used unmodified 0145 * @param context an opaque pointer that is passed on to the filter function 0146 * @param pValue if not NULL, receives the value that every code point start..end has; 0147 * may have been modified by filter(context, trie value) 0148 * if that function pointer is not NULL 0149 * @return the range end code point, or -1 if start is not a valid code point 0150 * @stable ICU 63 0151 */ 0152 U_CAPI UChar32 U_EXPORT2 0153 umutablecptrie_getRange(const UMutableCPTrie *trie, UChar32 start, 0154 UCPMapRangeOption option, uint32_t surrogateValue, 0155 UCPMapValueFilter *filter, const void *context, uint32_t *pValue); 0156 0157 /** 0158 * Sets a value for a code point. 0159 * 0160 * @param trie the trie 0161 * @param c the code point 0162 * @param value the value 0163 * @param pErrorCode an in/out ICU UErrorCode 0164 * @stable ICU 63 0165 */ 0166 U_CAPI void U_EXPORT2 0167 umutablecptrie_set(UMutableCPTrie *trie, UChar32 c, uint32_t value, UErrorCode *pErrorCode); 0168 0169 /** 0170 * Sets a value for each code point [start..end]. 0171 * Faster and more space-efficient than setting the value for each code point separately. 0172 * 0173 * @param trie the trie 0174 * @param start the first code point to get the value 0175 * @param end the last code point to get the value (inclusive) 0176 * @param value the value 0177 * @param pErrorCode an in/out ICU UErrorCode 0178 * @stable ICU 63 0179 */ 0180 U_CAPI void U_EXPORT2 0181 umutablecptrie_setRange(UMutableCPTrie *trie, 0182 UChar32 start, UChar32 end, 0183 uint32_t value, UErrorCode *pErrorCode); 0184 0185 /** 0186 * Compacts the data and builds an immutable UCPTrie according to the parameters. 0187 * After this, the mutable trie will be empty. 0188 * 0189 * The mutable trie stores 32-bit values until buildImmutable() is called. 0190 * If values shorter than 32 bits are to be stored in the immutable trie, 0191 * then the upper bits are discarded. 0192 * For example, when the mutable trie contains values 0x81, -0x7f, and 0xa581, 0193 * and the value width is 8 bits, then each of these is stored as 0x81 0194 * and the immutable trie will return that as an unsigned value. 0195 * (Some implementations may want to make productive temporary use of the upper bits 0196 * until buildImmutable() discards them.) 0197 * 0198 * Not every possible set of mappings can be built into a UCPTrie, 0199 * because of limitations resulting from speed and space optimizations. 0200 * Every Unicode assigned character can be mapped to a unique value. 0201 * Typical data yields data structures far smaller than the limitations. 0202 * 0203 * It is possible to construct extremely unusual mappings that exceed the data structure limits. 0204 * In such a case this function will fail with a U_INDEX_OUTOFBOUNDS_ERROR. 0205 * 0206 * @param trie the trie trie 0207 * @param type selects the trie type 0208 * @param valueWidth selects the number of bits in a trie data value; if smaller than 32 bits, 0209 * then the values stored in the trie will be truncated first 0210 * @param pErrorCode an in/out ICU UErrorCode 0211 * 0212 * @see umutablecptrie_fromUCPTrie 0213 * @stable ICU 63 0214 */ 0215 U_CAPI UCPTrie * U_EXPORT2 0216 umutablecptrie_buildImmutable(UMutableCPTrie *trie, UCPTrieType type, UCPTrieValueWidth valueWidth, 0217 UErrorCode *pErrorCode); 0218 0219 U_CDECL_END 0220 0221 #if U_SHOW_CPLUSPLUS_API 0222 0223 U_NAMESPACE_BEGIN 0224 0225 /** 0226 * \class LocalUMutableCPTriePointer 0227 * "Smart pointer" class, closes a UMutableCPTrie via umutablecptrie_close(). 0228 * For most methods see the LocalPointerBase base class. 0229 * 0230 * @see LocalPointerBase 0231 * @see LocalPointer 0232 * @stable ICU 63 0233 */ 0234 U_DEFINE_LOCAL_OPEN_POINTER(LocalUMutableCPTriePointer, UMutableCPTrie, umutablecptrie_close); 0235 0236 U_NAMESPACE_END 0237 0238 #endif 0239 0240 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |