重複ファイルを探す(続き)
ふかえさんに頂いたアドバイスを元に考え直してみた。
(defun find-duplicate-files (dir) (interactive "DFind duplicate files: ") (let* ((files (directory dir :absolute t :recursive t :file-only t)) (hash (make-hash-table :test #'equal)) (i 0) (n (length files))) (dolist (file files) (message "Searching for duplicate files...(~D%)" (truncate (* (incf i) 100) n)) (let ((md5 (with-open-file (stream file :encoding :binary) (si:md5 stream)))) (setf (gethash md5 hash) (cons file (gethash md5 hash))))) (with-output-to-temp-buffer (dir) (maphash #'(lambda (key val) (when (> (length val) 1) (format t "~{~A~%~}~%" val))) hash))))
以前のものより5倍程度速くなった。
ハッシュ表の使い道を初めて理解した気分。
アドバイスありがとうございました。