Hi Malcolm, I'm glad to see you using the library ;) You're right about the :key argument: if you're going to use a function that needs to update the priorities of nodes in the heap, then :key will have to be a function that accepts a second argument. The example code that you've given looks good, and is exactly how it's intended to be done. Unfortunately I haven't been able to think of a much better way of doing this. I'd thought of using a setf'able place, but SETF operates by performing macro expansions at compile time, while the value sent to :key is a function that's going to be evaluated at runtime. I might try to get around this using EQL specialisers in the next version. Good luck with your project. Rudy On Thu, 2009-06-11 at 15:04 +0100, Malcolm Reynolds wrote:
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
_______________________________________________ cl-heap-devel mailing list cl-heap-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cl-heap-devel