-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashCollisionChecker.java
29 lines (25 loc) · 926 Bytes
/
HashCollisionChecker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class HashCollisionChecker {
public static <T> int countOfUniqueHashCodes(HashSet<T> set) {
// TODO: Implement
return 0;
}
public static <K, V> int countOfUniqueHashCodes(HashMap<K, V> map) {
// TODO: Implement
return 0;
}
public static void main(String[] args) {
HashSet<String> set = new HashSet<>();
set.add("c#c#c#c#c#c#bBc#c#c#c#bBc#");
set.add("abcd");
set.add("c#c#c#c#c#c#bBc#c#c#c#c#aa");
set.add("1234");
set.add("c#c#c#c#c#c#bBc#c#c#c#c#bB");
System.out.println(countOfUniqueHashCodes(set)); // 3
HashMap<String, Integer> map = new HashMap<>();
map.put("c#c#c#c#c#c#c#aaaaaaaabBbB", 14);
map.put("c#c#c#c#c#c#c#aaaaaaaac#c#", 12);
map.put("c#c#c#c#c#c#c#aaaaaaaac#cc", 16);
System.out.println(countOfUniqueHashCodes(map)); // 2
}
}