(defun cross-index (tbl) (let* ((x (xindex-new tbl)) (uniques (xindex-uniques x)) (class-counts (xindex-class-counts x))) (dotimes (i (table-width tbl)) (setf (aref (xindex-ranges x) i) (make-counted))) (dotimes (j (xindex-ns x) x) (cross-index1 j (aref (xindex-all x) j) x uniques class-counts)))) (defun cross-index1 (j eg x uniques class-counts) (let* ((i -1) (class (eg-class eg))) (incf (gethash class class-counts 0)) (dolist (range (eg-features eg)) (incf i) (unless (unknownp range) (let* ((xkey `(,class ,i ,range)) (ukey `(,i ,range)) (counted (gethash xkey (xindex-counts x) (make-counted)))) (setf (gethash xkey (xindex-counts x)) (counted+ j counted nil)) (when (= 1 (incf (gethash ukey uniques 0))) (setf (aref (xindex-ranges x) i) (counted+ range (aref (xindex-ranges x) i))))))))) ;(deftest test-index () ; (let ((tmp (cross-index (make-data2)))) ; (check ; (samep tmp " ;#(XINDEX ; :TABLE