Anonymous user
Hash join: Difference between revisions
Updated D entry
(→{{header|Tcl}}: Corrected problems) |
(Updated D entry) |
||
Line 257:
auto hashJoin(size_t index1, size_t index2, T1, T2)
(in T1[] table1, in T2[] table2) pure /*nothrow*/
if (is(typeof(T1.init[index1]) == typeof(T2.init[index2]))) {
T1[][typeof(T1[index1])] h;▼
// Hash phase.
▲ T1[][typeof(T1.init[index1])] h;
foreach (const s; table1)
h[s[index1]] ~= s;
// Join phase.
Tuple!(const T1, const T2)[] result;
foreach (const r; table2)
foreach (const s; h.get(r[index2],
result ~= tuple(s, r);
return result;
}
Line 283 ⟶ 285:
T("Glory", "Buffy")];
foreach (const row; hashJoin!(1, 0)(table1, table2))
writefln("(%s, %5s) (%5s, %7s)", row[0][], row[1][]);
}</lang>
|