GNU bug report logs - #63671
Add function to test equality of hash tables

Previous Next

Package: emacs;

Reported by: Joseph Turner <joseph <at> breatheoutbreathe.in>

Date: Tue, 23 May 2023 19:41:02 UTC

Severity: wishlist

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#63671: closed (Add function to test equality of hash tables)
Date: Mon, 11 Sep 2023 18:40:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 11 Sep 2023 11:39:04 -0700
with message-id <CADwFkmkGyeZFGWq95T47AYTeTiu4589fA0Gf1aanm7ub6bY6wA <at> mail.gmail.com>
and subject line Re: bug#63671: Add function to test equality of hash tables
has caused the debbugs.gnu.org bug report #63671,
regarding Add function to test equality of hash tables
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
63671: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63671
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: bug-gnu-emacs <at> gnu.org
Subject: Add function to test equality of hash tables
Date: Tue, 23 May 2023 12:32:08 -0700
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


[Message part 3 (message/rfc822, inline)]
From: Stefan Kangas <stefankangas <at> gmail.com>
To: Mattias EngdegÄrd <mattias.engdegard <at> gmail.com>, 
 Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 63671-done <at> debbugs.gnu.org, Joseph Turner <joseph <at> breatheoutbreathe.in>
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Mon, 11 Sep 2023 11:39:04 -0700
Mattias EngdegÄrd <mattias.engdegard <at> gmail.com> writes:

> 25 maj 2023 kl. 08.31 skrev Ihor Radchenko <yantar92 <at> posteo.net>:
>
>> 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.


This bug report was last modified 1 year and 255 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.