Update of /project/elephant/cvsroot/elephant/src/elephant In directory clnet:/tmp/cvs-serv2395
Modified Files: collections.lisp Log Message: Henrik's re-fix to map-index for get-instances-by-value
--- /project/elephant/cvsroot/elephant/src/elephant/collections.lisp 2007/03/21 14:29:30 1.15 +++ /project/elephant/cvsroot/elephant/src/elephant/collections.lisp 2007/03/22 19:46:17 1.16 @@ -343,12 +343,18 @@ (funcall fn k v))))))
(defun lisp-compare<= (a b) + (assert (eq (type-of a) (type-of b))) (etypecase a (number (<= a b)) (string (string<= a b)) (persistent (<= (oid a) (oid b)))))
-(defmethod map-index (fn (index btree-index) &rest args &key (start nil start-supplied-p) (end nil end-supplied-p)) +(defun lisp-compare-eq (a b) + (assert (eq (type-of a) (type-of b))) + (assert (member (type-of a) '(number string persistent null) :test #'subtypep)) + (eq a b)) + +(defmethod map-index (fn (index btree-index) &rest args &key start end) "Like map-btree, but takes a function of three arguments key, value and primary key if you want to get at the primary key value, otherwise use map-btree" (declare (dynamic-extent args) @@ -359,8 +365,7 @@ (labels ((next-range () (multiple-value-bind (exists? skey val pkey) (cursor-pnext-nodup cur) (if (and exists? - (or (not end-supplied-p) - (null end) + (or (null end) (lisp-compare<= skey end))) (progn (funcall fn skey val pkey) @@ -377,12 +382,13 @@ (next-range)))))) (declare (dynamic-extent next-range next-in-range)) (multiple-value-bind (exists? skey val pkey) - (if (and start-supplied-p (not (null start))) - (cursor-pset-range cur start) - (cursor-pfirst cur)) + (cond ((lisp-compare-eq start end) + (cursor-pset cur start)) + ((null start) + (cursor-pfirst cur)) + (t (cursor-pset-range cur start))) (if (and exists? - (or (not end-supplied-p) - (null end) + (or (null end) (lisp-compare<= skey end))) (progn (funcall fn skey val pkey)