-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
70 lines (65 loc) · 1.92 KB
/
Main.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;
public class Main
{
public static void main(String[] args)
{
final int listSize = 20000;
final int maxSetSize = 20;
final int maxSetValue = 100;
//Generate list of HashSets
LinkedList<ExtendedHashSet<Integer>> list = new LinkedList<ExtendedHashSet<Integer>>();
Random rand = new Random(System.currentTimeMillis());
for(int i = 0; i < listSize; i++)
{
ExtendedHashSet<Integer> set = new ExtendedHashSet<Integer>();
int maxIndex = rand.nextInt(maxSetSize - 3) + 3;
for(int j = 0; j < maxIndex; j++)
{
set.add(rand.nextInt(maxSetValue));
}
list.add(set);
}
//run sample for ExtendedHashSet
long start = System.currentTimeMillis();
long subsetCount = 0;
for(ExtendedHashSet<Integer> setA : list)
{
for(ExtendedHashSet<Integer> setB : list)
{
if(setB.isSubsetOf(setA))
{
subsetCount++;
}
}
}
System.out.println("ExtendedHashSet:\nSubset search completed in " + (System.currentTimeMillis() - start) + " milliseconds with " + subsetCount + " Subsets Found\n");
//run sample for Normal HashSet
start = System.currentTimeMillis();
subsetCount = 0;
for(HashSet<Integer> setA : list)
{
for(HashSet<Integer> setB : list)
{
if(setB.size() <= setA.size())
{
if(setA.containsAll(setB))
{
subsetCount++;
}
}
}
}
System.out.println("HasheSet:\nSubset search completed in " + (System.currentTimeMillis() - start) + " milliseconds with " + subsetCount + " Subsets Found\n");
}
public static String generateString(Random rng, String characters, int length)
{
char[] text = new char[length];
for (int i = 0; i < length; i++)
{
text[i] = characters.charAt(rng.nextInt(characters.length()));
}
return new String(text);
}
}