1 7 8 package com.ibm.icu.impl; 9 10 import com.ibm.icu.lang.UCharacter; 11 import java.util.Arrays ; 12 13 30 public class TrieBuilder 31 { 32 34 38 public static final int DATA_BLOCK_LENGTH = 1 << Trie.INDEX_STAGE_1_SHIFT_; 39 40 42 50 public static interface DataManipulate 51 { 52 71 public int getFoldedValue(int start, int offset); 72 } 73 74 76 81 public boolean isInZeroBlock(int ch) 82 { 83 if (m_isCompacted_ || ch > UCharacter.MAX_VALUE 85 || ch < UCharacter.MIN_VALUE) { 86 return true; 87 } 88 89 return m_index_[ch >> SHIFT_] == 0; 90 } 91 92 94 96 101 protected int m_index_[]; 102 protected int m_indexLength_; 103 protected int m_dataCapacity_; 104 protected int m_dataLength_; 105 protected boolean m_isLatin1Linear_; 106 protected boolean m_isCompacted_; 107 111 protected int m_map_[]; 112 113 116 protected static final int SHIFT_ = Trie.INDEX_STAGE_1_SHIFT_; 117 122 protected static final int MAX_INDEX_LENGTH_ = (0x110000 >> SHIFT_); 123 126 protected static final int BMP_INDEX_LENGTH_ = 0x10000 >> SHIFT_; 127 134 protected static final int SURROGATE_BLOCK_COUNT_ = 1 << (10 - SHIFT_); 135 139 protected static final int MASK_ = Trie.INDEX_STAGE_3_MASK_; 140 147 protected static final int INDEX_SHIFT_ = Trie.INDEX_STAGE_2_SHIFT_; 148 152 protected static final int MAX_DATA_LENGTH_ = (0x10000 << INDEX_SHIFT_); 153 156 protected static final int OPTIONS_INDEX_SHIFT_ = 4; 157 160 protected static final int OPTIONS_DATA_IS_32_BIT_ = 0x100; 161 165 protected static final int OPTIONS_LATIN1_IS_LINEAR_ = 0x200; 166 170 protected static final int DATA_GRANULARITY_ = 1 << INDEX_SHIFT_; 171 172 174 protected TrieBuilder() 175 { 176 m_index_ = new int[MAX_INDEX_LENGTH_]; 177 m_map_ = new int[MAX_BUILD_TIME_DATA_LENGTH_ >> SHIFT_]; 178 m_isLatin1Linear_ = false; 179 m_isCompacted_ = false; 180 m_indexLength_ = MAX_INDEX_LENGTH_; 181 } 182 183 protected TrieBuilder(TrieBuilder table) 184 { 185 m_index_ = new int[MAX_INDEX_LENGTH_]; 186 m_indexLength_ = table.m_indexLength_; 187 System.arraycopy(table.m_index_, 0, m_index_, 0, m_indexLength_); 188 m_dataCapacity_ = table.m_dataCapacity_; 189 m_dataLength_ = table.m_dataLength_; 190 m_map_ = new int[table.m_map_.length]; 191 System.arraycopy(table.m_map_, 0, m_map_, 0, m_map_.length); 192 m_isLatin1Linear_ = table.m_isLatin1Linear_; 193 m_isCompacted_ = table.m_isCompacted_; 194 } 195 196 198 201 protected static final boolean equal_int(int[] array, int start1, int start2, int length) { 202 while(length>0 && array[start1]==array[start2]) { 203 ++start1; 204 ++start2; 205 --length; 206 } 207 return length==0; 208 } 209 210 218 protected void findUnusedBlocks() 219 { 220 Arrays.fill(m_map_, 0xff); 222 223 for (int i = 0; i < m_indexLength_; ++ i) { 225 m_map_[Math.abs(m_index_[i]) >> SHIFT_] = 0; 226 } 227 228 m_map_[0] = 0; 230 } 231 232 239 protected static final int findSameIndexBlock(int index[], int indexLength, 240 int otherBlock) 241 { 242 for (int block = BMP_INDEX_LENGTH_; block < indexLength; 243 block += SURROGATE_BLOCK_COUNT_) { 244 if(equal_int(index, block, otherBlock, SURROGATE_BLOCK_COUNT_)) { 245 return block; 246 } 247 } 248 return indexLength; 249 } 250 251 253 259 private static final int MAX_BUILD_TIME_DATA_LENGTH_ = 260 0x110000 + DATA_BLOCK_LENGTH + 0x400; 261 } 262 | Popular Tags |