[funds-cvs] r185 - trunk/funds/src
abaine at common-lisp.net
abaine at common-lisp.net
Mon Aug 20 02:07:40 UTC 2007
Author: abaine
Date: Sun Aug 19 22:07:40 2007
New Revision: 185
Modified:
trunk/funds/src/queue.lisp
Log:
Added map-queue and queue-as-list.
Modified: trunk/funds/src/queue.lisp
==============================================================================
--- trunk/funds/src/queue.lisp (original)
+++ trunk/funds/src/queue.lisp Sun Aug 19 22:07:40 2007
@@ -45,3 +45,17 @@
(defun queue-empty-p (q)
"Whether the given queue does not contain any items."
(tree-empty-p (queue-heap q)))
+
+(defun map-queue (function q)
+ "A queue containing items that are the result of applying function to
+the items in the given queue."
+ (make-queue :next-priority (queue-next-priority q)
+ :heap (map-tree #'(lambda (tree)
+ (funcall function (bt-value tree)))
+ (queue-heap q))))
+
+(defun queue-as-list (q)
+ "The elements in the given queue, returned as a list, in the order they
+would be dequeued from the given queue."
+ (mapcar #'cdr (sort (tree-as-alist (queue-heap q))
+ #'< :key #'car)))
More information about the Funds-cvs
mailing list