Lines Matching refs:trie
53 UNewTrie *trie; in utrie_open() local
63 trie=fillIn; in utrie_open()
65 trie=(UNewTrie *)uprv_malloc(sizeof(UNewTrie)); in utrie_open()
66 if(trie==NULL) { in utrie_open()
70 uprv_memset(trie, 0, sizeof(UNewTrie)); in utrie_open()
71 trie->isAllocated= (UBool)(fillIn==NULL); in utrie_open()
74 trie->data=aliasData; in utrie_open()
75 trie->isDataAllocated=FALSE; in utrie_open()
77 trie->data=(uint32_t *)uprv_malloc(maxDataLength*4); in utrie_open()
78 if(trie->data==NULL) { in utrie_open()
79 uprv_free(trie); in utrie_open()
82 trie->isDataAllocated=TRUE; in utrie_open()
96 trie->index[i++]=j; in utrie_open()
102 trie->dataLength=j; in utrie_open()
104 trie->data[--j]=initialValue; in utrie_open()
107 trie->leadUnitValue=leadUnitValue; in utrie_open()
108 trie->indexLength=UTRIE_MAX_INDEX_LENGTH; in utrie_open()
109 trie->dataCapacity=maxDataLength; in utrie_open()
110 trie->isLatin1Linear=latin1Linear; in utrie_open()
111 trie->isCompacted=FALSE; in utrie_open()
112 return trie; in utrie_open()
117 UNewTrie *trie; in utrie_clone() local
137 trie=utrie_open(fillIn, aliasData, aliasDataCapacity, in utrie_clone()
140 if(trie==NULL) { in utrie_clone()
143 uprv_memcpy(trie->index, other->index, sizeof(trie->index)); in utrie_clone()
144 uprv_memcpy(trie->data, other->data, (size_t)other->dataLength*4); in utrie_clone()
145 trie->dataLength=other->dataLength; in utrie_clone()
146 trie->isDataAllocated=isDataAllocated; in utrie_clone()
149 return trie; in utrie_clone()
153 utrie_close(UNewTrie *trie) { in utrie_close() argument
154 if(trie!=NULL) { in utrie_close()
155 if(trie->isDataAllocated) { in utrie_close()
156 uprv_free(trie->data); in utrie_close()
157 trie->data=NULL; in utrie_close()
159 if(trie->isAllocated) { in utrie_close()
160 uprv_free(trie); in utrie_close()
166 utrie_getData(UNewTrie *trie, int32_t *pLength) { in utrie_getData() argument
167 if(trie==NULL || pLength==NULL) { in utrie_getData()
171 *pLength=trie->dataLength; in utrie_getData()
172 return trie->data; in utrie_getData()
176 utrie_allocDataBlock(UNewTrie *trie) { in utrie_allocDataBlock() argument
179 newBlock=trie->dataLength; in utrie_allocDataBlock()
181 if(newTop>trie->dataCapacity) { in utrie_allocDataBlock()
185 trie->dataLength=newTop; in utrie_allocDataBlock()
196 utrie_getDataBlock(UNewTrie *trie, UChar32 c) { in utrie_getDataBlock() argument
200 indexValue=trie->index[c]; in utrie_getDataBlock()
206 newBlock=utrie_allocDataBlock(trie); in utrie_getDataBlock()
211 trie->index[c]=newBlock; in utrie_getDataBlock()
214 uprv_memcpy(trie->data+newBlock, trie->data-indexValue, 4*UTRIE_DATA_BLOCK_LENGTH); in utrie_getDataBlock()
222 utrie_set32(UNewTrie *trie, UChar32 c, uint32_t value) { in utrie_set32() argument
226 if(trie==NULL || trie->isCompacted || (uint32_t)c>0x10ffff) { in utrie_set32()
230 block=utrie_getDataBlock(trie, c); in utrie_set32()
235 trie->data[block+(c&UTRIE_MASK)]=value; in utrie_set32()
240 utrie_get32(UNewTrie *trie, UChar32 c, UBool *pInBlockZero) { in utrie_get32() argument
244 if(trie==NULL || trie->isCompacted || (uint32_t)c>0x10ffff) { in utrie_get32()
251 block=trie->index[c>>UTRIE_SHIFT]; in utrie_get32()
256 return trie->data[ABS(block)+(c&UTRIE_MASK)]; in utrie_get32()
284 utrie_setRange32(UNewTrie *trie, UChar32 start, UChar32 limit, uint32_t value, UBool overwrite) { in utrie_setRange32() argument
294 if( trie==NULL || trie->isCompacted || in utrie_setRange32()
303 initialValue=trie->data[0]; in utrie_setRange32()
308 block=utrie_getDataBlock(trie, start); in utrie_setRange32()
315 utrie_fillBlock(trie->data+block, start&UTRIE_MASK, UTRIE_DATA_BLOCK_LENGTH, in utrie_setRange32()
319 utrie_fillBlock(trie->data+block, start&UTRIE_MASK, limit&UTRIE_MASK, in utrie_setRange32()
339 block=trie->index[start>>UTRIE_SHIFT]; in utrie_setRange32()
342 … utrie_fillBlock(trie->data+block, 0, UTRIE_DATA_BLOCK_LENGTH, value, initialValue, overwrite); in utrie_setRange32()
343 } else if(trie->data[-block]!=value && (block==0 || overwrite)) { in utrie_setRange32()
346 trie->index[start>>UTRIE_SHIFT]=-repeatBlock; in utrie_setRange32()
349 repeatBlock=utrie_getDataBlock(trie, start); in utrie_setRange32()
355 trie->index[start>>UTRIE_SHIFT]=-repeatBlock; in utrie_setRange32()
356 … utrie_fillBlock(trie->data+repeatBlock, 0, UTRIE_DATA_BLOCK_LENGTH, value, initialValue, TRUE); in utrie_setRange32()
365 block=utrie_getDataBlock(trie, start); in utrie_setRange32()
370 utrie_fillBlock(trie->data+block, 0, rest, value, initialValue, overwrite); in utrie_setRange32()
405 utrie_fold(UNewTrie *trie, UNewTrieGetFoldedValue *getFoldedValue, UErrorCode *pErrorCode) { in utrie_fold() argument
415 idx=trie->index; in utrie_fold()
430 if(trie->leadUnitValue==trie->data[0]) { in utrie_fold()
434 block=utrie_allocDataBlock(trie); in utrie_fold()
440 …utrie_fillBlock(trie->data+block, 0, UTRIE_DATA_BLOCK_LENGTH, trie->leadUnitValue, trie->data[0], … in utrie_fold()
444 trie->index[c]=block; in utrie_fold()
475 value=getFoldedValue(trie, c, block+UTRIE_SURROGATE_BLOCK_COUNT); in utrie_fold()
476 if(value!=utrie_get32(trie, U16_LEAD(c), NULL)) { in utrie_fold()
477 if(!utrie_set32(trie, U16_LEAD(c), value)) { in utrie_fold()
534 trie->indexLength=indexLength; in utrie_fold()
546 _findUnusedBlocks(UNewTrie *trie) { in _findUnusedBlocks() argument
550 uprv_memset(trie->map, 0xff, (UTRIE_MAX_BUILD_TIME_DATA_LENGTH>>UTRIE_SHIFT)*4); in _findUnusedBlocks()
553 for(i=0; i<trie->indexLength; ++i) { in _findUnusedBlocks()
554 trie->map[ABS(trie->index[i])>>UTRIE_SHIFT]=0; in _findUnusedBlocks()
558 trie->map[0]=0; in _findUnusedBlocks()
590 utrie_compact(UNewTrie *trie, UBool overlap, UErrorCode *pErrorCode) { in utrie_compact() argument
598 if(trie==NULL) { in utrie_compact()
602 if(trie->isCompacted) { in utrie_compact()
609 _findUnusedBlocks(trie); in utrie_compact()
612 if(trie->isLatin1Linear && UTRIE_SHIFT<=8) { in utrie_compact()
619 for(start=newStart; start<trie->dataLength;) { in utrie_compact()
627 if(trie->map[start>>UTRIE_SHIFT]<0) { in utrie_compact()
637 (i=_findSameDataBlock(trie->data, newStart, start, in utrie_compact()
642 trie->map[start>>UTRIE_SHIFT]=i; in utrie_compact()
655 i>0 && !equal_uint32(trie->data+(newStart-i), trie->data+start, i); in utrie_compact()
663 trie->map[start>>UTRIE_SHIFT]=newStart-i; in utrie_compact()
668 trie->data[newStart++]=trie->data[start++]; in utrie_compact()
672 trie->map[start>>UTRIE_SHIFT]=newStart; in utrie_compact()
674 trie->data[newStart++]=trie->data[start++]; in utrie_compact()
677 trie->map[start>>UTRIE_SHIFT]=start; in utrie_compact()
684 for(i=0; i<trie->indexLength; ++i) { in utrie_compact()
685 trie->index[i]=trie->map[ABS(trie->index[i])>>UTRIE_SHIFT]; in utrie_compact()
691 (long)trie->dataLength, (long)newStart); in utrie_compact()
694 trie->dataLength=newStart; in utrie_compact()
721 defaultGetFoldedValue(UNewTrie *trie, UChar32 start, int32_t offset) { in defaultGetFoldedValue() argument
726 initialValue=trie->data[0]; in defaultGetFoldedValue()
729 value=utrie_get32(trie, start, &inBlockZero); in defaultGetFoldedValue()
742 utrie_serialize(UNewTrie *trie, void *dt, int32_t capacity, in utrie_serialize() argument
757 if(trie==NULL || capacity<0 || (capacity>0 && dt==NULL)) { in utrie_serialize()
767 if(!trie->isCompacted) { in utrie_serialize()
769 utrie_compact(trie, FALSE, pErrorCode); in utrie_serialize()
772 utrie_fold(trie, getFoldedValue, pErrorCode); in utrie_serialize()
775 utrie_compact(trie, TRUE, pErrorCode); in utrie_serialize()
777 trie->isCompacted=TRUE; in utrie_serialize()
784 …if( (reduceTo16Bits ? (trie->dataLength+trie->indexLength) : trie->dataLength) >= UTRIE_MAX_DATA_L… in utrie_serialize()
788 length=sizeof(UTrieHeader)+2*trie->indexLength; in utrie_serialize()
790 length+=2*trie->dataLength; in utrie_serialize()
792 length+=4*trie->dataLength; in utrie_serialize()
801 (long)trie->indexLength, (long)trie->dataLength, (long)length); in utrie_serialize()
814 if(trie->isLatin1Linear) { in utrie_serialize()
818 header->indexLength=trie->indexLength; in utrie_serialize()
819 header->dataLength=trie->dataLength; in utrie_serialize()
824 p=(uint32_t *)trie->index; in utrie_serialize()
826 for(i=trie->indexLength; i>0; --i) { in utrie_serialize()
827 *dest16++=(uint16_t)((*p++ + trie->indexLength)>>UTRIE_INDEX_SHIFT); in utrie_serialize()
831 p=trie->data; in utrie_serialize()
832 for(i=trie->dataLength; i>0; --i) { in utrie_serialize()
837 p=(uint32_t *)trie->index; in utrie_serialize()
839 for(i=trie->indexLength; i>0; --i) { in utrie_serialize()
844 uprv_memcpy(dest16, trie->data, 4*(size_t)trie->dataLength); in utrie_serialize()
857 utrie_unserialize(UTrie *trie, const void *data, int32_t length, UErrorCode *pErrorCode) { in utrie_unserialize() argument
887 trie->isLatin1Linear= (UBool)((options&UTRIE_OPTIONS_LATIN1_IS_LINEAR)!=0); in utrie_unserialize()
890 trie->indexLength=header->indexLength; in utrie_unserialize()
891 trie->dataLength=header->dataLength; in utrie_unserialize()
896 if(length<2*trie->indexLength) { in utrie_unserialize()
901 trie->index=p16; in utrie_unserialize()
902 p16+=trie->indexLength; in utrie_unserialize()
903 length-=2*trie->indexLength; in utrie_unserialize()
907 if(length<4*trie->dataLength) { in utrie_unserialize()
911 trie->data32=(const uint32_t *)p16; in utrie_unserialize()
912 trie->initialValue=trie->data32[0]; in utrie_unserialize()
913 length=(int32_t)sizeof(UTrieHeader)+2*trie->indexLength+4*trie->dataLength; in utrie_unserialize()
915 if(length<2*trie->dataLength) { in utrie_unserialize()
921 trie->data32=NULL; in utrie_unserialize()
922 trie->initialValue=trie->index[trie->indexLength]; in utrie_unserialize()
923 length=(int32_t)sizeof(UTrieHeader)+2*trie->indexLength+2*trie->dataLength; in utrie_unserialize()
926 trie->getFoldingOffset=utrie_defaultGetFoldingOffset; in utrie_unserialize()
932 utrie_unserializeDummy(UTrie *trie, in utrie_unserializeDummy() argument
950 trie->indexLength=UTRIE_BMP_INDEX_LENGTH+UTRIE_SURROGATE_BLOCK_COUNT; in utrie_unserializeDummy()
951 trie->dataLength=latin1Length; in utrie_unserializeDummy()
953 trie->dataLength+=UTRIE_DATA_BLOCK_LENGTH; in utrie_unserializeDummy()
956 actualLength=trie->indexLength*2; in utrie_unserializeDummy()
958 actualLength+=trie->dataLength*2; in utrie_unserializeDummy()
960 actualLength+=trie->dataLength*4; in utrie_unserializeDummy()
969 trie->isLatin1Linear=TRUE; in utrie_unserializeDummy()
970 trie->initialValue=initialValue; in utrie_unserializeDummy()
974 trie->index=p16; in utrie_unserializeDummy()
978 block=(uint16_t)(trie->indexLength>>UTRIE_INDEX_SHIFT); in utrie_unserializeDummy()
979 limit=trie->indexLength; in utrie_unserializeDummy()
994 trie->data32=NULL; in utrie_unserializeDummy()
997 p16+=trie->indexLength; in utrie_unserializeDummy()
1013 uprv_memset(p16, 0, trie->indexLength*2); in utrie_unserializeDummy()
1025 trie->data32=p32=(uint32_t *)(p16+trie->indexLength); in utrie_unserializeDummy()
1041 trie->getFoldingOffset=utrie_defaultGetFoldingOffset; in utrie_unserializeDummy()
1059 utrie_enum(const UTrie *trie, in utrie_enum() argument
1069 if(trie==NULL || trie->index==NULL || enumRange==NULL) { in utrie_enum()
1076 idx=trie->index; in utrie_enum()
1077 data32=trie->data32; in utrie_enum()
1080 initialValue=enumValue(context, trie->initialValue); in utrie_enum()
1083 nullBlock=trie->indexLength; in utrie_enum()
1167 offset=trie->getFoldingOffset(value); in utrie_enum()