#pragma once #include #include #include #include #include #include #include using namespace std; /** * @brief Function that generates the next combination of k elements from a set of n elements */ bool nextComb(vector &indices, int n) { int k = indices.size(); int i = n - 1; int j = k - 1; while (indices[j] == i) { if (j == 0) return 1; i--; j--; } indices[j]++; for (int l = 0; l <= k - j - 1; l++) { indices[j + l] = indices[j] + l; } return 0; } /** * @brief Function that returns the intersection of two sets */ template unordered_set intersectSets(unordered_set s1, unordered_set s2) { unordered_set s; if (s1.size() <= s2.size()) { for (auto &el : s1) { if (s2.find(el) != s2.end()) { s.insert(el); } } } else { for (auto &el : s2) { if (s1.find(el) != s1.end()) { s.insert(el); } } } return s; } /** * @brief Function that shuffles the keys of a map and returns them in a vector * * @param map: the map to shuffle * @param seed: the seed for the random number generator */ template vector getShuffleKeys(unordered_map map, long seed) { if (seed != -1) srand(seed); else srand(time(NULL)); vector output; for (auto& pair : map) { output.push_back(pair.first); } random_shuffle(output.begin(), output.end()); return output; }