lib/std: better policy for enlarging HashCollection
authorJean Privat <jean@pryen.org>
Wed, 6 Aug 2014 19:32:55 +0000 (15:32 -0400)
committerJean Privat <jean@pryen.org>
Thu, 7 Aug 2014 00:01:34 +0000 (20:01 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/hash_collection.nit

index c2c8353..2def742 100644 (file)
@@ -91,9 +91,13 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]]
                # Enlarge if needed
                var l = _length
                _length = l + 1
-               l = (l + 5) * 3 / 2
+
+               # Magic values determined empirically
+               # We do not want to enlarge too much
+               # We also want a odd capacity so that the modulo is more distributive
+               l = (l + 5) * 2 + 1
                if l >= _capacity then
-                       enlarge(l * 2)
+                       enlarge(l * 3 / 2 + 1)
                end
        end