Last active
November 21, 2015 02:39
-
-
Save pauljurczak/155c995202ab04c8246f 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
int setIntersectionBenchmarkLoopOpt1() | |
{ | |
const int nBags = 1000; | |
const int maxBagLength = 10; | |
vector<set<int>> bags; | |
ifstream input("10000ran.dat"); // http://www.agner.org/random/10000ran.zip | |
int similarity = 0; | |
bags.reserve(nBags); | |
for (int iBag = 0; iBag < nBags; ++iBag) { | |
bags.push_back(set<int>()); | |
for (int j = 0; j < maxBagLength; ++j) { | |
string number; | |
getline(input, number, ','); | |
bags.back().insert(round(atof(number.c_str())*maxBagLength)); | |
} | |
} | |
set<int> intersec; | |
for (int i = 0; i < bags.size(); ++i) | |
for (int j = i+1; j < bags.size(); ++j) { | |
intersec.clear(); | |
set_intersection(bags[i].begin(), bags[i].end(), bags[j].begin(), bags[j].end(), inserter(intersec, intersec.begin())); | |
similarity += intersec.size(); | |
} | |
return similarity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment