unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Suggestions to remove one alist's members from another
@ 2010-04-09 13:02 Wilson Snyder
  2010-04-09 14:11 ` Davis Herring
  0 siblings, 1 reply; 9+ messages in thread
From: Wilson Snyder @ 2010-04-09 13:02 UTC (permalink / raw)
  To: emacs-devel


Hello,

One of my packages has a function like this:

(defun not-in-alist (in-alist not-alist)
  "Return alist of elements in IN-ALIST that aren't also in NOT-ALIST.
Also remove any duplicates in IN-ALIST."
  (let (out-alist)
    (while in-alist
      (if (not (or (assoc (car (car in-alist)) not-alist)
		   (assoc (car (car in-alist)) out-alist)))
	  (setq out-alist (cons (car in-alist) out-alist)))
      (setq in-alist (cdr in-alist)))
    (nreverse out-alist)))

This code was expedient, but obviously not fast for large lists.
I want to replace it with something closer to O(1), even if it
has larger overhead.

Does anyone have an existing function or example I should use to
do this?  It seems relatively primitive.

If not, my thought is this: when the list was over some size
I'd determine experimentally, it would instead build a hash
table from in-list and hit the not-alist against that.  When
complete it would unfortunately require a second pass
through the in-alist to return it maintaining the original
order.

Thoughts?

Thanks






^ permalink raw reply	[flat|nested] 9+ messages in thread
* Suggestions to remove one alist's members from another
@ 2010-04-09 12:27 Wilson Snyder
  2010-04-09 15:12 ` David Kastrup
  0 siblings, 1 reply; 9+ messages in thread
From: Wilson Snyder @ 2010-04-09 12:27 UTC (permalink / raw)
  To: emacs-devel


Hello,

One of my packages has a function like this:

(defun not-in-alist (in-alist not-alist)
  "Return alist of elements in IN-ALIST that aren't also in NOT-ALIST.
Also remove any duplicates in IN-ALIST."
  (let (out-alist)
    (while in-alist
      (if (not (or (assoc (car (car in-alist)) not-alist)
		   (assoc (car (car in-alist)) out-alist)))
	  (setq out-alist (cons (car in-alist) out-alist)))
      (setq in-alist (cdr in-alist)))
    (nreverse out-alist)))

This code was expedient, but obviously not fast for large lists.
I want to replace it with something closer to O(1), even if it
has larger overhead.

Does anyone have an existing function or example I should use to
do this?  It seems relatively primitive.

If not, my thought is this: when the list was over some size
I'd determine experimentally, it would instead build a hash
table from in-list and hit the not-alist against that.  When
complete it would unfortunately require a second pass
through the in-alist to return it maintaining the original
order.

Thoughts?

Thanks




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-04-09 17:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-09 13:02 Suggestions to remove one alist's members from another Wilson Snyder
2010-04-09 14:11 ` Davis Herring
2010-04-09 14:16   ` Wilson Snyder
2010-04-09 14:45     ` Drew Adams
2010-04-09 14:48     ` Davis Herring
2010-04-09 15:05     ` David Kastrup
2010-04-09 17:31     ` Stephen J. Turnbull
  -- strict thread matches above, loose matches on Subject: below --
2010-04-09 12:27 Wilson Snyder
2010-04-09 15:12 ` David Kastrup

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).