Lines Matching full: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).
37 get32(const UNewTrie2 *trie, UChar32 c, UBool fromLSCP) {
40 if(c>=trie->highStart && (!U_IS_LEAD(c) || fromLSCP)) {
41 return trie->data[trie->dataLength-UTRIE2_DATA_GRANULARITY];
48 i2=trie->index1[c>>UTRIE2_SHIFT_1]+
51 block=trie->index2[i2];
52 return trie->data[block+(c&UTRIE2_DATA_MASK)];
56 utrie2_get32(const UTrie2 *trie, UChar32 c) {
57 if(trie->data16!=NULL) {
58 return UTRIE2_GET16(trie, c);
59 } else if(trie->data32!=NULL) {
60 return UTRIE2_GET32(trie, c);
62 return trie->errorValue;
64 return get32(trie->newTrie, c, TRUE);
69 utrie2_get32FromLeadSurrogateCodeUnit(const UTrie2 *trie, UChar32 c) {
71 return trie->errorValue;
73 if(trie->data16!=NULL) {
74 return UTRIE2_GET16_FROM_U16_SINGLE_LEAD(trie, c);
75 } else if(trie->data32!=NULL) {
76 return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
78 return get32(trie->newTrie, c, FALSE);
83 u8Index(const UTrie2 *trie, UChar32 c, int32_t i) {
86 trie,
87 trie->data32==NULL ? trie->indexLength : 0,
93 utrie2_internalU8NextIndex(const UTrie2 *trie, UChar32 c,
104 return u8Index(trie, c, i);
108 utrie2_internalU8PrevIndex(const UTrie2 *trie, UChar32 c,
120 return u8Index(trie, c, i);
132 UTrie2 *trie;
145 /* enough data for a trie header? */
189 /* allocate the trie */
190 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
191 if(trie==NULL) {
195 uprv_memcpy(trie, &tempTrie, sizeof(tempTrie));
196 trie->memory=(uint32_t *)data;
197 trie->length=actualLength;
198 trie->isMemoryOwned=FALSE;
202 trie->index=p16;
203 p16+=trie->indexLength;
208 trie->data16=p16;
209 trie->data32=NULL;
210 trie->initialValue=trie->index[trie->dataNullOffset];
211 trie->errorValue=trie->data16[UTRIE2_BAD_UTF8_DATA_OFFSET];
214 trie->data16=NULL;
215 trie->data32=(const uint32_t *)p16;
216 trie->initialValue=trie->data32[trie->dataNullOffset];
217 trie->errorValue=trie->data32[UTRIE2_BAD_UTF8_DATA_OFFSET];
227 return trie;
234 UTrie2 *trie;
250 /* calculate the total length of the dummy trie data */
260 /* allocate the trie */
261 trie=(UTrie2 *)uprv_malloc(sizeof(UTrie2));
262 if(trie==NULL) {
266 uprv_memset(trie, 0, sizeof(UTrie2));
267 trie->memory=uprv_malloc(length);
268 if(trie->memory==NULL) {
269 uprv_free(trie);
273 trie->length=length;
274 trie->isMemoryOwned=TRUE;
283 trie->indexLength=indexLength;
284 trie->dataLength=dataLength;
285 trie->index2NullOffset=UTRIE2_INDEX_2_OFFSET;
286 trie->dataNullOffset=(uint16_t)dataMove;
287 trie->initialValue=initialValue;
288 trie->errorValue=errorValue;
289 trie->highStart=0;
290 trie->highValueIndex=dataMove+UTRIE2_DATA_START_OFFSET;
293 header=(UTrie2Header *)trie->memory;
306 trie->index=dest16;
325 trie->data16=dest16;
326 trie->data32=NULL;
341 trie->data16=NULL;
342 trie->data32=p;
359 return trie;
363 utrie2_close(UTrie2 *trie) {
364 if(trie!=NULL) {
365 if(trie->isMemoryOwned) {
366 uprv_free(trie->memory);
368 if(trie->newTrie!=NULL) {
369 uprv_free(trie->newTrie->data);
370 uprv_free(trie->newTrie);
372 uprv_free(trie);
403 UTrie2Header trie;
422 trie.signature=ds->readUInt32(inTrie->signature);
423 trie.options=ds->readUInt16(inTrie->options);
424 trie.indexLength=ds->readUInt16(inTrie->indexLength);
425 trie.shiftedDataLength=ds->readUInt16(inTrie->shiftedDataLength);
427 valueBits=(UTrie2ValueBits)(trie.options&UTRIE2_OPTIONS_VALUE_BITS_MASK);
428 dataLength=(int32_t)trie.shiftedDataLength<<UTRIE2_INDEX_SHIFT;
430 if( trie.signature!=UTRIE2_SIG ||
432 trie.indexLength<UTRIE2_INDEX_1_OFFSET ||
439 size=sizeof(UTrie2Header)+trie.indexLength*2;
469 ds->swapArray16(ds, inTrie+1, (trie.indexLength+dataLength)*2, outTrie+1, pErrorCode);
472 ds->swapArray16(ds, inTrie+1, trie.indexLength*2, outTrie+1, pErrorCode);
473 ds->swapArray32(ds, (const uint16_t *)(inTrie+1)+trie.indexLength, dataLength*4,
474 (uint16_t *)(outTrie+1)+trie.indexLength, pErrorCode);
500 * The values are transformed from the raw trie entries by the enumValue function.
512 enumEitherTrie(const UTrie2 *trie,
529 if(trie->newTrie==NULL) {
530 /* frozen trie */
531 idx=trie->index;
532 data32=trie->data32;
534 index2NullOffset=trie->index2NullOffset;
535 nullBlock=trie->dataNullOffset;
537 /* unfrozen, mutable trie */
539 data32=trie->newTrie->data;
541 index2NullOffset=trie->newTrie->index2NullOffset;
542 nullBlock=trie->newTrie->dataNullOffset;
545 highStart=trie->highStart;
547 trie data entry */
548 initialValue=enumValue(context, trie->initialValue);
587 i2Block=trie->newTrie->index1[c>>UTRIE2_SHIFT_1];
624 block=trie->newTrie->index2[i2Block+i2];
667 data32[trie->highValueIndex] :
668 idx[trie->highValueIndex];
670 highValue=trie->newTrie->data[trie->newTrie->dataLength-UTRIE2_DATA_GRANULARITY];
688 utrie2_enum(const UTrie2 *trie,
690 enumEitherTrie(trie, 0, 0x110000, enumValue, enumRange, context);
694 utrie2_enumForLeadSurrogate(const UTrie2 *trie, UChar32 lead,
701 enumEitherTrie(trie, lead, lead+0x400, enumValue, enumRange, context);
715 UTRIE2_U16_PREV16(trie, start, codePointStart, codePoint, result);
726 UTRIE2_U16_NEXT16(trie, codePointLimit, limit, codePoint, result);