Home | History | Annotate | Download | only in common

Lines Matching refs:trie

18 *   This is a common implementation of a Unicode trie.
21 * This is the second common version of a Unicode trie (hence the name UTrie2).
43 get32(const UNewTrie2 *trie, UChar32 c, UBool fromLSCP) {
46 if(c>=trie->highStart && (!U_IS_LEAD(c) || fromLSCP)) {
47 return trie->data[trie->dataLength-UTRIE2_DATA_GRANULARITY];
54 i2=trie->index1[c>>UTRIE2_SHIFT_1]+
57 block=trie->index2[i2];
58 return trie->data[block+(c&UTRIE2_DATA_MASK)];
62 utrie2_get32(const UTrie2 *trie, UChar32 c) {
63 if(trie->data16!=NULL) {
64 return UTRIE2_GET16(trie, c);
65 } else if(trie->data32!=NULL) {
66 return UTRIE2_GET32(trie, c);
68 return trie->errorValue;
70 return get32(trie->newTrie, c, TRUE);
75 utrie2_get32FromLeadSurrogateCodeUnit(const UTrie2 *trie, UChar32 c) {
77 return trie->errorValue;
79 if(trie->data16!=NULL) {
80 return UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie, c);
81 } else if(trie->data32!=NULL) {
82 return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
84 return get32(trie->newTrie, c, FALSE);
89 u8Index(const UTrie2 *trie, UChar32 c, int32_t i) {
92 trie,
93 trie->data32==NULL ? trie->indexLength : 0,
99 utrie2_internalU8NextIndex(const UTrie2 *trie, UChar32 c,
110 return u8Index(trie, c, i);
114 utrie2_internalU8PrevIndex(const UTrie2 *trie, UChar32 c,
126 return u8Index(trie, c, i);
138 UTrie2 *trie;
151 /* enough data for a trie header? */
195 /* allocate the trie */
196 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
197 if(trie==NULL) {
201 uprv_memcpy(trie, &tempTrie, sizeof(tempTrie));
202 trie->memory=(uint32_t *)data;
203 trie->length=actualLength;
204 trie->isMemoryOwned=FALSE;
208 trie->index=p16;
209 p16+=trie->indexLength;
214 trie->data16=p16;
215 trie->data32=NULL;
216 trie->initialValue=trie->index[trie->dataNullOffset];
217 trie->errorValue=trie->data16[UTRIE2_BAD_UTF8_DATA_OFFSET];
220 trie->data16=NULL;
221 trie->data32=(const uint32_t *)p16;
222 trie->initialValue=trie->data32[trie->dataNullOffset];
223 trie->errorValue=trie->data32[UTRIE2_BAD_UTF8_DATA_OFFSET];
233 return trie;
240 UTrie2 *trie;
256 /* calculate the total length of the dummy trie data */
266 /* allocate the trie */
267 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
268 if(trie==NULL) {
272 uprv_memset(trie, 0, sizeof(UTrie2));
273 trie->memory=uprv_malloc(length);
274 if(trie->memory==NULL) {
275 uprv_free(trie);
279 trie->length=length;
280 trie->isMemoryOwned=TRUE;
289 trie->indexLength=indexLength;
290 trie->dataLength=dataLength;
291 trie->index2NullOffset=UTRIE2_INDEX_2_OFFSET;
292 trie->dataNullOffset=(uint16_t)dataMove;
293 trie->initialValue=initialValue;
294 trie->errorValue=errorValue;
295 trie->highStart=0;
296 trie->highValueIndex=dataMove+UTRIE2_DATA_START_OFFSET;
299 header=(UTrie2Header *)trie->memory;
312 trie->index=dest16;
331 trie->data16=dest16;
332 trie->data32=NULL;
347 trie->data16=NULL;
348 trie->data32=p;
365 return trie;
369 utrie2_close(UTrie2 *trie) {
370 if(trie!=NULL) {
371 if(trie->isMemoryOwned) {
372 uprv_free(trie->memory);
374 if(trie->newTrie!=NULL) {
375 uprv_free(trie->newTrie->data);
376 uprv_free(trie->newTrie);
378 uprv_free(trie);
405 utrie2_isFrozen(const UTrie2 *trie) {
406 return (UBool)(trie->newTrie==NULL);
410 utrie2_serialize(const UTrie2 *trie,
418 if( trie==NULL || trie->memory==NULL || trie->newTrie!=NULL ||
425 if(capacity>=trie->length) {
426 uprv_memcpy(data, trie->memory, trie->length);
430 return trie->length;
438 UTrie2Header trie;
457 trie.signature=ds->readUInt32(inTrie->signature);
458 trie.options=ds->readUInt16(inTrie->options);
459 trie.indexLength=ds->readUInt16(inTrie->indexLength);
460 trie.shiftedDataLength=ds->readUInt16(inTrie->shiftedDataLength);
462 valueBits=(UTrie2ValueBits)(trie.options&UTRIE2_OPTIONS_VALUE_BITS_MASK);
463 dataLength=(int32_t)trie.shiftedDataLength<<UTRIE2_INDEX_SHIFT;
465 if( trie.signature!=UTRIE2_SIG ||
467 trie.indexLength<UTRIE2_INDEX_1_OFFSET ||
474 size=sizeof(UTrie2Header)+trie.indexLength*2;
504 ds->swapArray16(ds, inTrie+1, (trie.indexLength+dataLength)*2, outTrie+1, pErrorCode);
507 ds->swapArray16(ds, inTrie+1, trie.indexLength*2, outTrie+1, pErrorCode);
508 ds->swapArray32(ds, (const uint16_t *)(inTrie+1)+trie.indexLength, dataLength*4,
509 (uint16_t *)(outTrie+1)+trie.indexLength, pErrorCode);
535 * The values are transformed from the raw trie entries by the enumValue function.
547 trie,
564 if(trie->newTrie==NULL) {
565 /* frozen trie */
566 idx=trie->index;
567 U_ASSERT(idx!=NULL); /* the following code assumes trie->newTrie is not NULL when idx is NULL */
568 data32=trie->data32;
570 index2NullOffset=trie->index2NullOffset;
571 nullBlock=trie->dataNullOffset;
573 /* unfrozen, mutable trie */
575 data32=trie->newTrie->data;
578 index2NullOffset=trie->newTrie->index2NullOffset;
579 nullBlock=trie->newTrie->dataNullOffset;
582 highStart=trie->highStart;
584 /* get the enumeration value that corresponds to an initial-value trie data entry */
585 initialValue=enumValue(context, trie->initialValue);
624 i2Block=trie->newTrie->index1[c>>UTRIE2_SHIFT_1];
661 block=trie->newTrie->index2[i2Block+i2];
704 data32[trie->highValueIndex] :
705 idx[trie->highValueIndex];
707 highValue=trie->newTrie->data[trie->newTrie->dataLength-UTRIE2_DATA_GRANULARITY];
725 utrie2_enum(const UTrie2 *trie,
727 enumEitherTrie(trie, 0, 0x110000, enumValue, enumRange, context);
731 utrie2_enumForLeadSurrogate(const UTrie2 *trie, UChar32 lead,
738 enumEitherTrie(trie, lead, lead+0x400, enumValue, enumRange, context);
752 UTRIE2_U16_PREV16(trie, start, codePointStart, codePoint, result);
763 UTRIE2_U16_NEXT16(trie, codePointLimit, limit, codePoint, result);