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)))) - -