@Override public void reset () { readObjects.clear(); writtenObjects.clear(65536); } }
public int getWrittenId (Object object) { return writtenObjects.get(object, -1); }
private void putStash (K key, int value) { if (stashSize == stashCapacity) { // Too many pushes occurred and the stash is full, increase the table size. resize(capacity << 1); put(key, value); return; } // Store key in the stash. int index = capacity + stashSize; keyTable[index] = key; valueTable[index] = value; stashSize++; size++; }
public boolean containsKey (K key) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) return containsKeyStash(key); } } return true; }
/** Skips checks for existing keys. */ private void putResize (K key, int value) { // Check for empty buckets. int hashCode = System.identityHashCode(key); int index1 = hashCode & mask; K key1 = keyTable[index1]; if (key1 == null) { keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; } int index2 = hash2(hashCode); K key2 = keyTable[index2]; if (key2 == null) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; } int index3 = hash3(hashCode); K key3 = keyTable[index3]; if (key3 == null) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; } push(key, value, index1, key1, index2, key2, index3, key3); }
protected void writeName(final Output output, final Class type) { output.writeVarInt(NAME + 2, true); if (classToNameId != null) { final int nameId = classToNameId.get(type, -1); if (nameId != -1) { output.writeVarInt(nameId, true); return; } } // Only write the class name the first time encountered in object graph. final int nameId = nextNameId++; if (classToNameId == null) classToNameId = new IdentityObjectIntMap<>(); classToNameId.put(type, nameId); output.writeVarInt(nameId, true); output.writeString(type.getName()); }
keyTable[index1] = evictedKey; valueTable[index1] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index2 = hash2(hashCode); key2 = keyTable[index2]; if (key2 == null) { keyTable[index2] = evictedKey; valueTable[index2] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index3 = hash3(hashCode); key3 = keyTable[index3]; if (key3 == null) { keyTable[index3] = evictedKey; valueTable[index3] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index4 = hash4(hashCode); key4 = keyTable[index4]; if (key4 == null) { keyTable[index4] = evictedKey; valueTable[index4] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return;
public boolean containsKey (K key) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) { if (isBigTable) { index = hash4(hashCode); if (key != keyTable[index]) return containsKeyStash(key); } else { return containsKeyStash(key); } } } } return true; }
/** Returns the key's current value and increments the stored value. If the key is not in the map, defaultValue + increment is * put into the map. */ public int getAndIncrement (K key, int defaultValue, int increment) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) { if (isBigTable) { index = hash4(hashCode); if (key != keyTable[index]) return getAndIncrementStash(key, defaultValue, increment); } else { return getAndIncrementStash(key, defaultValue, increment); } } } } int value = valueTable[index]; valueTable[index] = value + increment; return value; }
/** @param defaultValue Returned if the key was not associated with a value. */ public int get (K key, int defaultValue) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) { if (isBigTable) { index = hash4(hashCode); if (key != keyTable[index]) return getStash(key, defaultValue); } else { return getStash(key, defaultValue); } } } } return valueTable[index]; }
index = hash2(hashCode); if (key == keyTable[index]) { keyTable[index] = null; index = hash3(hashCode); if (key == keyTable[index]) { keyTable[index] = null; index = hash4(hashCode); if (key == keyTable[index]) { keyTable[index] = null; return removeStash(key, defaultValue);
public int addWrittenObject (Object object) { int id = writtenObjects.size; writtenObjects.put(object, id); return id; }
/** @param defaultValue Returned if the key was not associated with a value. */ public int get (K key, int defaultValue) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) return getStash(key, defaultValue); } } return valueTable[index]; }
/** Returns the key's current value and increments the stored value. If the key is not in the map, defaultValue + increment is * put into the map. */ public int getAndIncrement (K key, int defaultValue, int increment) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key != keyTable[index]) { index = hash2(hashCode); if (key != keyTable[index]) { index = hash3(hashCode); if (key != keyTable[index]) return getAndIncrementStash(key, defaultValue, increment); } } int value = valueTable[index]; valueTable[index] = value + increment; return value; }
public int remove (K key, int defaultValue) { int hashCode = System.identityHashCode(key); int index = hashCode & mask; if (key == keyTable[index]) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } index = hash2(hashCode); if (key == keyTable[index]) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } index = hash3(hashCode); if (key == keyTable[index]) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } return removeStash(key, defaultValue); }
keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; int index2 = hash2(hashCode); K key2 = keyTable[index2]; if (key2 == null) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; int index3 = hash3(hashCode); K key3 = keyTable[index3]; if (key3 == null) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; K key4 = null; if (isBigTable) { index4 = hash4(hashCode); key4 = keyTable[index4]; if (key4 == null) { keyTable[index4] = key; valueTable[index4] = value; if (size++ >= threshold) resize(capacity << 1);
protected void writeName (Output output, Class type, Registration registration) { output.writeVarInt(NAME + 2, true); if (classToNameId != null) { int nameId = classToNameId.get(type, -1); if (nameId != -1) { if (TRACE) trace("kryo", "Write class name reference " + nameId + ": " + className(type)); output.writeVarInt(nameId, true); return; } } // Only write the class name the first time encountered in object graph. if (TRACE) trace("kryo", "Write class name: " + className(type)); int nameId = nextNameId++; if (classToNameId == null) classToNameId = new IdentityObjectIntMap(); classToNameId.put(type, nameId); output.writeVarInt(nameId, true); output.writeString(type.getName()); }
keyTable[index1] = evictedKey; valueTable[index1] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index2 = hash2(hashCode); key2 = keyTable[index2]; if (key2 == null) { keyTable[index2] = evictedKey; valueTable[index2] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index3 = hash3(hashCode); key3 = keyTable[index3]; if (key3 == null) { keyTable[index3] = evictedKey; valueTable[index3] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; } while (true); putStash(evictedKey, evictedValue);