Skip to content

Commit

Permalink
Cantor (even multiplied by phi) has no collisions.
Browse files Browse the repository at this point in the history
(At least up to a 10000x10000 square grid, with a load factor of 0.5f . Larger grids often exhaust the Java heap.)
  • Loading branch information
tommyettinger committed Dec 31, 2023
1 parent 2b9bf83 commit d492849
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/test/java/com/github/tommyettinger/ds/test/Coord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit d492849

Please sign in to comment.