/** Returns the first object registered with the specified ID in any of the ObjectSpaces the specified connection belongs * to. */ static Object getRegisteredObject (Connection connection, int objectID) { ObjectSpace[] instances = ObjectSpace.instances; for (int i = 0, n = instances.length; i < n; i++) { ObjectSpace objectSpace = instances[i]; // Check if the connection is in this ObjectSpace. Connection[] connections = objectSpace.connections; for (int j = 0; j < connections.length; j++) { if (connections[j] != connection) continue; // Find an object with the objectID. Object object = objectSpace.idToObject.get(objectID); if (object != null) return object; } } return null; }
/** Registers an object to allow the remote end of the ObjectSpace's connections to access it using the specified ID. * <p> * If a connection is added to multiple ObjectSpaces, the same object ID should not be registered in more than one of those * ObjectSpaces. * @param objectID Must not be Integer.MAX_VALUE. * @see #getRemoteObject(Connection, int, Class...) */ public void register (int objectID, Object object) { if (objectID == Integer.MAX_VALUE) throw new IllegalArgumentException("objectID cannot be Integer.MAX_VALUE."); if (object == null) throw new IllegalArgumentException("object cannot be null."); idToObject.put(objectID, object); objectToID.put(object, objectID); if (TRACE) trace("kryonet", "Object registered with ObjectSpace as " + objectID + ": " + object); }
protected Registration readName(final Input input) { final int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap<>(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. final String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { throw new KryoException("Unable to find class: " + className, ex); } if (nameToClass == null) nameToClass = new ObjectMap<>(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); } return kryo.getRegistration(type); }
keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; int index2 = hash2(key); int key2 = keyTable[index2]; if (key2 == EMPTY) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; int index3 = hash3(key); int key3 = keyTable[index3]; if (key3 == EMPTY) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; push(key, value, index1, key1, index2, key2, index3, key3);
keyTable[index1] = evictedKey; valueTable[index1] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index2 = hash2(evictedKey); key2 = keyTable[index2]; if (key2 == EMPTY) { keyTable[index2] = evictedKey; valueTable[index2] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index3 = hash3(evictedKey); key3 = keyTable[index3]; if (key3 == EMPTY) { keyTable[index3] = evictedKey; valueTable[index3] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; } while (true); putStash(evictedKey, evictedValue);
public V get (int key) { if (key == 0) { if (!hasZeroValue) return null; return zeroValue; } int index = key & mask; if (keyTable[index] != key) { index = hash2(key); if (keyTable[index] != key) { index = hash3(key); if (keyTable[index] != key) { if (isBigTable) { index = hash4(key); if (keyTable[index] != key) return getStash(key, null); } else { return getStash(key, null); } } } } return valueTable[index]; }
private void putStash (int key, V 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 (int key) { if (key == 0) return hasZeroValue; int index = key & mask; if (keyTable[index] != key) { index = hash2(key); if (keyTable[index] != key) { index = hash3(key); if (keyTable[index] != key) { if (isBigTable) { index = hash4(key); if (keyTable[index] != key) return containsKeyStash(key); } else { return containsKeyStash(key); } } } } return true; }
index = hash2(key); if (keyTable[index] == key) { keyTable[index] = EMPTY; index = hash3(key); if (keyTable[index] == key) { keyTable[index] = EMPTY; index = hash4(key); if (keyTable[index] == key) { keyTable[index] = EMPTY; return removeStash(key);
public boolean containsKey (int key) { if (key == 0) return hasZeroValue; int index = key & mask; if (keyTable[index] != key) { index = hash2(key); if (keyTable[index] != key) { index = hash3(key); if (keyTable[index] != key) return containsKeyStash(key); } } return true; }
index = hash2(key); if (keyTable[index] == key) { keyTable[index] = EMPTY; index = hash3(key); if (keyTable[index] == key) { keyTable[index] = EMPTY; return removeStash(key);
public void reset () { if (!kryo.isRegistrationRequired()) { if (classToNameId != null) classToNameId.clear(2048); if (nameIdToClass != null) nameIdToClass.clear(); nextNameId = 0; } } }
private final IntMap<Array<Item>> roomsToItems = new IntMap(); private Array<Item> items; //... public void loadItems(int roomNumber) { items = roomsToItems.get(roomNumber); //get this room's previous list if it exists if (items == null) { //this room hasn't been loaded yet items = new Array<>(); //TODO: Load the items into "items" //store the items list so it can be retrieved instead of loaded next time: roomsToItems.put(roomNumber, items); } }
protected Registration readName (Input input) { int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { throw new KryoException("Unable to find class: " + className, ex); } if (nameToClass == null) nameToClass = new ObjectMap(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); if (TRACE) trace("kryo", "Read class name: " + className); } else { if (TRACE) trace("kryo", "Read class name reference " + nameId + ": " + className(type)); } return kryo.getRegistration(type); }
keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; int index2 = hash2(key); int key2 = keyTable[index2]; if (key2 == EMPTY) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; int index3 = hash3(key); int key3 = keyTable[index3]; if (key3 == EMPTY) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; push(key, value, index1, key1, index2, key2, index3, key3);
keyTable[index1] = evictedKey; valueTable[index1] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index2 = hash2(evictedKey); key2 = keyTable[index2]; if (key2 == EMPTY) { keyTable[index2] = evictedKey; valueTable[index2] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; index3 = hash3(evictedKey); key3 = keyTable[index3]; if (key3 == EMPTY) { keyTable[index3] = evictedKey; valueTable[index3] = evictedValue; if (size++ >= threshold) resize(capacity << 1); return; } while (true); putStash(evictedKey, evictedValue);
public V get (int key, V defaultValue) { if (key == 0) { if (!hasZeroValue) return defaultValue; return zeroValue; } int index = key & mask; if (keyTable[index] != key) { index = hash2(key); if (keyTable[index] != key) { index = hash3(key); if (keyTable[index] != key) { if (isBigTable) { index = hash4(key); if (keyTable[index] != key) return getStash(key, defaultValue); } else { return getStash(key, defaultValue); } } } } return valueTable[index]; }