~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/common/ucmp8.h

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 ********************************************************************
 
3
 * COPYRIGHT: 
 
4
 * Copyright (c) 1996-2001, International Business Machines Corporation and
 
5
 * others. All Rights Reserved.
 
6
 ********************************************************************
 
7
 */
 
8
 
 
9
 
 
10
 
 
11
#ifndef UCMP8_H
 
12
#define UCMP8_H
 
13
 
 
14
/* 32-bits.
 
15
  Bump this whenever the internal structure changes.
 
16
*/
 
17
#define ICU_UCMP8_VERSION 0x01260000
 
18
 
 
19
#include "umemstrm.h"
 
20
#include "unicode/utypes.h"
 
21
 
 
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
 *====================================
 
28
 */
 
29
 
 
30
U_CAPI int32_t U_EXPORT2 ucmp8_getkUnicodeCount(void);
 
31
U_CAPI int32_t U_EXPORT2 ucmp8_getkBlockCount(void);
 
32
 
 
33
typedef struct CompactByteArray {
 
34
  uint32_t fStructSize;
 
35
  int8_t* fArray;
 
36
  uint16_t* fIndex;
 
37
  int32_t fCount;
 
38
  UBool fCompact;
 
39
  UBool fBogus;
 
40
  UBool fAlias;
 
41
  UBool fIAmOwned; /* don't free CBA on close */
 
42
} CompactByteArray;
 
43
 
 
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)
 
50
 
 
51
 
 
52
/**
 
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
 
55
 * leak.
 
56
 *
 
57
 * @param defaultValue the default value for all characters not explicitly in the array
 
58
 * @see ucmp8_init
 
59
 * @see ucmp8_initBogus
 
60
 * @return The initialized array.
 
61
 */
 
62
U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_open(int8_t defaultValue);
 
63
 
 
64
/**
 
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.
 
71
 *
 
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
 
75
 * @see compact
 
76
 */
 
77
U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_openAdopt(uint16_t* indexArray, 
 
78
                               int8_t* newValues,
 
79
                               int32_t count);
 
80
 
 
81
/**
 
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.
 
87
 *
 
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
 * @see compact
 
92
 */
 
93
U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_openAlias(uint16_t* indexArray, 
 
94
                               int8_t* newValues,
 
95
                               int32_t count);
 
96
 
 
97
 
 
98
/**
 
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
 
101
 * leak.
 
102
 *
 
103
 * @param defaultValue the default value for all characters not explicitly in the array
 
104
 * @param array An uninitialized CompactByteArray
 
105
 * @see ucmp8_open
 
106
 */
 
107
U_CAPI  void U_EXPORT2 ucmp8_init(CompactByteArray* array, int8_t defaultValue);
 
108
 
 
109
/**
 
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
 
112
 * a memory leak.
 
113
 *
 
114
 * @param array An uninitialized CompactByteArray
 
115
 * @see ucmp8_open
 
116
 * @see ucmp8_isBogus
 
117
 */
 
118
U_CAPI  void U_EXPORT2 ucmp8_initBogus(CompactByteArray* array);
 
119
 
 
120
/**
 
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.
 
127
 *
 
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
 
131
 * @see compact
 
132
 */
 
133
U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_initAdopt(CompactByteArray *this_obj,
 
134
                               uint16_t* indexArray, 
 
135
                               int8_t* newValues,
 
136
                               int32_t count);
 
137
 
 
138
/**
 
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.
 
144
 *
 
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
 
148
 * @see compact
 
149
 */
 
150
U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_initAlias(CompactByteArray *this_obj,
 
151
                               uint16_t* indexArray, 
 
152
                               int8_t* newValues,
 
153
                               int32_t count);
 
154
 
 
155
/**
 
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
 
158
 * or opened.
 
159
 * 
 
160
 * @param array The compact array to close
 
161
 */
 
162
U_CAPI  void U_EXPORT2 ucmp8_close(CompactByteArray* array);
 
163
 
 
164
/**
 
165
 * Returns TRUE if the creation of the compact array fails.
 
166
 */
 
167
U_CAPI  UBool U_EXPORT2 ucmp8_isBogus(const CompactByteArray* array);
 
168
 
 
169
/**
 
170
 * Get the mapped value of a Unicode character.
 
171
 *
 
172
 * @param index the character to get the mapped value with
 
173
 * @return the mapped value of the given character
 
174
 */
 
175
#define ucmp8_get(array, index)  (array->fArray[(array->fIndex[index >> UCMP8_kBlockShift] & 0xFFFF) + (index & UCMP8_kBlockMask)])
 
176
 
 
177
#define ucmp8_getu(array,index) (uint8_t)ucmp8_get(array,index)
 
178
 
 
179
 
 
180
/**
 
181
 * Set a new value for a Unicode character.
 
182
 * Set automatically expands the array if it is compacted.
 
183
 *
 
184
 * @param character the character to set the mapped value with
 
185
 * @param value the new mapped value
 
186
 */
 
187
U_CAPI  void U_EXPORT2 ucmp8_set(CompactByteArray* array,
 
188
                 UChar character,
 
189
                 int8_t value);
 
190
 
 
191
/**
 
192
 * Set new values for a range of Unicode character.
 
193
 *
 
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
 
197
 */
 
198
U_CAPI  void U_EXPORT2 ucmp8_setRange(CompactByteArray* array, 
 
199
                  UChar start,
 
200
                  UChar end, 
 
201
                  int8_t value);
 
202
 
 
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);
 
206
 
 
207
/**
 
208
 * Compact the 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
 
213
 * same compression.
 
214
 */
 
215
U_CAPI  void U_EXPORT2 ucmp8_compact(CompactByteArray* array, 
 
216
                 uint32_t cycle);
 
217
 
 
218
/** Expanded takes the array back to a 65536 element array*/
 
219
U_CAPI  void U_EXPORT2 ucmp8_expand(CompactByteArray* array);
 
220
 
 
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);
 
225
 
 
226
#endif
 
227