HashSet<int> nhs(hs); TEST_EQUAL(nhs.getSize(), 3) TEST_EQUAL(nhs.has(0), true) TEST_EQUAL(nhs.has(1), true) TEST_EQUAL(nhs.has(2), true) TEST_EQUAL(nhs.has(3), false) RESULT CHECK(void clear() throw()) HashSet<int> hs; hs.insert(0); hs.insert(1); hs.insert(2); hs.clear(); TEST_EQUAL(hs.getSize(), 0) TEST_EQUAL(hs.getCapacity(), 4) TEST_EQUAL(hs.getBucketSize(), 3) RESULT CHECK(void destroy() throw()) HashSet<int> hs; hs.insert(0); hs.insert(1); hs.insert(2); hs.destroy(); TEST_EQUAL(hs.getSize(), 0) TEST_EQUAL(hs.getCapacity(), 4) TEST_EQUAL(hs.getBucketSize(), 3) RESULT CHECK(void set(const HashSet& hash_set) throw())
int main() { int filesCount; cin >> filesCount; if (filesCount == 0) return 0; cin.ignore(); char** files = readFilesFromStdOut(filesCount); char* smallestFile = getSmallestFile(files, filesCount); HashSet* hs = initialize(smallestFile); for (int i = 0; i < filesCount; ++i) { char* currentFile = files[i]; // skip the smallest file if (!strcmp(currentFile, smallestFile)) continue; HashSet* intersection = new HashSet(hs->getCapacity()); ifstream is(currentFile); while (true) { uint_64 n; is.read((char*)&n, sizeof(uint_64)); if (is.eof()) break; if (hs->contains(n)) intersection->add(n); } is.close(); // If at some point the intersection is empty // we no longer have to check the other files if (intersection->isEmpty()) break; delete hs; // Swap the previous intersection with the new one hs = intersection; } // Write the output in binary file hs->serializeToFile("result.bin"); delete hs; for (int i = 0; i < filesCount; ++i) delete[] files[i]; delete[] files; delete[] smallestFile; system("pause"); return 0; };