Hash join: Difference between revisions
→{{header|TXR}}: Updated code. Works with TXR 76 and up which provides the group-by function.
(→{{header|TXR}}: group-by solution.) |
(→{{header|TXR}}: Updated code. Works with TXR 76 and up which provides the group-by function.) |
||
Line 881:
=={{header|TXR}}==
Generic hash join. Arguments <code>left-key</code> and <code>right-key</code> are functions applied to the elements of the <code>left</code> and <code>right</code> sequences to retrieve the join key.
<lang txr>@(do
Line 888 ⟶ 890:
(18 Popeye)
(28 Alan)))
(defvar nemesis-name '((Jonah Whales)
(Jonah Spiders)
Line 893 ⟶ 896:
(Alan Zombies)
(Glory Buffy)))
(defun hash-join (left left-key right right-key)
(append-each ((r-entry right)) ;; join phase
(collect-each ((l-entry [join-hash [right-key r-entry]]))
(format t "~s\n" [hash-join age-name second nemesis-name first]))
▲ '(,age ,name ,nemesis)))))
</lang>
Line 912 ⟶ 909:
<pre>$ txr hash-join.txr
((27 Jonah Whales) (27 Jonah Spiders) (28 Alan Ghosts) (18 Alan Ghosts) (28 Alan Zombies) (18 Alan Zombies) (28 Glory Buffy))</pre>▼
▲(((27 Jonah) (Jonah Whales)) ((27 Jonah) (Jonah Spiders)) (
|