From d492849cb2df61373707d0279c73268d8d4bb47d Mon Sep 17 00:00:00 2001 From: Tommy Ettinger Date: Sat, 30 Dec 2023 22:24:14 -0800 Subject: [PATCH] Cantor (even multiplied by phi) has no collisions. (At least up to a 10000x10000 square grid, with a load factor of 0.5f . Larger grids often exhaust the Java heap.) --- .../github/tommyettinger/ds/test/Coord.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/github/tommyettinger/ds/test/Coord.java b/src/test/java/com/github/tommyettinger/ds/test/Coord.java index d12c6699..2cb579ee 100644 --- a/src/test/java/com/github/tommyettinger/ds/test/Coord.java +++ b/src/test/java/com/github/tommyettinger/ds/test/Coord.java @@ -65,18 +65,21 @@ public int hashCode () { } private static int hash(int x, int y, int mask) { - return x * 0x17587 + y * 0x16A89 & mask; +// return x * 0x17587 + y * 0x16A89 & mask; + return (y + ((x + y) * (x + y + 1) >>> 1)) * 0x9E3779B9 & mask; } public static void main(String[] args) { - int LIMIT = 512; + int LIMIT = 10000; int collisions = 0; - IntSet ints = new IntSet(51, 0.7f){ - @Override - protected int place (int item) { - return item & mask; - } - }; - int mask = MathTools.nextPowerOfTwo((int)(LIMIT * LIMIT / 0.7f)) - 1; + IntSet ints = new IntSet(51, 0.5f) +// { +// @Override +// protected int place (int item) { +// return item & mask; +// } +// } + ; + int mask = MathTools.nextPowerOfTwo((int)(LIMIT * LIMIT / 0.5f)) - 1; ints.add(0); int latest; for (int shell = 1; shell < LIMIT; shell++) {