<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.26.0">
</HEAD>
<BODY>
Hi Malcolm,<BR>
<BR>
I'm glad to see you using the library ;)<BR>
<BR>
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. <BR>
<BR>
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. <BR>
<BR>
Good luck with your project.<BR>
Rudy<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<BR>
</TD>
</TR>
</TABLE>
<BR>
On Thu, 2009-06-11 at 15:04 +0100, Malcolm Reynolds wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
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
<A HREF="mailto:cl-heap-devel@common-lisp.net">cl-heap-devel@common-lisp.net</A>
<A HREF="http://common-lisp.net/cgi-bin/mailman/listinfo/cl-heap-devel">http://common-lisp.net/cgi-bin/mailman/listinfo/cl-heap-devel</A>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>