Hash join: Difference between revisions

Content added Content deleted
m (→‎{{header|LFE}}: removed superfluous colon)
m (→‎{{header|LFE}}: Split out into more functions for increased readability)
Line 673: Line 673:
'()
'()
table))
table))

(defun get-hash (col hash-table)
(proplists:get_value
(proplists:get_value col r)
hashed))

(defun merge (row-1 row-2)
(orddict:merge
(lambda (k v1 v2) v2)
(lists:sort row-1)
(lists:sort row-2)))


(defun hash-join (table-1 col-1 table-2 col-2)
(defun hash-join (table-1 col-1 table-2 col-2)
(let ((hashed (hash col-1 table-1)))
(let ((hashed (hash col-1 table-1)))
(lc ((<- r table-2))
(lc ((<- r table-2))
(lc ((<- s (proplists:get_value
(lc ((<- s (get-hash col-2 hashed)))
(proplists:get_value col-2 r)
(merge r s)))))
hashed)))
(orddict:merge
(lambda (k v1 v2) v2)
(lists:sort r)
(lists:sort s))))))
</lang>
</lang>