-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
33 lines (29 loc) · 825 Bytes
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <vector>
#include <map>
//g++ utils.cpp -O3 -fPIC -std=c++11 -shared -o cpputils.so
using namespace std;
extern "C" //Tells the compile to use C-linkage for the next scope.
{
void getColPairs(int N, int * nums, int * X, int * Y, int * Pa, int * Pb)
{
map<tuple<int, int>, int> D;
int cnt = 0;
for (int i = 0; i < N; i++)
{
int true_i = nums[i];
auto key_i = std::make_tuple (X[true_i], Y[true_i]);
if (D.count(key_i) == 0 || D[key_i] == -1)
{
D[key_i] = true_i;
} else
{
int true_j = D[key_i];
Pa[cnt] = true_i;
Pb[cnt] = true_j;
D[key_i] = -1;
cnt++;
}
}
}
}