Ranides Atterwim %!s(int64=11) %!d(string=hai) anos
pai
achega
6c91d3cf6e

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1396 - 1399
assira/src/main/java/net/ranides/assira/collection/lookups/AVLTreeLookup.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1061 - 1058
assira/src/main/java/net/ranides/assira/collection/lookups/CustomLookup.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1047 - 1035
assira/src/main/java/net/ranides/assira/collection/lookups/HashLookup.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1511 - 1514
assira/src/main/java/net/ranides/assira/collection/lookups/RBTreeLookup.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1383 - 1386
assira/src/main/java/net/ranides/assira/collection/maps/AVLTreeMap.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 951 - 946
assira/src/main/java/net/ranides/assira/collection/maps/CustomMap.java


+ 1 - 4
assira/src/main/java/net/ranides/assira/collection/maps/IntAVLTreeMap.java

@@ -96,16 +96,13 @@ public class IntAVLTreeMap<V> extends IntSortedMap<V> implements java.io.Seriali
      */
     protected transient IntComparator actualComparator;
 
-    {
-        allocatePaths();
-    }
-
     /**
      * Creates a new empty tree map.
      */
     public IntAVLTreeMap() {
         tree = null;
         count = 0;
+        allocatePaths();
     }
 
     /**

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2209 - 2212
assira/src/main/java/net/ranides/assira/collection/maps/IntRBTreeMap.java


+ 28 - 79
assira/src/main/java/net/ranides/assira/collection/maps/RBTreeMap.java

@@ -58,10 +58,6 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
     
     protected transient RBEntry<K, V> nodePath[];
 
-    {
-        allocatePaths();
-    }
-
     /**
      * Creates a new empty tree map.
      */
@@ -78,6 +74,7 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
         super(comparator);
         tree = null;
         count = 0;
+        allocatePaths();
     }
 
     /**
@@ -180,12 +177,12 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
     
     @Override
     protected ListIterator<Entry<K, V>> entryIterator() {
-        return new EntryIterator(); 
+        return new TreeIterator(); 
     }
 
     @Override
     protected ListIterator<Entry<K, V>> entryIterator(K begin) {
-        return new EntryIterator(begin);
+        return new TreeIterator(begin);
     }
 
     @Override
@@ -644,11 +641,11 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
     
     private void writeObject(java.io.ObjectOutputStream ostream) throws java.io.IOException {
         int n = count;
-        EntryIterator iterator = new EntryIterator();
+        TreeIterator iterator = new TreeIterator();
         RBEntry<K, V> entry;
         ostream.defaultWriteObject();
         while (n-- != 0) {
-            entry = iterator.nextEntry();
+            entry = iterator.next();
             ostream.writeObject(entry.key);
             ostream.writeObject(entry.value);
         }
@@ -977,7 +974,7 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
 
     
 
-    private abstract class TreeIterator<T> extends AListIterator<T> {
+    private class TreeIterator extends AListIterator<Entry<K, V>> {
 
         /**
          * The entry that will be returned by the next call to
@@ -1018,6 +1015,16 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
             }
         }
 
+        @Override
+        public void set(Entry<K, V> object) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void add(Entry<K, V> object) {
+            throw new UnsupportedOperationException();
+        }
+
         @Override
         public boolean hasNext() {
             return next != null;
@@ -1032,7 +1039,8 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
             next = next.next();
         }
 
-        RBEntry<K, V> nextEntry() {
+        @Override
+        public RBEntry<K, V> next() {
             if (!hasNext()) {
                 throw new NoSuchElementException();
             }
@@ -1046,7 +1054,8 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
             prev = prev.prev();
         }
 
-        RBEntry<K, V> previousEntry() {
+        @Override
+        public RBEntry<K, V> previous() {
             if (!hasPrevious()) {
                 throw new NoSuchElementException();
             }
@@ -1086,7 +1095,7 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
         public int skip(int n) {
             int i = n;
             while (i-- != 0 && hasNext()) {
-                nextEntry();
+                next();
             }
             return n - i - 1;
         }
@@ -1094,43 +1103,12 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
         public int back(int n) {
             int i = n;
             while (i-- != 0 && hasPrevious()) {
-                previousEntry();
+                previous();
             }
             return n - i - 1;
         }
     }
 
-    private class EntryIterator extends TreeIterator<Entry<K, V>> {
-
-        EntryIterator() {
-        }
-
-        EntryIterator(K key) {
-            super(key);
-        }
-
-        @Override
-        public Entry<K, V> next() {
-            return nextEntry();
-        }
-
-        @Override
-        public Entry<K, V> previous() {
-            return previousEntry();
-        }
-
-        @Override
-        public void set(Entry<K, V> object) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void add(Entry<K, V> object) {
-            throw new UnsupportedOperationException();
-        }
-    }
-
-    
     
     private final class Submap extends ASubmap implements java.io.Serializable {
 
@@ -1203,21 +1181,21 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
 
         @Override
         protected ListIterator<Entry<K, V>> entryIterator() {
-            return new SubmapEntryIterator();
+            return new SubTreeIterator();
         }
 
         @Override
         protected ListIterator<Entry<K, V>> entryIterator(K begin) {
-            return new SubmapEntryIterator(begin);
+            return new SubTreeIterator(begin);
         }
-        
-        private abstract class SubmapIterator<T> extends TreeIterator<T> {
 
-            SubmapIterator() {
+        private class SubTreeIterator extends TreeIterator {
+
+            SubTreeIterator() {
                 next = firstEntry();
             }
 
-            SubmapIterator(K key) {
+            SubTreeIterator(K key) {
                 this();
                 if (next != null) {
                     if (!bottom && compare(key, next.key) < 0) {
@@ -1251,36 +1229,7 @@ public final class RBTreeMap<K, V> extends ASortedMap<K, V> implements java.io.S
                     next = null;
                 }
             }
-        }
-
-        private class SubmapEntryIterator extends SubmapIterator<Entry<K, V>> {
 
-            SubmapEntryIterator() {
-            }
-
-            SubmapEntryIterator(K key) {
-                super(key);
-            }
-
-            @Override
-            public Entry<K, V> next() {
-                return nextEntry();
-            }
-
-            @Override
-            public Entry<K, V> previous() {
-                return previousEntry();
-            }
-
-            @Override
-            public void set(Entry<K, V> object) {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override
-            public void add(Entry<K, V> object) {
-                throw new UnsupportedOperationException();
-            }
         }
 
     }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1526 - 1529
assira/src/main/java/net/ranides/assira/collection/sets/AVLTreeSet.java


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 654 - 648
assira/src/main/java/net/ranides/assira/collection/sets/CustomSet.java


+ 1 - 4
assira/src/main/java/net/ranides/assira/collection/sets/IntAVLTreeSet.java

@@ -81,16 +81,13 @@ public class IntAVLTreeSet extends IntSortedSet implements java.io.Serializable
      */
     protected transient boolean dirPath[];
 
-    {
-        allocatePaths();
-    }
-
     /**
      * Creates a new empty tree set.
      */
     public IntAVLTreeSet() {
         tree = null;
         count = 0;
+        allocatePaths();
     }
 
     /**

+ 1 - 4
assira/src/main/java/net/ranides/assira/collection/sets/IntRBTreeSet.java

@@ -84,10 +84,6 @@ public class IntRBTreeSet extends IntSortedSet implements java.io.Serializable {
     protected transient boolean dirPath[];
     
     protected transient Entry nodePath[];
-    
-    {
-        allocatePaths();
-    }
 
     /**
      * Creates a new empty tree set.
@@ -95,6 +91,7 @@ public class IntRBTreeSet extends IntSortedSet implements java.io.Serializable {
     public IntRBTreeSet() {
         tree = null;
         count = 0;
+        allocatePaths();
     }
 
     /**

+ 1 - 4
assira/src/main/java/net/ranides/assira/collection/sets/RBTreeSet.java

@@ -74,16 +74,13 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
     
     protected transient Entry<K> nodePath[];
 
-    {
-        allocatePaths();
-    }
-
     /**
      * Creates a new empty tree set.
      */
     public RBTreeSet() {
         tree = null;
         count = 0;
+        allocatePaths();
     }
 
     /**

+ 140 - 139
assira/src/main/java/net/ranides/assira/collection/utils/HashCollection.java

@@ -1,140 +1,141 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
-package net.ranides.assira.collection.utils;
-
-import net.ranides.assira.math.MathUtils;
-
-public final class HashCollection {
-
-    private HashCollection() {
-        // utility class
-    }
-    /**
-     * The initial default size of a hash table.
-     */
-    public static final int INITIAL_SIZE = 16;
-    /**
-     * The default load factor of a hash table.
-     */
-    public static final float LOAD_FACTOR = .75f;
-    /**
-     * The load factor for a (usually small) table that is meant to be
-     * particularly fast.
-     */
-    public static final float LOAD_FACTOR_FAST = .5f;
-    /**
-     * The load factor for a (usually very small) table that is meant to be
-     * extremely fast.
-     */
-    public static final float LOAD_FACTOR_VFAST = .25f;
-    
-    /**
-     * The default growth factor of a hash table.
-     */
-    public static final int GROWTH_FACTOR = 16;
-    /**
-     * The state of a free hash table entry.
-     */
-    public static final byte FREE = 0;
-    /**
-     * The state of a occupied hash table entry.
-     */
-    public static final byte OCCUPIED = -1;
-    /**
-     * The state of a hash table entry freed by a deletion.
-     */
-    public static final byte REMOVED = 1;
-    
-    /**
-     * A list of primes to be used as table sizes. The <var>i</var>-th element
-     * is the largest prime <var>p</var> smaller than
-     * 2<sup>(<var>i</var>+28)/16</sup>
-     * and such that <var>p</var>-2 is also prime (or 1, for the first few
-     * entries).
-     */
-    public static final int PRIMES[] = {
-        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13, 19, 19, 19, 19, 19,
-        19, 19, 19, 19, 19, 19, 19, 31, 31, 31, 31, 31, 31, 31, 43, 43, 43, 43, 43,
-        43, 43, 43, 61, 61, 61, 61, 61, 73, 73, 73, 73, 73, 73, 73, 103, 103, 109,
-        109, 109, 109, 109, 139, 139, 151, 151, 151, 151, 181, 181, 193, 199, 199,
-        199, 229, 241, 241, 241, 271, 283, 283, 313, 313, 313, 349, 349, 349, 349,
-        421, 433, 463, 463, 463, 523, 523, 571, 601, 619, 661, 661, 661, 661, 661,
-        823, 859, 883, 883, 883, 1021, 1063, 1093, 1153, 1153, 1231, 1321, 1321,
-        1429, 1489, 1489, 1621, 1699, 1789, 1873, 1951, 2029, 2131, 2143, 2311,
-        2383, 2383, 2593, 2731, 2803, 3001, 3121, 3259, 3391, 3583, 3673, 3919,
-        4093, 4273, 4423, 4651, 4801, 5023, 5281, 5521, 5743, 5881, 6301, 6571,
-        6871, 7129, 7489, 7759, 8089, 8539, 8863, 9283, 9721, 10141, 10531, 11071,
-        11551, 12073, 12613, 13009, 13759, 14323, 14869, 15649, 16363, 17029,
-        17839, 18541, 19471, 20233, 21193, 22159, 23059, 24181, 25171, 26263,
-        27541, 28753, 30013, 31321, 32719, 34213, 35731, 37309, 38923, 40639,
-        42463, 44281, 46309, 48313, 50461, 52711, 55051, 57529, 60091, 62299,
-        65521, 68281, 71413, 74611, 77713, 81373, 84979, 88663, 92671, 96739,
-        100801, 105529, 109849, 115021, 120079, 125509, 131011, 136861, 142873,
-        149251, 155863, 162751, 169891, 177433, 185071, 193381, 202129, 211063,
-        220021, 229981, 240349, 250969, 262111, 273643, 285841, 298411, 311713,
-        325543, 339841, 355009, 370663, 386989, 404269, 422113, 440809, 460081,
-        480463, 501829, 524221, 547399, 571603, 596929, 623353, 651019, 679909,
-        709741, 741343, 774133, 808441, 844201, 881539, 920743, 961531, 1004119,
-        1048573, 1094923, 1143283, 1193911, 1246963, 1302181, 1359733, 1420039,
-        1482853, 1548541, 1616899, 1688413, 1763431, 1841293, 1922773, 2008081,
-        2097133, 2189989, 2286883, 2388163, 2493853, 2604013, 2719669, 2840041,
-        2965603, 3097123, 3234241, 3377191, 3526933, 3682363, 3845983, 4016041,
-        4193803, 4379719, 4573873, 4776223, 4987891, 5208523, 5439223, 5680153,
-        5931313, 6194191, 6468463, 6754879, 7053331, 7366069, 7692343, 8032639,
-        8388451, 8759953, 9147661, 9552733, 9975193, 10417291, 10878619, 11360203,
-        11863153, 12387841, 12936529, 13509343, 14107801, 14732413, 15384673,
-        16065559, 16777141, 17519893, 18295633, 19105483, 19951231, 20834689,
-        21757291, 22720591, 23726449, 24776953, 25873963, 27018853, 28215619,
-        29464579, 30769093, 32131711, 33554011, 35039911, 36591211, 38211163,
-        39903121, 41669479, 43514521, 45441199, 47452879, 49553941, 51747991,
-        54039079, 56431513, 58930021, 61539091, 64263571, 67108669, 70079959,
-        73182409, 76422793, 79806229, 83339383, 87029053, 90881083, 94906249,
-        99108043, 103495879, 108077731, 112863013, 117860053, 123078019, 128526943,
-        134217439, 140159911, 146365159, 152845393, 159612601, 166679173,
-        174058849, 181765093, 189812341, 198216103, 206991601, 216156043,
-        225726379, 235720159, 246156271, 257054491, 268435009, 280319203,
-        292730833, 305691181, 319225021, 333358513, 348117151, 363529759,
-        379624279, 396432481, 413983771, 432312511, 451452613, 471440161,
-        492312523, 514109251, 536870839, 560640001, 585461743, 611382451,
-        638450569, 666717199, 696235363, 727060069, 759249643, 792864871,
-        827967631, 864625033, 902905501, 942880663, 984625531, 1028218189,
-        1073741719, 1121280091, 1170923713, 1222764841, 1276901371, 1333434301,
-        1392470281, 1454120779, 1518500173, 1585729993, 1655935399, 1729249999,
-        1805811253, 1885761133, 1969251079, 2056437379, 2147482951};
-
-    /**
-     * Returns the maximum number of entries that can be filled before
-     * rehashing.
-     *
-     * @param n the size of the backing array.
-     * @param f the load factor.
-     * @return the maximum number of entries before rehashing.
-     */
-    public static int arrayfill(int n, float f) {
-        return (int) Math.ceil(n * f);
-    }
-
-    /**
-     * Returns the least power of two smaller than or equal to 2<sup>30</sup>
-     * and larger than or equal to
-     * <code>Math.ceil( expected / f )</code>.
-     *
-     * @param expected the expected number of elements in a hash table.
-     * @param f the load factor.
-     * @return the minimum possible size for a backing array.
-     * @throws IllegalArgumentException if the necessary size is larger than
-     * 2<sup>30</sup>.
-     */
-    public static int arraysize(int expected, float f) {
-        final long s = MathUtils.pow2next((long) Math.ceil(expected / f));
-        if (s > (1 << 30)) {
-            throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")");
-        }
-        return (int) s;
-    }
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.collection.utils;
+
+import net.ranides.assira.math.MathUtils;
+
+public final class HashCollection {
+
+    private HashCollection() {
+        // utility class
+    }
+    /**
+     * The initial default size of a hash table.
+     */
+    public static final int INITIAL_SIZE = 16;
+    /**
+     * The default load factor of a hash table.
+     */
+    public static final float LOAD_FACTOR = .75f;
+    /**
+     * The load factor for a (usually small) table that is meant to be
+     * particularly fast.
+     */
+    public static final float LOAD_FACTOR_FAST = .5f;
+    /**
+     * The load factor for a (usually very small) table that is meant to be
+     * extremely fast.
+     */
+    public static final float LOAD_FACTOR_VFAST = .25f;
+    
+    /**
+     * The default growth factor of a hash table.
+     */
+    public static final int GROWTH_FACTOR = 16;
+    /**
+     * The state of a free hash table entry.
+     */
+    public static final byte FREE = 0;
+    /**
+     * The state of a occupied hash table entry.
+     */
+    public static final byte OCCUPIED = -1;
+    /**
+     * The state of a hash table entry freed by a deletion.
+     */
+    public static final byte REMOVED = 1;
+    
+    /**
+     * A list of primes to be used as table sizes. The <var>i</var>-th element
+     * is the largest prime <var>p</var> smaller than
+     * 2<sup>(<var>i</var>+28)/16</sup>
+     * and such that <var>p</var>-2 is also prime (or 1, for the first few
+     * entries).
+     */
+    public static final int PRIMES[] = {
+        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 7, 7, 7,
+        7, 7, 7, 7, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13, 19, 19, 19, 19, 19,
+        19, 19, 19, 19, 19, 19, 19, 31, 31, 31, 31, 31, 31, 31, 43, 43, 43, 43, 43,
+        43, 43, 43, 61, 61, 61, 61, 61, 73, 73, 73, 73, 73, 73, 73, 103, 103, 109,
+        109, 109, 109, 109, 139, 139, 151, 151, 151, 151, 181, 181, 193, 199, 199,
+        199, 229, 241, 241, 241, 271, 283, 283, 313, 313, 313, 349, 349, 349, 349,
+        421, 433, 463, 463, 463, 523, 523, 571, 601, 619, 661, 661, 661, 661, 661,
+        823, 859, 883, 883, 883, 1021, 1063, 1093, 1153, 1153, 1231, 1321, 1321,
+        1429, 1489, 1489, 1621, 1699, 1789, 1873, 1951, 2029, 2131, 2143, 2311,
+        2383, 2383, 2593, 2731, 2803, 3001, 3121, 3259, 3391, 3583, 3673, 3919,
+        4093, 4273, 4423, 4651, 4801, 5023, 5281, 5521, 5743, 5881, 6301, 6571,
+        6871, 7129, 7489, 7759, 8089, 8539, 8863, 9283, 9721, 10141, 10531, 11071,
+        11551, 12073, 12613, 13009, 13759, 14323, 14869, 15649, 16363, 17029,
+        17839, 18541, 19471, 20233, 21193, 22159, 23059, 24181, 25171, 26263,
+        27541, 28753, 30013, 31321, 32719, 34213, 35731, 37309, 38923, 40639,
+        42463, 44281, 46309, 48313, 50461, 52711, 55051, 57529, 60091, 62299,
+        65521, 68281, 71413, 74611, 77713, 81373, 84979, 88663, 92671, 96739,
+        100801, 105529, 109849, 115021, 120079, 125509, 131011, 136861, 142873,
+        149251, 155863, 162751, 169891, 177433, 185071, 193381, 202129, 211063,
+        220021, 229981, 240349, 250969, 262111, 273643, 285841, 298411, 311713,
+        325543, 339841, 355009, 370663, 386989, 404269, 422113, 440809, 460081,
+        480463, 501829, 524221, 547399, 571603, 596929, 623353, 651019, 679909,
+        709741, 741343, 774133, 808441, 844201, 881539, 920743, 961531, 1004119,
+        1048573, 1094923, 1143283, 1193911, 1246963, 1302181, 1359733, 1420039,
+        1482853, 1548541, 1616899, 1688413, 1763431, 1841293, 1922773, 2008081,
+        2097133, 2189989, 2286883, 2388163, 2493853, 2604013, 2719669, 2840041,
+        2965603, 3097123, 3234241, 3377191, 3526933, 3682363, 3845983, 4016041,
+        4193803, 4379719, 4573873, 4776223, 4987891, 5208523, 5439223, 5680153,
+        5931313, 6194191, 6468463, 6754879, 7053331, 7366069, 7692343, 8032639,
+        8388451, 8759953, 9147661, 9552733, 9975193, 10417291, 10878619, 11360203,
+        11863153, 12387841, 12936529, 13509343, 14107801, 14732413, 15384673,
+        16065559, 16777141, 17519893, 18295633, 19105483, 19951231, 20834689,
+        21757291, 22720591, 23726449, 24776953, 25873963, 27018853, 28215619,
+        29464579, 30769093, 32131711, 33554011, 35039911, 36591211, 38211163,
+        39903121, 41669479, 43514521, 45441199, 47452879, 49553941, 51747991,
+        54039079, 56431513, 58930021, 61539091, 64263571, 67108669, 70079959,
+        73182409, 76422793, 79806229, 83339383, 87029053, 90881083, 94906249,
+        99108043, 103495879, 108077731, 112863013, 117860053, 123078019, 128526943,
+        134217439, 140159911, 146365159, 152845393, 159612601, 166679173,
+        174058849, 181765093, 189812341, 198216103, 206991601, 216156043,
+        225726379, 235720159, 246156271, 257054491, 268435009, 280319203,
+        292730833, 305691181, 319225021, 333358513, 348117151, 363529759,
+        379624279, 396432481, 413983771, 432312511, 451452613, 471440161,
+        492312523, 514109251, 536870839, 560640001, 585461743, 611382451,
+        638450569, 666717199, 696235363, 727060069, 759249643, 792864871,
+        827967631, 864625033, 902905501, 942880663, 984625531, 1028218189,
+        1073741719, 1121280091, 1170923713, 1222764841, 1276901371, 1333434301,
+        1392470281, 1454120779, 1518500173, 1585729993, 1655935399, 1729249999,
+        1805811253, 1885761133, 1969251079, 2056437379, 2147482951};
+
+    /**
+     * Returns the maximum number of entries that can be filled before
+     * rehashing.
+     *
+     * @param n the size of the backing array.
+     * @param f the load factor.
+     * @return the maximum number of entries before rehashing.
+     */
+    public static int arrayfill(int n, float f) {
+        return (int) Math.ceil(n * f);
+    }
+
+    /**
+     * Returns the least power of two smaller than or equal to 2<sup>30</sup>
+     * and larger than or equal to
+     * <code>Math.ceil( expected / f )</code>.
+     *
+     * @param expected the expected number of elements in a hash table.
+     * @param f the load factor.
+     * @return the minimum possible size for a backing array.
+     * @throws IllegalArgumentException if the necessary size is larger than
+     * 2<sup>30</sup>.
+     */
+    public static int arraysize(int expected, float f) {
+        final long s = MathUtils.pow2next((long) Math.ceil(expected / f));
+        if (s > (1 << 30)) {
+            throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")");
+        }
+        return (int) s;
+    }
+
 }