]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ucmp8.h
2 ********************************************************************
4 * Copyright (c) 1996-2004, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 ********************************************************************
15 Bump this whenever the internal structure changes.
17 #define ICU_UCMP8_VERSION 0x01260000
19 #include "unicode/utypes.h"
21 /*====================================
22 * class CompactByteArray
23 * Provides a compact way to store information that is indexed by Unicode values,
24 * such as character properties, types, keyboard values, etc.
25 * The ATypes are used by value, so should be small, integers or pointers.
26 *====================================
29 U_CAPI
int32_t U_EXPORT2
ucmp8_getkUnicodeCount(void);
30 U_CAPI
int32_t U_EXPORT2
ucmp8_getkBlockCount(void);
32 typedef struct CompactByteArray
{
40 UBool fIAmOwned
; /* don't free CBA on close */
43 #define UCMP8_kUnicodeCount 65536
44 #define UCMP8_kBlockShift 7
45 #define UCMP8_kBlockCount (1<<UCMP8_kBlockShift)
46 #define UCMP8_kIndexShift (16-UCMP8_kBlockShift)
47 #define UCMP8_kIndexCount (1<<UCMP8_kIndexShift)
48 #define UCMP8_kBlockMask (UCMP8_kBlockCount-1)
52 * Construct an empty CompactByteArray with uprv_malloc(). Do not call any of the
53 * ucmp8_init*() functions after using this function. They will cause a memory
56 * @param defaultValue the default value for all characters not explicitly in the array
58 * @see ucmp8_initBogus
59 * @return The initialized array.
61 U_CAPI CompactByteArray
* U_EXPORT2
ucmp8_open(int8_t defaultValue
);
64 * Construct a CompactByteArray from a pre-computed index and values array. The values
65 * will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
66 * Note: for speed, the compact method will only re-use blocks in the values array
67 * that are on a block boundary. The pre-computed arrays passed in to this constructor
68 * may re-use blocks at any position in the values array. The indexArray and newValues
69 * will be uprv_free'd when ucmp16_close() is called.
71 * @param indexArray the index array to be adopted
72 * @param newValues the value array to be adopted
73 * @param count the number of entries in the value array
74 * @return the newly constructed ComapctByteArray
77 U_CAPI CompactByteArray
* U_EXPORT2
ucmp8_openAdopt(uint16_t* indexArray
,
82 * Construct a CompactByteArray from a pre-computed index and values array. The values
83 * will be aliased by the CompactByteArray. Memory is allocated with uprv_malloc.
84 * Note: for speed, the compact method will only re-use blocks in the values array
85 * that are on a block boundary. The pre-computed arrays passed in to this constructor
86 * may re-use blocks at any position in the values array.
88 * @param indexArray the index array to be adopted
89 * @param newValues the value array to be adopted
90 * @param count the number of entries in the value array
91 * @return the newly constructed CompactByteArray
94 U_CAPI CompactByteArray
* U_EXPORT2
ucmp8_openAlias(uint16_t* indexArray
,
100 * Initialize an empty CompactByteArray. Do not call this function
101 * if you created the array with ucmp8_open() because it will cause a memory
104 * @param defaultValue the default value for all characters not explicitly in the array
105 * @param array An uninitialized CompactByteArray
108 U_CAPI
void U_EXPORT2
ucmp8_init(CompactByteArray
* array
, int8_t defaultValue
);
111 * Initialize an empty CompactByteArray to the bogus value. Do not call this
112 * function if you created the array with ucmp8_open() because it will cause
115 * @param array An uninitialized CompactByteArray
119 U_CAPI
void U_EXPORT2
ucmp8_initBogus(CompactByteArray
* array
);
122 * Initialize a CompactByteArray from a pre-computed index and values array. The values
123 * will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
124 * Note: for speed, the compact method will only re-use blocks in the values array
125 * that are on a block boundary. The pre-computed arrays passed in to this constructor
126 * may re-use blocks at any position in the values array. The indexArray and newValues
127 * will be uprv_free'd when ucmp16_close() is called.
129 * @param this_obj An uninitialized CompactByteArray
130 * @param indexArray the index array to be adopted
131 * @param newValues the value array to be adopted
132 * @param count the number of entries in the value array
133 * @return the pointer refers to the CompactByteArray
136 U_CAPI CompactByteArray
* U_EXPORT2
ucmp8_initAdopt(CompactByteArray
*this_obj
,
137 uint16_t* indexArray
,
142 * Initialize a CompactByteArray from a pre-computed index and values array. The values
143 * will be aliased by the CompactByteArray. Memory is allocated with uprv_malloc.
144 * Note: for speed, the compact method will only re-use blocks in the values array
145 * that are on a block boundary. The pre-computed arrays passed in to this constructor
146 * may re-use blocks at any position in the values array.
148 * @param this_obj An uninitialized CompactByteArray
149 * @param indexArray the index array to be adopted
150 * @param newValues the value array to be adopted
151 * @param count the number of entries in the value array
152 * @return the pointer refers to the CompactByteArray
155 U_CAPI CompactByteArray
* U_EXPORT2
ucmp8_initAlias(CompactByteArray
*this_obj
,
156 uint16_t* indexArray
,
161 * Free up any allocated memory associated with this compact array.
162 * The memory that is uprv_free'd depends on how the array was initialized
165 * @param array The compact array to close
167 U_CAPI
void U_EXPORT2
ucmp8_close(CompactByteArray
* array
);
170 * Returns TRUE if the creation of the compact array fails.
171 * @param array The CompactByteArray to be created.
172 * @return TRUE if the creation of the compact array fails.
174 U_CAPI UBool U_EXPORT2
ucmp8_isBogus(const CompactByteArray
* array
);
177 * Get the mapped value of a Unicode character.
179 * @param index the character to get the mapped value with
180 * @return the mapped value of the given character
182 #define ucmp8_get(array, index) (array->fArray[(array->fIndex[index >> UCMP8_kBlockShift] & 0xFFFF) + (index & UCMP8_kBlockMask)])
184 #define ucmp8_getu(array,index) (uint8_t)ucmp8_get(array,index)
188 * Set a new value for a Unicode character.
189 * Set automatically expands the array if it is compacted.
191 * @param array the CompactByteArray to be set
192 * @param character the character to set the mapped value with
193 * @param value the new mapped value
195 U_CAPI
void U_EXPORT2
ucmp8_set(CompactByteArray
* array
,
200 * Set new values for a range of Unicode character.
202 * @param array the CompactByteArray to be set
203 * @param start the starting offset of the range
204 * @param end the ending offset of the range
205 * @param value the new mapped value
207 U_CAPI
void U_EXPORT2
ucmp8_setRange(CompactByteArray
* array
,
212 U_CAPI
int32_t U_EXPORT2
ucmp8_getCount(const CompactByteArray
* array
);
213 U_CAPI
const int8_t* U_EXPORT2
ucmp8_getArray(const CompactByteArray
* array
);
214 U_CAPI
const uint16_t* U_EXPORT2
ucmp8_getIndex(const CompactByteArray
* array
);
218 * The value of cycle determines how large the overlap can be.
219 * A cycle of 1 is the most compacted, but takes the most time to do.
220 * If values stored in the array tend to repeat in cycles of, say, 16,
221 * then using that will be faster than cycle = 1, and get almost the
223 * @param array The CompactByteArray to be compacted
224 * @param cycle The value determines how large the overlap can be.
226 U_CAPI
void U_EXPORT2
ucmp8_compact(CompactByteArray
* array
,
229 /** Expanded takes the array back to a 65536 element array
230 * @param array The CompactByteArray to be expanded
232 U_CAPI
void U_EXPORT2
ucmp8_expand(CompactByteArray
* array
);
235 * Flatten into a memory structure. Pass in NULL to pre-flight to get the required size.
238 U_CAPI
uint32_t U_EXPORT2
ucmp8_flattenMem(const CompactByteArray
* array
, uint8_t *MS
);
240 /* initializes an existing CBA from memory. Will cause ucmp8_close() to not deallocate anything. */
241 U_CAPI
void U_EXPORT2
ucmp8_initFromData(CompactByteArray
* array
, const uint8_t **source
, UErrorCode
*status
);