emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to do for faster `remove-duplicates'?


From: Oleh Krehel
Subject: Re: What to do for faster `remove-duplicates'?
Date: Wed, 06 May 2015 19:54:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Stefan Monnier <address@hidden> writes:
>
>> Looks good, please install.
>
> Not so good as now it is no more destructive for a seq > 100.

Should I make it destructive, like this?

(defun delete-dups (list)
  "Destructively remove `equal' duplicates from LIST.
Store the result in LIST and return it.  LIST must be a proper list.
Of several `equal' occurrences of an element in LIST, the first
one is kept."
  (if (> (length list) 100)
      (let ((hash (make-hash-table :test #'equal))
            res)
        (dolist (elt list)
          (unless (gethash elt hash)
            (puthash elt elt hash)
            (push elt res)))
        (setcdr list (cdr (nreverse res))))
    (let ((tail list))
      (while tail
        (setcdr tail (delete (car tail) (cdr tail)))
        (setq tail (cdr tail)))))
  list)

Oleh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]