mirror of
https://github.com/open-goal/jak-project.git
synced 2024-11-27 08:20:47 +00:00
6aa15c897f
oops, leads to some very confusing behaviour
23 lines
483 B
C++
23 lines
483 B
C++
#pragma once
|
|
|
|
#include <unordered_set>
|
|
|
|
namespace set_util {
|
|
template <typename T>
|
|
std::unordered_set<T> intersection(std::unordered_set<T> set1, std::unordered_set<T> set2) {
|
|
if (set2.size() < set1.size()) {
|
|
auto temp = set1;
|
|
set1 = set2;
|
|
set2 = temp;
|
|
}
|
|
std::unordered_set<T> m(set1.begin(), set1.end());
|
|
std::unordered_set<T> res;
|
|
for (auto a : set2)
|
|
if (m.count(a)) {
|
|
res.insert(a);
|
|
m.erase(a);
|
|
}
|
|
return res;
|
|
}
|
|
} // namespace set_util
|