Created
May 19, 2017 10:26
-
-
Save ivmos/8657c533540b3965b6b8d925a8fecad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// More about hash code | |
import java.util.*; | |
import java.lang.*; | |
public class Example | |
{ | |
public int x; | |
public Example(int x) { | |
this.x = x; | |
} | |
public static void main(String[] args) | |
{ | |
Set<Example> set = new HashSet<>(); | |
long startTime = System.nanoTime(); | |
Example last = null; | |
for (int i=0; i < 10; i++) { | |
last = new Example(i); | |
set.add(last); | |
} | |
long estimatedTime = System.nanoTime() - startTime; | |
System.out.println(set.size()); | |
System.out.println((double)estimatedTime / 1000000000.0); | |
Example other = new Example(-1); | |
System.out.println(set.contains(other)); | |
} | |
public int hashCode() { | |
return 2; | |
} | |
public boolean equals(Object a) { | |
Example aE = (Example) a; | |
System.out.println("equals " + this.x + " " + aE.x); | |
return super.equals(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment