Jump to content

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 = Arr.new;[]
var h = Hash.new;()
 
# hash phase
table1.each { |s|
h{s[index1]} := [] -><< append(s);
};
 
# 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 { .dump.say };</lang>
{{out}}
<pre>[[27, 'Jonah'], ['Jonah', 'Whales']]
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.