Function: HEAPIFY

Source

(defun heapify (array node size key comp)
  (labels ((item-key (i)
	     (funcall key (aref array i))))
    (let ((left (+ 1 (* 2 node)))
	  (right (+ 2 (* 2 node))))
      (condlet (((and (< left size)
		      (comp-< (item-key left) (item-key node) comp)
		      (or (>= right size)
			  (comp-< (item-key left) (item-key right) comp)))
		 (smallest left))
		((and (< right size)
		      (comp-< (item-key right) (item-key node) comp))
		 (smallest right)))
	(array-swap array node smallest)
	(heapify array smallest size key comp))
      (values))))
Source Context