Home | History | Annotate | Download | only in common

Lines Matching defs:trie

16 *   This is a common implementation of a Unicode trie.
19 * This is the second common version of a Unicode trie (hence the name UTrie2).
41 get32(const UNewTrie2 *trie, UChar32 c, UBool fromLSCP) {
44 if(c>=trie->highStart && (!U_IS_LEAD(c) || fromLSCP)) {
45 return trie->data[trie->dataLength-UTRIE2_DATA_GRANULARITY];
52 i2=trie->index1[c>>UTRIE2_SHIFT_1]+
55 block=trie->index2[i2];
56 return trie->data[block+(c&UTRIE2_DATA_MASK)];
60 utrie2_get32(const UTrie2 *trie, UChar32 c) {
61 if(trie->data16!=NULL) {
62 return UTRIE2_GET16(trie, c);
63 } else if(trie->data32!=NULL) {
64 return UTRIE2_GET32(trie, c);
66 return trie->errorValue;
68 return get32(trie->newTrie, c, TRUE);
73 utrie2_get32FromLeadSurrogateCodeUnit(const UTrie2 *trie, UChar32 c) {
75 return trie->errorValue;
77 if(trie->data16!=NULL) {
78 return UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie, c);
79 } else if(trie->data32!=NULL) {
80 return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
82 return get32(trie->newTrie, c, FALSE);
87 u8Index(const UTrie2 *trie, UChar32 c, int32_t i) {
90 trie,
91 trie->data32==NULL ? trie->indexLength : 0,
97 utrie2_internalU8NextIndex(const UTrie2 *trie, UChar32 c,
108 return u8Index(trie, c, i);
112 utrie2_internalU8PrevIndex(const UTrie2 *trie, UChar32 c,
124 return u8Index(trie, c, i);
136 UTrie2 *trie;
149 /* enough data for a trie header? */
193 /* allocate the trie */
194 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
195 if(trie==NULL) {
199 uprv_memcpy(trie, &tempTrie, sizeof(tempTrie));
200 trie->memory=(uint32_t *)data;
201 trie->length=actualLength;
202 trie->isMemoryOwned=FALSE;
206 trie->index=p16;
207 p16+=trie->indexLength;
212 trie->data16=p16;
213 trie->data32=NULL;
214 trie->initialValue=trie->index[trie->dataNullOffset];
215 trie->errorValue=trie->data16[UTRIE2_BAD_UTF8_DATA_OFFSET];
218 trie->data16=NULL;
219 trie->data32=(const uint32_t *)p16;
220 trie->initialValue=trie->data32[trie->dataNullOffset];
221 trie->errorValue=trie->data32[UTRIE2_BAD_UTF8_DATA_OFFSET];
231 return trie;
238 UTrie2 *trie;
254 /* calculate the total length of the dummy trie data */
264 /* allocate the trie */
265 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
266 if(trie==NULL) {
270 uprv_memset(trie, 0, sizeof(UTrie2));
271 trie->memory=uprv_malloc(length);
272 if(trie->memory==NULL) {
273 uprv_free(trie);
277 trie->length=length;
278 trie->isMemoryOwned=TRUE;
287 trie->indexLength=indexLength;
288 trie->dataLength=dataLength;
289 trie->index2NullOffset=UTRIE2_INDEX_2_OFFSET;
290 trie->dataNullOffset=(uint16_t)dataMove;
291 trie->initialValue=initialValue;
292 trie->errorValue=errorValue;
293 trie->highStart=0;
294 trie->highValueIndex=dataMove+UTRIE2_DATA_START_OFFSET;
297 header=(UTrie2Header *)trie->memory;
310 trie->index=dest16;
329 trie->data16=dest16;
330 trie->data32=NULL;
345 trie->data16=NULL;
346 trie->data32=p;
363 return trie;
367 utrie2_close(UTrie2 *trie) {
368 if(trie!=NULL) {
369 if(trie->isMemoryOwned) {
370 uprv_free(trie->memory);
372 if(trie->newTrie!=NULL) {
373 uprv_free(trie->newTrie->data);
374 uprv_free(trie->newTrie);
376 uprv_free(trie);
407 UTrie2Header trie;
426 trie.signature=ds->readUInt32(inTrie->signature);
427 trie.options=ds->readUInt16(inTrie->options);
428 trie.indexLength=ds->readUInt16(inTrie->indexLength);
429 trie.shiftedDataLength=ds->readUInt16(inTrie->shiftedDataLength);
431 valueBits=(UTrie2ValueBits)(trie.options&UTRIE2_OPTIONS_VALUE_BITS_MASK);
432 dataLength=(int32_t)trie.shiftedDataLength<<UTRIE2_INDEX_SHIFT;
434 if( trie.signature!=UTRIE2_SIG ||
436 trie.indexLength<UTRIE2_INDEX_1_OFFSET ||
443 size=sizeof(UTrie2Header)+trie.indexLength*2;
473 ds->swapArray16(ds, inTrie+1, (trie.indexLength+dataLength)*2, outTrie+1, pErrorCode);
476 ds->swapArray16(ds, inTrie+1, trie.indexLength*2, outTrie+1, pErrorCode);
477 ds->swapArray32(ds, (const uint16_t *)(inTrie+1)+trie.indexLength, dataLength*4,
478 (uint16_t *)(outTrie+1)+trie.indexLength, pErrorCode);
504 * The values are transformed from the raw trie entries by the enumValue function.
516 enumEitherTrie(const UTrie2 *trie,
533 if(trie->newTrie==NULL) {
534 /* frozen trie */
535 idx=trie->index;
536 U_ASSERT(idx!=NULL); /* the following code assumes trie->newTrie is not NULL when idx is NULL */
537 data32=trie->data32;
539 index2NullOffset=trie->index2NullOffset;
540 nullBlock=trie->dataNullOffset;
542 /* unfrozen, mutable trie */
544 trie->newTrie->data;
547 index2NullOffset=trie->newTrie->index2NullOffset;
548 nullBlock=trie->newTrie->dataNullOffset;
551 highStart=trie->highStart;
553 /* get the enumeration value that corresponds to an initial-value trie data entry */
554 initialValue=enumValue(context, trie->initialValue);
593 i2Block=trie->newTrie->index1[c>>UTRIE2_SHIFT_1];
630 block=trie->newTrie->index2[i2Block+i2];
673 data32[trie->highValueIndex] :
674 idx[trie->highValueIndex];
676 highValue=trie->newTrie->data[trie->newTrie->dataLength-UTRIE2_DATA_GRANULARITY];
694 utrie2_enum(const UTrie2 *trie,
696 enumEitherTrie(trie, 0, 0x110000, enumValue, enumRange, context);
700 utrie2_enumForLeadSurrogate(const UTrie2 *trie, UChar32 lead,
707 enumEitherTrie(trie, lead, lead+0x400, enumValue, enumRange, context);
721 UTRIE2_U16_PREV16(trie, start, codePointStart, codePoint, result);
732 UTRIE2_U16_NEXT16(trie, codePointLimit, limit, codePoint, result);