diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java index 9ec8566852..3f6f5afa15 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java @@ -26,10 +26,12 @@ public class Array2DHashSet implements Set { /** How many elements in set */ protected int n = 0; - protected int threshold = (int)Math.floor(INITAL_CAPACITY * LOAD_FACTOR); // when to expand - protected int currentPrime = 1; // jump by 4 primes each expand or whatever - protected int initialBucketCapacity = INITAL_BUCKET_CAPACITY; + + /** when to expand */ + protected int threshold; + protected final int initialCapacity; + protected final int initialBucketCapacity; public Array2DHashSet() { this(null, INITAL_CAPACITY, INITAL_BUCKET_CAPACITY); @@ -45,8 +47,10 @@ public Array2DHashSet(AbstractEqualityComparator comparator, int init } this.comparator = comparator; - this.buckets = createBuckets(initialCapacity); + this.initialCapacity = initialCapacity; this.initialBucketCapacity = initialBucketCapacity; + this.buckets = createBuckets(initialCapacity); + this.threshold = (int)Math.floor(initialCapacity * LOAD_FACTOR); } /** @@ -381,9 +385,9 @@ public boolean removeAll(Collection c) { @Override public void clear() { - buckets = createBuckets(INITAL_CAPACITY); n = 0; - threshold = (int)Math.floor(INITAL_CAPACITY * LOAD_FACTOR); + buckets = createBuckets(this.initialCapacity); + threshold = (int)Math.floor(this.initialCapacity * LOAD_FACTOR); } @Override diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/FlexibleHashMap.java b/runtime/Java/src/org/antlr/v4/runtime/misc/FlexibleHashMap.java index 3c49eb2d0b..cc28bb0edc 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/FlexibleHashMap.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/FlexibleHashMap.java @@ -41,10 +41,12 @@ public String toString() { /** How many elements in set */ protected int n = 0; - protected int threshold = (int)(INITAL_CAPACITY * LOAD_FACTOR); // when to expand - protected int currentPrime = 1; // jump by 4 primes each expand or whatever - protected int initialBucketCapacity = INITAL_BUCKET_CAPACITY; + + /** when to expand */ + protected int threshold; + protected final int initialCapacity; + protected final int initialBucketCapacity; public FlexibleHashMap() { this(null, INITAL_CAPACITY, INITAL_BUCKET_CAPACITY); @@ -60,8 +62,10 @@ public FlexibleHashMap(AbstractEqualityComparator comparator, int ini } this.comparator = comparator; - this.buckets = createEntryListArray(initialBucketCapacity); + this.initialCapacity = initialCapacity; this.initialBucketCapacity = initialBucketCapacity; + this.threshold = (int)Math.floor(initialCapacity * LOAD_FACTOR); + this.buckets = createEntryListArray(initialBucketCapacity); } private static LinkedList>[] createEntryListArray(int length) { @@ -209,8 +213,9 @@ public boolean isEmpty() { @Override public void clear() { - buckets = createEntryListArray(INITAL_CAPACITY); + buckets = createEntryListArray(this.initialCapacity); n = 0; + threshold = (int)Math.floor(this.initialCapacity * LOAD_FACTOR); } @Override