Subject: bug#63671: closed (Re: bug#63671: Add function to test equality of hash tables)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 11 Sep 2023 18:40:02 +0000

Your bug report

#63671: Add function to test equality of hash tables

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
63671: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63671
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#63671: Add function to test equality of hash tables
From: Stefan Kangas <[email-masked]>
To: Mattias Engdegård <[email-masked]>, Ihor Radchenko <[email-masked]>
Cc: [email-masked], Joseph Turner <[email-masked]>
Date: Mon, 11 Sep 2023 11:39:04 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Mattias Engdegård <[email-masked]> writes:

> 25 maj 2023 kl. 08.31 skrev Ihor Radchenko <[email-masked]>:
>
>> If we are serious about adding this feature, lets not close this report.
>
> I for one am not, at least not now.

Let's close this for now then.

Subject: Add function to test equality of hash tables
From: Joseph Turner <[email-masked]>
To: [email-masked]
Date: Tue, 23 May 2023 12:32:08 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello!

Would y'all be open to adding something like this?

(defun hash-equal (hash1 hash2)
  "Return non-nil when the contents of HASH1 and HASH2 are equal.
Table values are compared using `equal' unless they are both hash
tables themselves, in which case `hash-equal' is used.
Does not compare equality predicates."
  (and (= (hash-table-count hash1)
          (hash-table-count hash2))
       (catch 'flag (maphash (lambda (key hash1-value)
                               (let ((hash2-value (gethash key hash2)))
                                 (or (if (and (hash-table-p hash1-value)
                                              (hash-table-p hash2-value))
                                         (hash-equal hash1-value hash2-value)
                                       (equal hash1-value hash2-value))
                                     (throw 'flag nil))))
                             hash1)
              t)))

Rudimentary test:

(let ((hash1 (make-hash-table))
      (hash2 (make-hash-table))
      (hash3 (make-hash-table))
      (hash4 (make-hash-table)))
  (puthash 'foo "foo" hash1)
  (puthash 'foo "foo" hash2)
  (puthash 'bar "foo" hash3)
  (puthash 'bar "foo" hash4)
  (puthash 'baz hash3 hash1)
  (puthash 'baz hash4 hash2)
  (hash-equal hash1 hash2))

We could use hash-table-test to compare predicates, perhaps
dependent on the presence of a 'compare-tests flag?

Best,

Joseph