From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#28753: 25.3; Functions to get alist from hash table and vice versa Date: Sun, 8 Oct 2017 17:25:47 -0700 (PDT) Message-ID: <54ecd1bb-0c84-4b0a-b19e-3a89cbe832bc@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1507508835 961 195.159.176.226 (9 Oct 2017 00:27:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 9 Oct 2017 00:27:15 +0000 (UTC) To: 28753@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 09 02:27:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1LuU-0007Zu-J3 for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Oct 2017 02:27:06 +0200 Original-Received: from localhost ([::1]:55582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Lub-0003Fd-IK for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Oct 2017 20:27:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1LuV-0003FM-KP for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:27:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1LuQ-0002om-N6 for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:27:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1LuQ-0002og-Ji for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e1LuQ-00033c-AP for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Oct 2017 00:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28753 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.150750876811682 (code B ref -1); Mon, 09 Oct 2017 00:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Oct 2017 00:26:08 +0000 Original-Received: from localhost ([127.0.0.1]:56889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1LtY-00032M-8H for submit@debbugs.gnu.org; Sun, 08 Oct 2017 20:26:08 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55215) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1LtW-00031s-74 for submit@debbugs.gnu.org; Sun, 08 Oct 2017 20:26:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1LtQ-0002C9-5S for submit@debbugs.gnu.org; Sun, 08 Oct 2017 20:26:01 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:58299) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1LtQ-0002By-1n for submit@debbugs.gnu.org; Sun, 08 Oct 2017 20:26:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1LtO-00036e-VD for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:25:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1LtK-00027S-0P for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:25:58 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:37080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1LtJ-00026a-NS for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 20:25:53 -0400 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v990Pp2B003291 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 9 Oct 2017 00:25:51 GMT Original-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v990PoHd008591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 9 Oct 2017 00:25:51 GMT Original-Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v990Pnte014528 for ; Mon, 9 Oct 2017 00:25:49 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4588.0 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138095 Archived-At: Dunno whether functions like these might be useful. I use something similar. If you think they're useful, consider adding them. (cl-defun alist-to-hash-table (alist &optional use-last-p &key (test 'eql) weakness (size 65) (rehash-size 1.5) (rehash-threshold 0.= 8)) "Create and return a hash table created from ALIST. By default, if the same alist key is used in more than one alist entry then only the first entry is used for the hash table. Non-nil USE-LAST-P means override this to use only the last entry for a given key. See `make-hash-table' for the keyword arguments you can use and their default values." (let ((ht (make-hash-table :test test :weakness weakness :size size :rehash-size rehash-size :rehash-threshold re= hash-threshold)) key val) (dolist (key.val alist) (setq key (car key.val) val (cdr key.val)) (when (or use-last-p (not (gethash key ht))) (puthash key val ht))) ht)) (defun hash-table-to-alist (hash-table) "Create and return an alist created from HASH-TABLE. The order of alist entries is the same as the order of hash-table entries (which normally is the order in which the entries were added to the table)." (let ((al ())) (maphash (lambda (key val) (push (cons key val) al)) hash-table) (nreverse al))) In GNU Emacs 25.3.1 (x86_64-w64-mingw32) of 2017-09-26 Windowing system distributor `Microsoft Corp.', version 6.1.7601 Configured using: `configure --without-dbus --without-compress-install 'CFLAGS=3D-O2 -static -g3' PKG_CONFIG_PATH=3D/mingw64/lib/pkgconfig'