RosettaCodeData/Task/Hash-join/Phix/hash-join.phix
2026-02-01 16:33:20 -08:00

29 lines
776 B
Text

with javascript_semantics
requires("1.0.6") -- (or use the pre-1.0.6 code below)
constant A = {{27,"Jonah"},
{18,"Alan"},
{28,"Glory"},
{18,"Popeye"},
{28,"Alan"}},
B = {{"Jonah","Whales"},
{"Jonah","Spiders"},
{"Alan", "Ghosts"},
{"Alan", "Zombies"},
{"Glory","Buffy"}},
jA = 2, -- (join A index)
jB = 1, -- (join B index)
MB = new_dict()
sequence C = {}
for b in B do
object key = b[jB],
data = getdd(key,{},MB,true) -- 1.0.6+
data = append(data,b)
putd(key,data,MB)
end for
for a in A do
for d in getdd(a[jA],{},MB) do
C = append(C,{a,d})
end for
end for
destroy_dict(MB)
pp(C,{pp_Nest,1})