Hash join: Difference between revisions
m
→{{header|Sidef}}: minor code simplifications
(→{{header|Perl 6}}: further simplify the code) |
m (→{{header|Sidef}}: minor code simplifications) |
||
Line 1,956:
=={{header|Sidef}}==
<lang ruby>func hashJoin(table1, index1, table2, index2) {
var a =
var h = Hash
# hash phase
table1.each { |s|
h{s[index1]} := []
}
# join phase
table2.each { |r|
a += h{r[index2]}.map{[_,r]}
}
return a
}
Line 1,976:
[28, "Glory"],
[18, "Popeye"],
[28, "Alan"]]
var t2 = [["Jonah", "Whales"],
Line 1,982:
["Alan", "Ghosts"],
["Alan", "Zombies"],
["Glory", "Buffy"]]
hashJoin(t1, 1, t2, 0).each {
{{out}}
<pre>[[27, 'Jonah'], ['Jonah', 'Whales']]
|