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

Rudy Neeser rudy.neeser at gmail.com
Thu Jun 11 22:02:15 UTC 2009


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 at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/cl-heap-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-heap-devel/attachments/20090612/3b52d28f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/cl-heap-devel/attachments/20090612/3b52d28f/attachment.sig>


More information about the Cl-heap-devel mailing list