[cl-heap-devel] Number of arguments heap key function should accept?

Malcolm Reynolds malcolm.reynolds at gmail.com
Thu Jun 11 14:04:25 UTC 2009


Hi

I'm currently implementing Prim's MST algorithm using CL-heap. The
structure which I'm keeping in the fibonacci heap is called an
mst-node and it has a field min-dist which is the key that the heap
should be a min-queue according to. I thought I'd be able to pass
#'mst-node-min-dist as the :key argument in the heap instantiation but
that gave me errors complaining that the function used as heap key
needs to accept two arguments. After a bit of playing around it
appears the key function needs to take an optional second argument,
which if used should update the key in the item? Is this correct? I'm
currently using this and I'm wondering if there is a better way (since
mst-node-min-dist is setf'able)...

     (make-instance 'cl-heap:fibonacci-heap
				:key #'(lambda (x &optional y)
			                          (if y
								 (setf (mst-node-min-dist x) y)
								 (mst-node-min-dist x))))))

Many thanks,

Malcolm




More information about the Cl-heap-devel mailing list