PageRenderTime 3894ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/parser/SymbolTable.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 256 lines | 239 code | 13 blank | 4 comment | 53 complexity | 687d363d7c1f210f6a9a125eac575bb9 MD5 | raw file
  1. package com.alibaba.fastjson.parser;
  2. import com.alibaba.fastjson.JSON;
  3. public class SymbolTable
  4. {
  5. public static final int DEFAULT_TABLE_SIZE = 256;
  6. public static final int MAX_BUCKET_LENTH = 8;
  7. public static final int MAX_SIZE = 2048;
  8. private final Entry[] buckets;
  9. private final int indexMask;
  10. private int size = 0;
  11. private final String[] symbols;
  12. private final char[][] symbols_char;
  13. public SymbolTable()
  14. {
  15. this(256);
  16. addSymbol("$ref", 0, 4, "$ref".hashCode());
  17. addSymbol(JSON.DEFAULT_TYPE_KEY, 0, 4, JSON.DEFAULT_TYPE_KEY.hashCode());
  18. }
  19. public SymbolTable(int paramInt)
  20. {
  21. this.indexMask = (paramInt - 1);
  22. this.buckets = new Entry[paramInt];
  23. this.symbols = new String[paramInt];
  24. this.symbols_char = new char[paramInt][];
  25. }
  26. public static final int hash(char[] paramArrayOfChar, int paramInt1, int paramInt2)
  27. {
  28. int j = 0;
  29. int i = 0;
  30. while (i < paramInt2)
  31. {
  32. j = j * 31 + paramArrayOfChar[paramInt1];
  33. i += 1;
  34. paramInt1 += 1;
  35. }
  36. return j;
  37. }
  38. public String addSymbol(String paramString, int paramInt1, int paramInt2, int paramInt3)
  39. {
  40. int i1 = paramInt3 & this.indexMask;
  41. Object localObject = this.symbols[i1];
  42. int i = 1;
  43. int k = 1;
  44. char[] arrayOfChar;
  45. if (localObject != null)
  46. {
  47. if (((String)localObject).length() == paramInt2)
  48. {
  49. arrayOfChar = this.symbols_char[i1];
  50. i = 0;
  51. while (true)
  52. {
  53. j = k;
  54. if (i < paramInt2)
  55. {
  56. if (paramString.charAt(paramInt1 + i) != arrayOfChar[i])
  57. j = 0;
  58. }
  59. else
  60. {
  61. i = j;
  62. if (j == 0)
  63. break;
  64. return localObject;
  65. }
  66. i += 1;
  67. }
  68. }
  69. i = 0;
  70. }
  71. int j = 0;
  72. localObject = this.buckets[i1];
  73. if (localObject != null)
  74. {
  75. arrayOfChar = ((Entry)localObject).characters;
  76. k = j;
  77. int n;
  78. if (paramInt2 == arrayOfChar.length)
  79. {
  80. k = j;
  81. if (paramInt3 == ((Entry)localObject).hashCode)
  82. {
  83. n = 1;
  84. k = 0;
  85. }
  86. }
  87. while (true)
  88. {
  89. int m = n;
  90. if (k < paramInt2)
  91. {
  92. if (paramString.charAt(paramInt1 + k) != arrayOfChar[k])
  93. m = 0;
  94. }
  95. else
  96. {
  97. if (m != 0)
  98. break label221;
  99. k = j + 1;
  100. localObject = ((Entry)localObject).next;
  101. j = k;
  102. break;
  103. }
  104. k += 1;
  105. }
  106. label221: return ((Entry)localObject).symbol;
  107. }
  108. if (j >= 8)
  109. return paramString.substring(paramInt1, paramInt1 + paramInt2);
  110. if (this.size >= 2048)
  111. return paramString.substring(paramInt1, paramInt1 + paramInt2);
  112. paramString = new Entry(paramString, paramInt1, paramInt2, paramInt3, this.buckets[i1]);
  113. this.buckets[i1] = paramString;
  114. if (i != 0)
  115. {
  116. this.symbols[i1] = paramString.symbol;
  117. this.symbols_char[i1] = paramString.characters;
  118. }
  119. this.size += 1;
  120. return paramString.symbol;
  121. }
  122. public String addSymbol(char[] paramArrayOfChar, int paramInt1, int paramInt2)
  123. {
  124. return addSymbol(paramArrayOfChar, paramInt1, paramInt2, hash(paramArrayOfChar, paramInt1, paramInt2));
  125. }
  126. public String addSymbol(char[] paramArrayOfChar, int paramInt1, int paramInt2, int paramInt3)
  127. {
  128. int i1 = paramInt3 & this.indexMask;
  129. Object localObject = this.symbols[i1];
  130. int i = 1;
  131. int k = 1;
  132. char[] arrayOfChar;
  133. if (localObject != null)
  134. {
  135. if (((String)localObject).length() == paramInt2)
  136. {
  137. arrayOfChar = this.symbols_char[i1];
  138. i = 0;
  139. while (true)
  140. {
  141. j = k;
  142. if (i < paramInt2)
  143. {
  144. if (paramArrayOfChar[(paramInt1 + i)] != arrayOfChar[i])
  145. j = 0;
  146. }
  147. else
  148. {
  149. i = j;
  150. if (j == 0)
  151. break;
  152. return localObject;
  153. }
  154. i += 1;
  155. }
  156. }
  157. i = 0;
  158. }
  159. int j = 0;
  160. localObject = this.buckets[i1];
  161. if (localObject != null)
  162. {
  163. arrayOfChar = ((Entry)localObject).characters;
  164. k = j;
  165. int n;
  166. if (paramInt2 == arrayOfChar.length)
  167. {
  168. k = j;
  169. if (paramInt3 == ((Entry)localObject).hashCode)
  170. {
  171. n = 1;
  172. k = 0;
  173. }
  174. }
  175. while (true)
  176. {
  177. int m = n;
  178. if (k < paramInt2)
  179. {
  180. if (paramArrayOfChar[(paramInt1 + k)] != arrayOfChar[k])
  181. m = 0;
  182. }
  183. else
  184. {
  185. if (m != 0)
  186. break label217;
  187. k = j + 1;
  188. localObject = ((Entry)localObject).next;
  189. j = k;
  190. break;
  191. }
  192. k += 1;
  193. }
  194. label217: return ((Entry)localObject).symbol;
  195. }
  196. if (j >= 8)
  197. return new String(paramArrayOfChar, paramInt1, paramInt2);
  198. if (this.size >= 2048)
  199. return new String(paramArrayOfChar, paramInt1, paramInt2);
  200. paramArrayOfChar = new Entry(paramArrayOfChar, paramInt1, paramInt2, paramInt3, this.buckets[i1]);
  201. this.buckets[i1] = paramArrayOfChar;
  202. if (i != 0)
  203. {
  204. this.symbols[i1] = paramArrayOfChar.symbol;
  205. this.symbols_char[i1] = paramArrayOfChar.characters;
  206. }
  207. this.size += 1;
  208. return paramArrayOfChar.symbol;
  209. }
  210. public int size()
  211. {
  212. return this.size;
  213. }
  214. protected static final class Entry
  215. {
  216. public final byte[] bytes;
  217. public final char[] characters;
  218. public final int hashCode;
  219. public Entry next;
  220. public final String symbol;
  221. public Entry(String paramString, int paramInt1, int paramInt2, int paramInt3, Entry paramEntry)
  222. {
  223. this.symbol = paramString.substring(paramInt1, paramInt1 + paramInt2).intern();
  224. this.characters = this.symbol.toCharArray();
  225. this.next = paramEntry;
  226. this.hashCode = paramInt3;
  227. this.bytes = null;
  228. }
  229. public Entry(char[] paramArrayOfChar, int paramInt1, int paramInt2, int paramInt3, Entry paramEntry)
  230. {
  231. this.characters = new char[paramInt2];
  232. System.arraycopy(paramArrayOfChar, paramInt1, this.characters, 0, paramInt2);
  233. this.symbol = new String(this.characters).intern();
  234. this.next = paramEntry;
  235. this.hashCode = paramInt3;
  236. this.bytes = null;
  237. }
  238. }
  239. }
  240. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  241. * Qualified Name: com.alibaba.fastjson.parser.SymbolTable
  242. * JD-Core Version: 0.6.2
  243. */