Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-02-15 10:27:27 -0500
committerEike Stepper2013-02-15 10:27:27 -0500
commit526b5d4c657fc404f21085d3130f048bb57e39ba (patch)
tree10bcb30fa489ac9e95a14eecf43d3d7f95515d25
parent1e999f4825d41c2a3b43fb6291fb6416410376ad (diff)
downloadcdo-526b5d4c657fc404f21085d3130f048bb57e39ba.tar.gz
cdo-526b5d4c657fc404f21085d3130f048bb57e39ba.tar.xz
cdo-526b5d4c657fc404f21085d3130f048bb57e39ba.zip
[400911] Utility for interning instances efficiently
https://bugs.eclipse.org/bugs/show_bug.cgi?id=400911
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/Interner.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/Interner.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/Interner.java
index 6c85849b2b..3247428250 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/Interner.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/Interner.java
@@ -35,6 +35,34 @@ public class Interner<E>
{
}
+ public Interner(int minimumCapacity)
+ {
+ grow(minimumCapacity);
+ }
+
+ /**
+ * Ensures that the set has at least the specifies capacity.
+ * Higher capacity ensures fewer collisions hence faster lookup.
+ * Does nothing if the specified capacity is smaller than the current capacity.
+ */
+ public void grow(int minimumCapacity)
+ {
+ int currentCapacity = PRIME_CAPACITIES[capacityIndex];
+ if (currentCapacity < minimumCapacity)
+ {
+ for (int i = 0, length = PRIME_CAPACITIES.length; i < length; ++i)
+ {
+ int capacity = PRIME_CAPACITIES[i];
+ if (capacity > minimumCapacity)
+ {
+ capacityIndex = i;
+ rehash(newEntries(capacity));
+ break;
+ }
+ }
+ }
+ }
+
public E intern(E object)
{
cleanup();

Back to the top