Jump to content

Hash join: Difference between revisions

1,704 bytes added ,  6 years ago
no edit summary
(→‎{{header|AppleScript}}: Updated primitives)
No edit summary
Line 2,090:
28 : Alan : Ghosts
28 : Alan : Zombies</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>Structure tabA
age.i
name.s
EndStructure
 
Structure tabB
char_name.s
nemesis.s
EndStructure
 
NewList listA.tabA()
NewList listB.tabB()
 
Macro SetListA(c_age, c_name)
AddElement(listA()) : listA()\age = c_age : listA()\name = c_name
EndMacro
 
Macro SetListB(c_char, c_nem)
AddElement(listB()) : listB()\char_name = c_char : listB()\nemesis = c_nem
EndMacro
 
SetListA(27, "Jonah") : SetListA(18, "Alan") : SetListA(28, "Glory")
SetListA(18, "Popeye") : SetListA(28, "Alan")
 
SetListB("Jonah", "Whales") : SetListB("Jonah", "Spiders")
SetListB("Alan", "Ghosts") : SetListB("Alan", "Zombies")
SetListB("Glory", "Buffy")
 
If OpenConsole("Hash_join")
ForEach listA()
PrintN("Input A = "+Str(listA()\age)+~"\t"+listA()\name)
Next
PrintN("")
ForEach listB()
PrintN("Input B = "+listB()\char_name+~"\t"+listB()\nemesis)
Next
PrintN(~"\nOutput\nA.Age\tA.Name\tB.Char.\tB.Nemesis")
ForEach listA()
ForEach listB()
If listA()\name = listB()\char_name
PrintN(Str(listA()\age)+~"\t"+listA()\name+~"\t"+
listB()\char_name+~"\t"+listB()\nemesis)
EndIf
Next
Next
Input()
EndIf</lang>
{{out}}
<pre>Input A = 27 Jonah
Input A = 18 Alan
Input A = 28 Glory
Input A = 18 Popeye
Input A = 28 Alan
 
Input B = Jonah Whales
Input B = Jonah Spiders
Input B = Alan Ghosts
Input B = Alan Zombies
Input B = Glory Buffy
 
Output
A.Age A.Name B.Char. B.Nemesis
27 Jonah Jonah Whales
27 Jonah Jonah Spiders
18 Alan Alan Ghosts
18 Alan Alan Zombies
28 Glory Glory Buffy
28 Alan Alan Ghosts
28 Alan Alan Zombies</pre>
 
=={{header|Python}}==
164

edits

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