help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Most used words in current buffer


From: Stefan Monnier
Subject: Re: Most used words in current buffer
Date: Sat, 21 Jul 2018 14:22:44 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> (defun buffer-most-used-words-2 (n)
>   "Make a list of the N most used words in buffer."
>   (let ((counts (avl-tree-create (lambda (wc1 wc2)
>                                  (string< (first wc1) (first wc2)))))
>       (words (split-string (buffer-string)))

If you want to go fast, don't use split-string+buffer-string.
Scan through the buffer and extract each word with buffer-substring directly.

>       (let ((element (avl-tree-member counts (list (downcase word) 0))))

I'd use a hash-table (implemented in C) rather than an avl-tree
(implemented in Elisp).


        Stefan




reply via email to

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