From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#45539: 26.3; `add-to-ordered-list': Add optional arg for :test predicate for hash table Date: Thu, 31 Dec 2020 04:55:05 +0100 Message-ID: <87v9ciociu.fsf@gnus.org> References: <1af7f2ac-0e6c-4c8a-860b-22148265d8aa@default> <87y2hgosxo.fsf@gnus.org> <64015d41-a84f-4ff6-a5a1-ab5d92aa20e5@default> <87k0szpyaj.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30210"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 45539@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 31 04:56:09 2020 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 1kup4L-0007kh-0c for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 31 Dec 2020 04:56:09 +0100 Original-Received: from localhost ([::1]:55132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kup4J-0001wl-Vk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 22:56:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kup4E-0001we-4x for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 22:56:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kup4D-0000ej-Tj for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 22:56:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kup4D-0004O0-RI for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 22:56:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 31 Dec 2020 03:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45539 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 45539-submit@debbugs.gnu.org id=B45539.160938692216810 (code B ref 45539); Thu, 31 Dec 2020 03:56:01 +0000 Original-Received: (at 45539) by debbugs.gnu.org; 31 Dec 2020 03:55:22 +0000 Original-Received: from localhost ([127.0.0.1]:51644 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kup3Z-0004N4-JE for submit@debbugs.gnu.org; Wed, 30 Dec 2020 22:55:21 -0500 Original-Received: from quimby.gnus.org ([95.216.78.240]:44010) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kup3X-0004Mq-1l for 45539@debbugs.gnu.org; Wed, 30 Dec 2020 22:55:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=662CE/pTG8mvG2x1XmnJlrVss5izIqSQoz0lZaYgx4E=; b=HKDskP3BtDsC+N5VODivv78FbL +ISb00dJo6EP7SsZadkiqmkO+DzY1dWxq12yOLPcU5DrWDMWflqM+V2/faX59NjwSwfl+QHh2A3vK mhPDypcd+jTj/5cIWsKJLLmzBHnWCJr88IxvQuFfTxNujJyYYr1CiHsd0HH5lG2H0lYw=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kup3K-0001ev-Ek; Thu, 31 Dec 2020 04:55:12 +0100 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAFVBMVEXFoR391RD82xdT PUsiEU2slJX///8HICltAAAAAWJLR0QGYWa4fQAAAAd0SU1FB+QMHwMjIuUE0SAAAAGiSURBVDjL XZJblsMgCIZN7QKi2UDNbIAezHvnwCygJ3H/Wxm8oLbkxfCJ8ANmcX5Xc945t1lEgGgWVyxUFORo LSB24HqUww0wogL1isUNCaEBP17y9oFGrIL9xxoE+dBazKdNI+53lAeIMEawSNF2YCOweQmTECDE GUiMGN4ZiFhBLp5YqolyGQ3M5UZmkrL28rkOHuJnVkkd+OrnmyjyE1A/P0PY54i1+fkVXGtBAd3P 1JLUCMvDbhOY/fwc4MPPrw7ww1+S+Nx+w1+mE22AtC56l6l1cKRGjrfmqPdSOim7mUSiC/2pvyQk X6h93P06IhJKfVj7GFZo4JAATBFjkbjLwE0FKYek6ywSVwO3FdpTRwbnVc4buBWXCjANwIu3sIwc GZxFDBjjw1RullKSEPgwCczJq37au0BCBSWL9x2ckiRfP06dYgWYUPwikFP+/e1ALo/cZVUqEHkn 5YBzWpUOpE8KyhTbU9eBjMc1rYqCIrHv45RcR9WTVB2paO+LmpM0gTKSGTy1V+JKVdwXyA2elg7c BGgEmOwfK5qukVnAPwsS3IMOvteXAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIwLTEyLTMxVDAzOjM1 OjM0KzAwOjAwWHxzKwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0xMi0zMVQwMzozNTozNCswMDow MCkhy5cAAAAASUVORK5CYII= X-Now-Playing: Tom Robinson's _North by Northwest_: "Can't Keep Away (part II)" In-Reply-To: (Drew Adams's message of "Wed, 30 Dec 2020 09:55:55 -0800 (PST)") 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" Xref: news.gmane.io gmane.emacs.bugs:197059 Archived-At: Drew Adams writes: > What this function is really about, I think, is this: a list with > unique elements - no duplicates. > > With your fix of this bug, "unique" will be defined by the new TEST > arg (predicate). Until then, "unique" is defined by `eq'. My confusion here was due to not reading the code closely enough, and because it's implemented how you'd think, it's just ... confusing. > (defun add-to-ordered-list (list-var element &optional order) > "Add ELEMENT to the value of LIST-VAR if it isn't there yet. > The test for presence of ELEMENT is done with `eq'. > The resulting list is reordered so that the elements are in the > order given by each element's numeric list order. Elements > without a numeric list order are placed at the end of the list. What on earth is a "numeric list order" of an object? This seems to imply that ELEMENT should be a number. > If the third optional argument ORDER is a number (integer or > float), set the element's list order to the given value. If > ORDER is nil or omitted, do not change the numeric order of > ELEMENT. If ORDER has any other value, remove the numeric order > of ELEMENT if it has one. The actual ORDER bit is optional, which makes no sense for a function that's allegedly about an ordered list. > (when order > (puthash element (and (numberp order) order) ordering)) The hash table is only used to store this ORDER, and ORDER is silently discarded unless it's a number. > (unless (memq element (symbol-value list-var)) > (set list-var (cons element (symbol-value list-var)))) This is the actual member check -- the hash table isn't used to keep track of what's already in the list or not. > (set list-var (sort (symbol-value list-var) The list is re-sorted upon every call, which is maximally inefficient. > (lambda (a b) > (let ((oa (gethash a ordering)) > (ob (gethash b ordering))) > (if (and oa ob) > (< oa ob) > oa))))))) Finally, we sort based on the values stashed in the hash table, and the ones with a (numerical) order gets sorted first. It's a strange, maximally inefficient function. I'll fix it up a bit and add the test-function. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no