Hash join: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|TXR}}: Drop @(do ...)) |
||
Line 1,737: | Line 1,737: | ||
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. |
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 |
|||
⚫ | |||
⚫ | |||
(28 Glory) |
|||
(18 Popeye) |
|||
(28 Alan))) |
|||
⚫ | |||
(defvar nemesis-name '((Jonah Whales) |
|||
(Jonah Spiders) |
|||
(Alan Ghosts) |
|||
(Alan Zombies) |
|||
(Glory Buffy))) |
|||
(defun hash-join (left left-key right right-key) |
|||
(let ((join-hash [group-by left-key left])) ;; hash phase |
|||
(append-each ((r-entry right)) ;; join phase |
|||
(collect-each ((l-entry [join-hash [right-key r-entry]])) |
|||
^(,l-entry ,r-entry))))) |
|||
(format t "~s\n" [hash-join age-name second nemesis-name first])</lang> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>$ txr hash-join. |
<pre>$ txr hash-join.tl |
||
(((27 Jonah) (Jonah Whales)) ((27 Jonah) (Jonah Spiders)) ((18 Alan) (Alan Ghosts)) ((28 Alan) (Alan Ghosts)) ((18 Alan) (Alan Zombies)) ((28 Alan) (Alan Zombies)) ((28 Glory) (Glory Buffy)))</pre> |
(((27 Jonah) (Jonah Whales)) ((27 Jonah) (Jonah Spiders)) ((18 Alan) (Alan Ghosts)) ((28 Alan) (Alan Ghosts)) ((18 Alan) (Alan Zombies)) ((28 Alan) (Alan Zombies)) ((28 Glory) (Glory Buffy)))</pre> |
||