Created
November 20, 2015 19:07
-
-
Save pauljurczak/ee310ba49d9b26da9a5f 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
static int setIntersectionBenchmark() throws java.io.IOException { | |
final int nBags = 1000; | |
final int maxBagLength = 10; | |
Scanner scanner = new Scanner(new File("10000ran.dat")); | |
ArrayList<HashSet<Integer>> bags = new ArrayList<HashSet<Integer>>(nBags); | |
int similarity = 0; | |
scanner.useDelimiter(",\\s*"); | |
for (int iBag = 0; iBag < nBags; ++iBag) { | |
HashSet<Integer> bag = new HashSet<Integer>(maxBagLength); | |
for (int j = 0; j < maxBagLength; ++j) | |
bag.add(round(scanner.nextFloat()*maxBagLength)); | |
bags.add(bag); | |
} | |
scanner.close(); | |
for (int i = 0; i < nBags; ++i) | |
for (int j = i+1; j < nBags; ++j) { | |
HashSet<Integer> s = new HashSet<Integer>(bags.get(i)); | |
s.retainAll(bags.get(j)); | |
similarity += s.size(); | |
} | |
return similarity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment