From 0e4ad432dd61216449603802e36e991ed0cb2154 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Wed, 18 Mar 2026 18:19:42 +0300 Subject: [PATCH] remove-duplicates: use hash-tables for :test #'= --- src/code/seq.lisp | 4 +++- tests/hash.pure.lisp | 1 + tests/seq.pure.lisp | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/code/seq.lisp b/src/code/seq.lisp index 0f64817f8..72d81c7c7 100644 --- a/src/code/seq.lisp +++ b/src/code/seq.lisp @@ -2549,7 +2549,9 @@ many elements are copied." ((eq fun #'string=) (make-hash-table :test #'string= :hash-function #'string=-hash :size size)) ((eq fun #'string-equal) - (make-hash-table :test #'string-equal :hash-function #'string-equal-hash :size size)))) + (make-hash-table :test #'string-equal :hash-function #'string-equal-hash :size size)) + ((eq fun #'=) + (make-hash-table :test #'= :hash-function #'psxhash :size size)))) ;;; Remove duplicates from a list. If from-end, remove the later duplicates, ;;; not the earlier ones. Thus if we check from-end we don't copy an item diff --git a/tests/hash.pure.lisp b/tests/hash.pure.lisp index fefe3c364..e14b0e5a9 100644 --- a/tests/hash.pure.lisp +++ b/tests/hash.pure.lisp @@ -477,6 +477,7 @@ (unwind-protect (let ((transformed-cases '((integer sb-impl::integer-sxhash) (number sb-impl::number-sxhash) + #-sb-devel ;; where sb-impl::instance-sxhash is inlined (sb-kernel:instance sb-impl::instance-sxhash))) (inlined-cases '(single-float double-float fixnum))) (loop for (type . hasher) in transformed-cases diff --git a/tests/seq.pure.lisp b/tests/seq.pure.lisp index a9595c8f2..7eaa25266 100644 --- a/tests/seq.pure.lisp +++ b/tests/seq.pure.lisp @@ -76,7 +76,7 @@ (assert (equalp (remove-duplicates orig :start 3 :end 9) '(0 1 2 0 1 2 0 1 2))) (assert (equalp (delete-duplicates orig :start 3 :end 9) '(0 1 2 0 1 2 0 1 2))))) -(with-test (:name (remove-duplicates delete-duplicates :key)) +(with-test (:name (remove-duplicates :key)) (let* ((negative (loop :for i :from 1 :to 11 :collect (- i))) (positive (loop :for i :from 1 :to 11 :collect i)) (combined (append negative positive)) @@ -86,6 +86,16 @@ (assert (equalp (coerce positive 'vector) (remove-duplicates vector :key #'abs))) (assert (equalp (coerce negative 'vector) (remove-duplicates vector :key #'abs :from-end t))))) +(with-test (:name :remove-duplicates-test-=) + (let* ((negative (loop :for i :from 1 :to 11 :collect (- i))) + (positive (loop :for i :from 1 :to 11 :collect (float i))) + (combined (append negative positive)) + (vector (coerce combined 'vector))) + (assert (equal positive (remove-duplicates combined :key #'abs :test #'=))) + (assert (equal negative (remove-duplicates combined :key #'abs :from-end t :test #'=))) + (assert (equalp (coerce positive 'vector) (remove-duplicates vector :key #'abs :test #'=))) + (assert (equalp (coerce negative 'vector) (remove-duplicates vector :key #'abs :from-end t :test #'=))))) + ;;; tests of COUNT (with-test (:name (count)) (assert (= 1 (count 1 '(1 2 3))))