Hash join: Difference between revisions

→‎{{header|D}}: Add Déjà Vu example
(Updated D entry)
(→‎{{header|D}}: Add Déjà Vu example)
Line 296:
(28, Alan) ( Alan, Zombies)
(28, Glory) (Glory, Buffy)</pre>
 
=={{header|Déjà Vu}}==
{{trans|Python}}
<lang dejavu>hashJoin table1 index1 table2 index2:
local :h {}
# hash phase
for s in table1:
local :key s! index1
if not has h key:
set-to h key []
push-to h! key s
# join phase
[]
for r in table2:
for s in copy h! r! index2:
push-through swap [ s r ]
 
local :table1 [ [ 27 "Jonah" ] [ 18 "Alan" ] [ 28 "Glory" ] [ 18 "Popeye" ] [ 28 "Alan" ] ]
local :table2 [ [ "Jonah" "Whales" ] [ "Jonah" "Spiders" ] [ "Alan" "Ghosts" ] [ "Alan" "Zombies" ] [ "Glory" "Buffy" ] ]
 
for row in hashJoin table1 1 table2 0:
!. row</lang>
{{out}}
<pre>[ [ 27 "Jonah" ] [ "Jonah" "Whales" ] ]
[ [ 27 "Jonah" ] [ "Jonah" "Spiders" ] ]
[ [ 28 "Alan" ] [ "Alan" "Ghosts" ] ]
[ [ 18 "Alan" ] [ "Alan" "Ghosts" ] ]
[ [ 28 "Alan" ] [ "Alan" "Zombies" ] ]
[ [ 18 "Alan" ] [ "Alan" "Zombies" ] ]
[ [ 28 "Glory" ] [ "Glory" "Buffy" ] ]
</pre>
 
=={{header|Erlang}}==
Anonymous user