2
********************************************************************
4
* Copyright (c) 1996-2001, 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
20
#include "unicode/utypes.h"
22
/*====================================
23
* class CompactByteArray
24
* Provides a compact way to store information that is indexed by Unicode values,
25
* such as character properties, types, keyboard values, etc.
26
* The ATypes are used by value, so should be small, integers or pointers.
27
*====================================
30
U_CAPI int32_t U_EXPORT2 ucmp8_getkUnicodeCount(void);
31
U_CAPI int32_t U_EXPORT2 ucmp8_getkBlockCount(void);
33
typedef struct CompactByteArray {
41
UBool fIAmOwned; /* don't free CBA on close */
44
#define UCMP8_kUnicodeCount 65536
45
#define UCMP8_kBlockShift 7
46
#define UCMP8_kBlockCount (1<<UCMP8_kBlockShift)
47
#define UCMP8_kIndexShift (16-UCMP8_kBlockShift)
48
#define UCMP8_kIndexCount (1<<UCMP8_kIndexShift)
49
#define UCMP8_kBlockMask (UCMP8_kBlockCount-1)
53
* Construct an empty CompactByteArray with uprv_malloc(). Do not call any of the
54
* ucmp8_init*() functions after using this function. They will cause a memory
57
* @param defaultValue the default value for all characters not explicitly in the array
59
* @see ucmp8_initBogus
60
* @return The initialized array.
62
U_CAPI CompactByteArray* U_EXPORT2 ucmp8_open(int8_t defaultValue);
65
* Construct a CompactByteArray from a pre-computed index and values array. The values
66
* will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
67
* Note: for speed, the compact method will only re-use blocks in the values array
68
* that are on a block boundary. The pre-computed arrays passed in to this constructor
69
* may re-use blocks at any position in the values array. The indexArray and newValues
70
* will be uprv_free'd when ucmp16_close() is called.
72
* @param indexArray the index array to be adopted
73
* @param newValues the value array to be adopted
74
* @param count the number of entries in the value array
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
93
U_CAPI CompactByteArray* U_EXPORT2 ucmp8_openAlias(uint16_t* indexArray,
99
* Initialize an empty CompactByteArray. Do not call this function
100
* if you created the array with ucmp8_open() because it will cause a memory
103
* @param defaultValue the default value for all characters not explicitly in the array
104
* @param array An uninitialized CompactByteArray
107
U_CAPI void U_EXPORT2 ucmp8_init(CompactByteArray* array, int8_t defaultValue);
110
* Initialize an empty CompactByteArray to the bogus value. Do not call this
111
* function if you created the array with ucmp8_open() because it will cause
114
* @param array An uninitialized CompactByteArray
118
U_CAPI void U_EXPORT2 ucmp8_initBogus(CompactByteArray* array);
121
* Initialize a CompactByteArray from a pre-computed index and values array. The values
122
* will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
123
* Note: for speed, the compact method will only re-use blocks in the values array
124
* that are on a block boundary. The pre-computed arrays passed in to this constructor
125
* may re-use blocks at any position in the values array. The indexArray and newValues
126
* will be uprv_free'd when ucmp16_close() is called.
128
* @param indexArray the index array to be adopted
129
* @param newValues the value array to be adopted
130
* @param count the number of entries in the value array
133
U_CAPI CompactByteArray* U_EXPORT2 ucmp8_initAdopt(CompactByteArray *this_obj,
134
uint16_t* indexArray,
139
* Initialize a CompactByteArray from a pre-computed index and values array. The values
140
* will be aliased by the CompactByteArray. Memory is allocated with uprv_malloc.
141
* Note: for speed, the compact method will only re-use blocks in the values array
142
* that are on a block boundary. The pre-computed arrays passed in to this constructor
143
* may re-use blocks at any position in the values array.
145
* @param indexArray the index array to be adopted
146
* @param newValues the value array to be adopted
147
* @param count the number of entries in the value array
150
U_CAPI CompactByteArray* U_EXPORT2 ucmp8_initAlias(CompactByteArray *this_obj,
151
uint16_t* indexArray,
156
* Free up any allocated memory associated with this compact array.
157
* The memory that is uprv_free'd depends on how the array was initialized
160
* @param array The compact array to close
162
U_CAPI void U_EXPORT2 ucmp8_close(CompactByteArray* array);
165
* Returns TRUE if the creation of the compact array fails.
167
U_CAPI UBool U_EXPORT2 ucmp8_isBogus(const CompactByteArray* array);
170
* Get the mapped value of a Unicode character.
172
* @param index the character to get the mapped value with
173
* @return the mapped value of the given character
175
#define ucmp8_get(array, index) (array->fArray[(array->fIndex[index >> UCMP8_kBlockShift] & 0xFFFF) + (index & UCMP8_kBlockMask)])
177
#define ucmp8_getu(array,index) (uint8_t)ucmp8_get(array,index)
181
* Set a new value for a Unicode character.
182
* Set automatically expands the array if it is compacted.
184
* @param character the character to set the mapped value with
185
* @param value the new mapped value
187
U_CAPI void U_EXPORT2 ucmp8_set(CompactByteArray* array,
192
* Set new values for a range of Unicode character.
194
* @param start the starting offset of the range
195
* @param end the ending offset of the range
196
* @param value the new mapped value
198
U_CAPI void U_EXPORT2 ucmp8_setRange(CompactByteArray* array,
203
U_CAPI int32_t U_EXPORT2 ucmp8_getCount(const CompactByteArray* array);
204
U_CAPI const int8_t* U_EXPORT2 ucmp8_getArray(const CompactByteArray* array);
205
U_CAPI const uint16_t* U_EXPORT2 ucmp8_getIndex(const CompactByteArray* array);
209
* The value of cycle determines how large the overlap can be.
210
* A cycle of 1 is the most compacted, but takes the most time to do.
211
* If values stored in the array tend to repeat in cycles of, say, 16,
212
* then using that will be faster than cycle = 1, and get almost the
215
U_CAPI void U_EXPORT2 ucmp8_compact(CompactByteArray* array,
218
/** Expanded takes the array back to a 65536 element array*/
219
U_CAPI void U_EXPORT2 ucmp8_expand(CompactByteArray* array);
221
/** (more) INTERNAL USE ONLY **/
222
U_CAPI uint32_t U_EXPORT2 ucmp8_flattenMem (const CompactByteArray* array, UMemoryStream *MS);
223
/* initializes an existing CBA from memory. Will cause ucmp8_close() to not deallocate anything. */
224
U_CAPI void U_EXPORT2 ucmp8_initFromData(CompactByteArray* array, const uint8_t **source, UErrorCode *status);