public LWeakTable(LTable copy) { super(copy.array.length, copy.hashKeys.length); for (int i = 0, k = 1, n = copy.array.length; i < n; i++, k++) this.put(k, copy.get(k)); for (int i = 0, n = copy.hashKeys.length; i < n; i++) { LValue k = copy.hashKeys[i]; if (k != null) this.put(k, copy.get(k)); } }
protected void rehash() { final LValue[] keys = this.hashKeys; final Object[] values = this.hashValues; final int n = hashKeys.length; for (int i = 0; i < n; ++i) { if (keys[i] != null && normalizeGet(values[i]).isNil()) { // key has dropped out, clear the slot // It's necessary to call hashClearSlot instead of just nulling // out the slot because the table must be left in a consistent // state if an OutOfMemoryError occurs later in the rehash // process. hashClearSlot(i); // If number of hash entries gets to zero, hashClearSlot will // set hashKeys back to an empty array. Check for that so we // don't have an out-of-bounds index operation. if (hashKeys != keys) break; } } // check load factor again since rehash might not be required if enough // entries dropped out. if (checkLoadFactor()) super.rehash(); }