(defun heap-insert (item heap) (with-comparator (heap-comparator heap) (labels ((insert-at (pos) (let ((p (parent-index pos)) (key (heap-key-fn heap))) (if (and (> pos 0) (comp-> (funcall key (aref (heap-array heap) p)) (funcall key item))) (progn (setf (aref (heap-array heap) pos) (aref (heap-array heap) p)) (insert-at p)) (setf (aref (heap-array heap) pos) item))))) (adjust-heap-array (incf (heap-size heap)) heap) (insert-at (1- (heap-size heap))))))Source Context