private void rehash() { WeakHashSet newHashSet = new WeakHashSet(this.elementSize * 2); // double the number of expected elements newHashSet.referenceQueue = this.referenceQueue; HashableWeakReference currentValue; for (int i = 0, length = this.values.length; i < length; i++) if ((currentValue = this.values[i]) != null) newHashSet.addValue(currentValue); this.values = newHashSet.values; this.threshold = newHashSet.threshold; this.elementSize = newHashSet.elementSize; }
public boolean contains(Object obj) { return get(obj) != null; }
public synchronized String intern(String s) { return (String) this.stringSymbols.add(s); // Note1: String#intern() cannot be used as on some VMs this prevents the string from being garbage collected // Note 2: Instead of using a WeakHashset, one could use a WeakHashMap with the following implementation // This would costs more per entry (one Entry object and one WeakReference more)) /* WeakReference reference = (WeakReference) this.symbols.get(s); String existing; if (reference != null && (existing = (String) reference.get()) != null) return existing; this.symbols.put(s, new WeakReference(s)); return s; */ }
public Object remove(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { this.elementSize--; this.values[index] = null; rehash(); return referent; } if (++index == valuesLength) { index = 0; } } return null; }
public Object get(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void addValue(HashableWeakReference value) { Object obj = value.get(); if (obj == null) return; int valuesLength = this.values.length; int index = (value.hashCode & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { if (obj.equals(currentValue.get())) { return; } if (++index == valuesLength) { index = 0; } } this.values[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); }
public Object remove(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { this.elementSize--; this.values[index] = null; rehash(); return referent; } if (++index == valuesLength) { index = 0; } } return null; }
public Object get(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void addValue(HashableWeakReference value) { Object obj = value.get(); if (obj == null) return; int valuesLength = this.values.length; int index = (value.hashCode & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { if (obj.equals(currentValue.get())) { return; } if (++index == valuesLength) { index = 0; } } this.values[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); }
public Object remove(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { this.elementSize--; this.values[index] = null; rehash(); return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void rehash() { WeakHashSet newHashSet = new WeakHashSet(this.elementSize * 2); // double the number of expected elements newHashSet.referenceQueue = this.referenceQueue; HashableWeakReference currentValue; for (int i = 0, length = this.values.length; i < length; i++) if ((currentValue = this.values[i]) != null) newHashSet.addValue(currentValue); this.values = newHashSet.values; this.threshold = newHashSet.threshold; this.elementSize = newHashSet.elementSize; }
public boolean contains(Object obj) { return get(obj) != null; }
public Object get(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void addValue(HashableWeakReference value) { Object obj = value.get(); if (obj == null) return; int valuesLength = this.values.length; int index = (value.hashCode & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { if (obj.equals(currentValue.get())) { return; } if (++index == valuesLength) { index = 0; } } this.values[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); }
public synchronized String intern(String s) { // make sure to copy the string (so that it doesn't hold on the underlying char[] that might be much bigger than necessary) return (String) this.stringSymbols.add(new String(s)); // Note1: String#intern() cannot be used as on some VMs this prevents the string from being garbage collected // Note 2: Instead of using a WeakHashset, one could use a WeakHashMap with the following implementation // This would costs more per entry (one Entry object and one WeakReference more)) /* WeakReference reference = (WeakReference) this.symbols.get(s); String existing; if (reference != null && (existing = (String) reference.get()) != null) return existing; this.symbols.put(s, new WeakReference(s)); return s; */ }
public Object remove(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { this.elementSize--; this.values[index] = null; rehash(); return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void rehash() { WeakHashSet newHashSet = new WeakHashSet(this.elementSize * 2); // double the number of expected elements newHashSet.referenceQueue = this.referenceQueue; HashableWeakReference currentValue; for (int i = 0, length = this.values.length; i < length; i++) if ((currentValue = this.values[i]) != null) newHashSet.addValue(currentValue); this.values = newHashSet.values; this.threshold = newHashSet.threshold; this.elementSize = newHashSet.elementSize; }
public boolean contains(Object obj) { return get(obj) != null; }
public Object get(Object obj) { cleanupGarbageCollectedValues(); int valuesLength = this.values.length; int index = (obj.hashCode() & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { Object referent; if (obj.equals(referent = currentValue.get())) { return referent; } if (++index == valuesLength) { index = 0; } } return null; }
private void addValue(HashableWeakReference value) { Object obj = value.get(); if (obj == null) return; int valuesLength = this.values.length; int index = (value.hashCode & 0x7FFFFFFF) % valuesLength; HashableWeakReference currentValue; while ((currentValue = this.values[index]) != null) { if (obj.equals(currentValue.get())) { return; } if (++index == valuesLength) { index = 0; } } this.values[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); }