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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63671 in the body.
You can then email your comments to 63671 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Tue, 23 May 2023 19:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Joseph Turner <joseph <at> breatheoutbreathe.in>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 23 May 2023 19:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Wed, 24 May 2023 09:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Joseph Turner <joseph <at> breatheoutbreathe.in>
Cc: 63671 <at> debbugs.gnu.org
Subject: bug#63671: Add function to test equality of hash tables
Date: Wed, 24 May 2023 11:27:41 +0200
Thank you, but this seems a bit too specific to your own requirements -- maybe you can keep that procedure locally where you need it? The standard library must be generally useful with clear semantics.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Wed, 24 May 2023 17:30:02 GMT) Full text and rfc822 format available.

Message #11 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Wed, 24 May 2023 10:27:13 -0700
Mattias Engdegård <mattias.engdegard <at> gmail.com> writes:

> Thank you, but this seems a bit too specific to your own requirements
> -- maybe you can keep that procedure locally where you need it?

It's no problem to keep the procedure local.

> The standard library must be generally useful with clear semantics.

Would extending `equal' to handle hash tables be generally useful?

Joseph






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Wed, 24 May 2023 19:58:02 GMT) Full text and rfc822 format available.

Message #14 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Joseph Turner <joseph <at> breatheoutbreathe.in>
Cc: Mattias Engdegård <mattias.engdegard <at> gmail.com>,
 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Wed, 24 May 2023 20:01:01 +0000
Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:

>> The standard library must be generally useful with clear semantics.
>
> Would extending `equal' to handle hash tables be generally useful?

See https://yhetil.org/emacs-devel/871qvz4kdw.fsf <at> localhost/

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Wed, 24 May 2023 20:35:01 GMT) Full text and rfc822 format available.

Message #17 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Joseph Turner <joseph <at> breatheoutbreathe.in>
Cc: 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Wed, 24 May 2023 22:34:11 +0200
[Message part 1 (text/plain, inline)]
24 maj 2023 kl. 19.27 skrev Joseph Turner <joseph <at> breatheoutbreathe.in>:

> Would extending `equal' to handle hash tables be generally useful?

It would, but doing so would be very risky at this point since it would change long-standing semantics.

We could make an augmented version of `equal` but what we really want is one that works for user-defined types (see Ihor's reference to a previous discussion).

Anyway, here's an old patch I had lying around, in case we decide that we do need a shoddy equality predicate for hash tables only.

[hash-table-equal-p.diff (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Thu, 25 May 2023 02:48:01 GMT) Full text and rfc822 format available.

Message #20 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: yantar92 <at> posteo.net, 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Wed, 24 May 2023 19:44:29 -0700
Mattias Engdegård <mattias.engdegard <at> gmail.com> writes:

> 24 maj 2023 kl. 19.27 skrev Joseph Turner <joseph <at> breatheoutbreathe.in>:
>
>> Would extending `equal' to handle hash tables be generally useful?
>
> It would, but doing so would be very risky at this point since it would change long-standing semantics.
>
> We could make an augmented version of `equal` but what we really want is one that works for user-defined types (see Ihor's reference to a previous discussion).
>
> Anyway, here's an old patch I had lying around, in case we decide that we do need a shoddy equality predicate for hash tables only.

Thank you for the references, Ihor and Mattias! Since this is a
duplicate of Ihor's thread, my report should probably be closed.

How do I close this report?

Joseph




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Thu, 25 May 2023 06:28:02 GMT) Full text and rfc822 format available.

Message #23 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Joseph Turner <joseph <at> breatheoutbreathe.in>
Cc: Mattias Engdegård <mattias.engdegard <at> gmail.com>,
 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Thu, 25 May 2023 06:31:52 +0000
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:

> Thank you for the references, Ihor and Mattias! Since this is a
> duplicate of Ihor's thread, my report should probably be closed.

If we are serious about adding this feature, lets not close this report.
My email was on emacs-devel, and it is thus less visible compared to
something being tracked on debbugs.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Thu, 25 May 2023 07:27:01 GMT) Full text and rfc822 format available.

Message #26 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: Mattias Engdegård <mattias.engdegard <at> gmail.com>,
 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Thu, 25 May 2023 00:22:50 -0700
Ihor Radchenko <yantar92 <at> posteo.net> writes:

> If we are serious about adding this feature, lets not close this report.
> My email was on emacs-devel, and it is thus less visible compared to
> something being tracked on debbugs.

I would be happy to see this feature added to Emacs! Unfortunately, I
won't be of much help right now since I have no C experience.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Thu, 25 May 2023 07:27:02 GMT) Full text and rfc822 format available.

Message #29 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: Mattias Engdegård <mattias.engdegard <at> gmail.com>,
 63671 <at> debbugs.gnu.org
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Thu, 25 May 2023 00:22:50 -0700
Ihor Radchenko <yantar92 <at> posteo.net> writes:

> If we are serious about adding this feature, lets not close this report.
> My email was on emacs-devel, and it is thus less visible compared to
> something being tracked on debbugs.

I would be happy to see this feature added to Emacs! Unfortunately, I
won't be of much help right now since I have no C experience.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63671; Package emacs. (Thu, 25 May 2023 08:19:02 GMT) Full text and rfc822 format available.

Message #32 received at 63671 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 63671 <at> debbugs.gnu.org, Joseph Turner <joseph <at> breatheoutbreathe.in>
Subject: Re: bug#63671: Add function to test equality of hash tables
Date: Thu, 25 May 2023 10:18:03 +0200
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.





Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Sep 2023 08:27:01 GMT) Full text and rfc822 format available.

Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Mon, 11 Sep 2023 18:40:02 GMT) Full text and rfc822 format available.

Notification sent to Joseph Turner <joseph <at> breatheoutbreathe.in>:
bug acknowledged by developer. (Mon, 11 Sep 2023 18:40:02 GMT) Full text and rfc822 format available.

Message #39 received at 63671-done <at> debbugs.gnu.org (full text, mbox):

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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 10 Oct 2023 11:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 193 days ago.

Previous Next


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