public static NameCanonicalizer createRoot() { return new NameCanonicalizer(DEFAULT_TABLE_SIZE); }
public Name addName(String symbolStr, int[] quads, int qlen) { int hash = calcHash(quads, qlen); Name symbol = constructName(hash, symbolStr, quads, qlen); _addSymbol(hash, symbol); return symbol; }
private void _addSymbol(int hash, Name symbol) unshareMain(); rehash(); mMainHash[ix] = (hash << 8); if (mMainNamesShared) { unshareNames(); unshareCollision(); // also allocates if list was null expandCollision(); bucket = findBestBucket();
if (child.size() > MAX_TABLE_SIZE) { initTables(DEFAULT_TABLE_SIZE); } else { mCount = child.mCount;
private final Name findName(int q1, int lastQuadBytes) throws JsonParseException { // Usually we'll find it from the canonical symbol table already Name name = _symbols.findName(q1); if (name != null) { return name; } // If not, more work. We'll need add stuff to buffer _quadBuffer[0] = q1; return addName(_quadBuffer, 1, lastQuadBytes); }
int hash = calcHash(firstQuad); int ix = (hash & mMainHashMask); int val = mMainHash[ix];
/** * Method called when not even first 8 bytes are guaranteed * to come consequtively. Happens rarely, so this is offlined; * plus we'll also do full checks for escaping etc. */ protected Name slowParseFieldName() throws IOException, JsonParseException { if (_inputPtr >= _inputEnd) { if (!loadMore()) { _reportInvalidEOF(": was expecting closing quote for name"); } } int i = _inputBuffer[_inputPtr++] & 0xFF; if (i == INT_QUOTE) { // special case, "" return NameCanonicalizer.getEmptyName(); } return parseEscapedFieldName(_quadBuffer, 0, 0, i, 0); }
private NameCanonicalizer(int hashSize) { mParent = null; /* Sanity check: let's now allow hash sizes below certain * min. value */ if (hashSize < MIN_HASH_SIZE) { hashSize = MIN_HASH_SIZE; } else { /* Also; size must be 2^N; otherwise hash algorithm won't * work... so let's just pad it up, if so */ if ((hashSize & (hashSize - 1)) != 0) { // only true if it's 2^N int curr = MIN_HASH_SIZE; while (curr < hashSize) { curr += curr; } hashSize = curr; } } initTables(hashSize); }
quads[qlen-1] = lastQuad; return _symbols.addName(baseName, quads, qlen);
private final Name findName(int q1, int q2, int lastQuadBytes) throws JsonParseException { // Usually we'll find it from the canonical symbol table already Name name = _symbols.findName(q1, q2); if (name != null) { return name; } // If not, more work. We'll need add stuff to buffer _quadBuffer[0] = q1; _quadBuffer[1] = q2; return addName(_quadBuffer, 2, lastQuadBytes); }
int hash = calcHash(firstQuad, secondQuad); int ix = (hash & mMainHashMask); int val = mMainHash[ix];
if (codes[q] != 0) { if (q == INT_QUOTE) { // special case, "" return NameCanonicalizer.getEmptyName();
private final Name findName(int[] quads, int qlen, int lastQuad, int lastQuadBytes) throws JsonParseException { if (qlen >= quads.length) { _quadBuffer = quads = growArrayBy(quads, quads.length); } quads[qlen++] = lastQuad; Name name = _symbols.findName(quads, qlen); if (name == null) { return addName(quads, qlen, lastQuadBytes); } return name; }
int hash = calcHash(quads, qlen);
public synchronized NameCanonicalizer makeChild() { return new NameCanonicalizer(this); }
Name name = _symbols.findName(quads, qlen); if (name == null) { name = addName(quads, qlen, currQuadBytes);