anchor.diff:    ()
     (:documentation "Signaled when an operation depends on an item that was not found in the queue."))
   
  -;;;; Basic Operations on Queues
  +(declaim (inline parent))
  +(defun parent (i) (declare (fixnum i)) (floor (- i 1) 2))
  +(declaim (inline left))
  +(defun left (i) (declare (fixnum i)) (the fixnum (+ 1 i i)))
  +(declaim (inline right))
  +(defun right (i) (declare (fixnum i)) (the fixnum (+ 2 i i)))
  +(declaim (inline exchange))
  +(defun exchange (heap a b set-index-fn)
  +  (declare (fixnum a b) (function set-index-fn))
  +  (rotatef (aref heap a) (aref heap b))
  +  (funcall set-index-fn (aref heap a) a)
  +  (funcall set-index-fn (aref heap b) b))
   
  -(defconstant +not-in-queue+ -1)
  +(defun heapify (heap i compare-fn set-index-fn)
  +  "Assume that the children of i are heaps, but that heap[i] may be
  +worse than its children. If it is, move heap[i] down where it
  +belongs. [Page 130 CL&R 2nd ed.]."
  +  (declare (array heap) (fixnum i) (function compare-fn) (function set-index-fn))
  +  (loop with N = (length heap)
  +        with item = (aref heap i)
  +        for l = (left i)
  +        for r = (right i)
  +        for best = i
  +        do (when (and (< l N) (funcall compare-fn (aref heap l) (aref heap i)))
  +             (setf best l))
  +           (when (and (< r N) (funcall compare-fn (aref heap r) (aref heap best)))
  +             (setf best r))
  +           (cond ((/= best i)
  +                  (rotatef (aref heap i) (aref heap best))
  +                  (funcall set-index-fn (aref heap i) i)
  +                  (setf i best))
  +                 (t
  +                  (funcall set-index-fn item i)
  +                  (return)))))
  +
  +(defun improve-key (heap i compare-fn set-index-fn)
  +  (declare (array heap) (fixnum i) (function compare-fn) (function set-index-fn))
  +  (let ((item (aref heap i)))
  +    (loop while (and (> i 0)
  +                     (funcall compare-fn item (aref heap (parent i))))
  +          do (exchange heap i (parent i) set-index-fn)
  +             (setf i (parent i)))))
   
   (defstruct q
     (compare-fn nil :type function)
  
positive.code:   (make-q :compare-fn compare-fn
            :set-index-fn set-index-fn
            :get-index-fn get-index-fn
            :items (make-array size :element-type element-type :fill-pointer 0 :adjustable t)))
  
  (defun queue-empty-p (q)
    "Are there no items in the queue?"
  
negative.code: 
  (defun queue-pop (q)
    "Remove the element from the front of the queue and return
  it. Signals empty-queue-error if the queue is empty. [Page 139 CL&R
  2nd ed.]."
    (if (queue-empty-p q)
        (error 'empty-queue-error)
        (let* ((heap (q-items q))
               (set-index-fn (q-set-index-fn q))
               (min (aref heap 0)))
          (when (> (length heap) 1)
            (setf (aref heap 0) (aref heap (1- (length heap))))
            (funcall set-index-fn (aref heap 0) 0))
          (decf (fill-pointer heap))
          (heapify heap 0 (q-compare-fn q) set-index-fn)
          (funcall set-index-fn min +not-in-queue+)
          min)))
  
  (defun queue-insert (q item)
    "Insert the item by priority according to the compare
  function. Returns the queue. [Page 140 CL&R 2nd ed.]."
    (let ((heap (q-items q))
          (compare-fn (q-compare-fn q))
          (set-index-fn (q-set-index-fn q)))
      (let ((i (vector-push-extend item heap)))
        (funcall set-index-fn item i)
        (improve-key heap i compare-fn set-index-fn)))
    q)
  
  (defun queue-replace (q old new)
  