--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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@gmail.com> writes:
> 25 maj 2023 kl. 08.31 skrev Ihor Radchenko <yantar92@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.
--- End Message ---