From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63671: Add function to test equality of hash tables Date: Tue, 23 May 2023 12:32:08 -0700 Message-ID: <87edn6bzvz.fsf@breatheoutbreathe.in> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16104"; mail-complaints-to="usenet@ciao.gmane.io" To: 63671@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 23 21:41:21 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1Xsm-00041l-Th for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 23 May 2023 21:41:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1XsX-00028G-Qb; Tue, 23 May 2023 15:41:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1XsV-00027m-JY for bug-gnu-emacs@gnu.org; Tue, 23 May 2023 15:41:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1XsU-0002Yx-T2 for bug-gnu-emacs@gnu.org; Tue, 23 May 2023 15:41:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1XsU-0008Qj-AY for bug-gnu-emacs@gnu.org; Tue, 23 May 2023 15:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 May 2023 19:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63671 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168487081432332 (code B ref -1); Tue, 23 May 2023 19:41:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 May 2023 19:40:14 +0000 Original-Received: from localhost ([127.0.0.1]:40446 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1Xrh-0008PP-OB for submit@debbugs.gnu.org; Tue, 23 May 2023 15:40:14 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:32940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1Xrf-0008PH-Kq for submit@debbugs.gnu.org; Tue, 23 May 2023 15:40:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Xrf-0001VV-6x for bug-gnu-emacs@gnu.org; Tue, 23 May 2023 15:40:11 -0400 Original-Received: from out-2.mta0.migadu.com ([2001:41d0:1004:224b::2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Xrc-0002Lk-QV for bug-gnu-emacs@gnu.org; Tue, 23 May 2023 15:40:10 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1684870804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=nwnoTo7gorEnCdom/hnGn60ldV0mgADYDUps5zqnw9g=; b=MLqa6sYNW0x2cURIWadEoGjGe8ZRZJVHoqQecO4CQsG12PHjTTCnbRlHikTWmtZGNrm220 Z+yHiQZ+DC3LjhVaJdqme97cncgYVMKeZwW9EETRy5a7C7FnCvFZOKC3Gbydge3iRhY7SR vM+NhzmYNIBvyix6ghqUlXTs2FnOEBs= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::2; envelope-from=joseph@breatheoutbreathe.in; helo=out-2.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262251 Archived-At: 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