I have two relations A and B, both with all integer attributes (A {a1,a2,a3,...} B{b1,b2,b3,..}. How would I hash-join these two in C++? The user will pick the two joining attributes.
What data structure should I use for this? I don't know how to start it.
I played with an example only and try to do it with arrays but I don't see it working like this.
2 vector<int> of varying size, A and B, constructed (lines 8, 10)
1 vector<pair<int,int>>, A_merge_B, whose size is the lower of the sizes of A and B is declared (12)
pairwise numbers are drawn from A, B and made into pair<int,int> using make_pair() (16, rhs)
These <int,int> pairs are then assigned to A_merge_B (16, lhs)
Each of the pairs is printed out (20)
An alternative that might be cheaper in as much as it avoids copying objects, and if you don't care about the final states of A and B, is to std::move the elements of A and B directly into A_merge_B: A_merge_B[i] = std::make_pair(move(A[i]), move(B[i])); A, B are left in an undefined state after the move operation however