Hash join: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: not obvious bare 'a' was code-ref, re-write for clarity) |
m (Add Emacs Lisp) |
||
Line 961: | Line 961: | ||
{{28,"Glory"},{"Glory","Buffy"}}] |
{{28,"Glory"},{"Glory","Buffy"}}] |
||
</pre> |
</pre> |
||
=={{header|Emacs Lisp}}== |
|||
<syntaxhighlight lang="lisp"> |
|||
(defun make-multi-map (rows) |
|||
(let ((map1 '())) |
|||
(defun place_line (row) |
|||
(let ((name (car row))) |
|||
(if (assoc name map1) |
|||
(let ((rc-list (assoc name map1))) |
|||
(setcdr (nthcdr (1- (length rc-list)) rc-list) (list row)) ) |
|||
(add-to-list 'map1 (list name row) 't)) ) ) |
|||
(mapcar 'place_line rows) |
|||
map1)) |
|||
(defun join-tables (table1 table2) |
|||
(let ((multi-map (make-multi-map table2)) |
|||
(result-table '())) |
|||
(cl-loop |
|||
for row in table1 do |
|||
(progn |
|||
(let ((multi-rc (assoc (cdr row) multi-map))) |
|||
(message "multi-rc: %s" multi-rc) |
|||
(when multi-rc |
|||
(cl-loop for multi-line in (cdr multi-rc) do |
|||
(add-to-list 'result-table (list row multi-line) 't)))))) |
|||
result-table)) |
|||
(let ((table1 '((27 . "Jonah") |
|||
(18 . "Alan") |
|||
(28 . "Glory") |
|||
(18 . "Popeye") |
|||
(28 . "Alan"))) |
|||
(table2 '(("Jonah" . "Whales") |
|||
("Jonah" . "Spiders") |
|||
("Alan" . "Ghosts") |
|||
("Alan" . "Zombies") |
|||
("Glory" . "Buffy")))) |
|||
(join-tables table1 table2)) |
|||
</syntaxhighlight> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |