[funds-cvs] r176 - trunk/funds/src/trees

abaine at common-lisp.net abaine at common-lisp.net
Sun Aug 19 21:46:09 UTC 2007


Author: abaine
Date: Sun Aug 19 17:46:09 2007
New Revision: 176

Modified:
   trunk/funds/src/trees/utilities.lisp
Log:
Fixed tree-count and tree-count-if.

Modified: trunk/funds/src/trees/utilities.lisp
==============================================================================
--- trunk/funds/src/trees/utilities.lisp	(original)
+++ trunk/funds/src/trees/utilities.lisp	Sun Aug 19 17:46:09 2007
@@ -1,18 +1,18 @@
 
 (in-package :funds)
 
-(defun tree-count (item tree &key (key #'bt-value) (test #'eql))
+(defun tree-count (item tree &key (key #'identity) (test #'eql))
   "The number of sub-trees in the tree that satisfy the test."
-  (tree-count #'(lambda (x)
-		  (funcall test x item))
-	      :key key))
+  (tree-count-if #'(lambda (x) (funcall test x item))
+		 tree
+		 :key key))
 
-(defun tree-count-if (predicate tree &key (key #'bt-value))
+(defun tree-count-if (predicate tree &key (key #'identity))
   "The number of sub-trees in the given tree that satisfy the test."
   (if (tree-empty-p tree)
       0
       (+ (tree-count-if predicate (bt-left tree) :key key)
-	 (funcall predicate (funcall key tree))
+	 (if (funcall predicate (funcall key tree))
+	     1
+	     0)
 	 (tree-count-if predicate (bt-right tree) :key key))))
-
-



More information about the Funds-cvs mailing list