Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Calculate a hash code for a pair of coordinates
- * @return The hashcode
- * @author REghZy
- */
- public static int hash(int x, int y) {
- // 15.8M/16M collisions
- // return this.hash = (this.x * 31) ^ (68 + this.y);
- // 15.3M/16M collisions
- // return this.hash = (this.x * 0x1f1f1f1f) ^ (this.y);
- // 8000/16M collisions
- // int hash = 'X';
- // hash = (31 * hash) + ':';
- // hash = aggregateHash(hash, Integer.toString(x));
- // hash = (31 * hash) + 'Y';
- // hash = (31 * hash) + ':';
- // hash = aggregateHash(hash, Integer.toString(y));
- // return hash;
- // return new StringBuilder(24).append("X:").append(x).append("Y:").append(y).toString().hashCode();
- // 8M/16M collisions
- // return (x * 0x101DEAD) ^ (y);
- // 2.6M/16M collisions
- return (x * 0x101DEAD) ^ (y * 0xBEEF);
- }
- public static void main(String[] args) throws IOException, InterruptedException {
- int collisions = 0, totazzl = 0;
- int w = 2000, d = 2000;
- HashMap<Integer, String> aaaamap = new HashMap<Integer, String>((w*d) * 5);
- for(int x = -w; x < w; x++) {
- for (int z = -d; z < d; z++) {
- int hash = hash(x, z);
- if (aaaamap.put(hash, "") != null) {
- collisions++;
- if (collisions < 20) {
- System.out.println(RZFormats.format("Collision: {0},{1} ({2})", x, z, hash(x, z)));
- }
- }
- totazzl++;
- }
- }
- System.out.println(collisions + " / " + totazzl + " collisions");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement