unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Drew Adams <drew.adams@oracle.com>
Cc: Eric Abrahamsen <eric@ericabrahamsen.net>,
	Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: [External] : Re: Any faster way to find frequency of words?
Date: Mon, 10 May 2021 19:26:18 +0300	[thread overview]
Message-ID: <YJleqrIWWPiEaGmA@protected.localdomain> (raw)
In-Reply-To: <SA2PR10MB44749A2367EC882E1EBCCF27F3549@SA2PR10MB4474.namprd10.prod.outlook.com>

* Drew Adams <drew.adams@oracle.com> [2021-05-10 17:03]:
> I use this, FWIW:
> 
> (defun hash-table-to-alist (hash-table)
>   "Create and return an alist created from HASH-TABLE.
> The order of alist entries is undefined, but it seems to be the same
> as the order of hash-table entries (which seems to be 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)))

That may be better, nicer.

I wonder if nreverse is really needed as function just returns some
data, is that data anyway destroyed thereafter?

Then I was also using reverse, I will take it out, as I don't think
there is any order in the hash, if I reverse it or not, it does not
matter.

(setq hash (make-hash-table))
(puthash 'Name "Jimmy" hash)
(puthash "City" "New York" hash)
(puthash "Brigade" "II" hash)

hash ⇒ #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data (Name "Jimmy" "City" "New York" "Brigade" "II"))

(puthash 'Name "Jimmy2" hash)

hash ⇒ #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data (Name "Jimmy2" "City" "New York" "Brigade" "II"))

I can see that hash keeps order of entries, but I don't believe
that is guaranteed. Visually it gives us the same order:

(hash-table-to-alist hash) ⇒ ((Name . "Jimmy2") ("City" . "New York") ("Brigade" . "II"))

(setq alist (hash-table-to-alist hash)) ⇒ ((Name . "Jimmy2") ("City" . "New York") ("Brigade" . "II"))

(assoc 'Name alist) ⇒ (Name . "Jimmy2")

I just wonder if the order matters. It should not matter in hash,
alist, plist I guess.




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




  reply	other threads:[~2021-05-10 16:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 14:38 Any faster way to find frequency of words? Jean Louis
2021-05-09 14:56 ` Eric Abrahamsen
2021-05-09 15:05   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-09 17:16   ` Jean Louis
2021-05-10  3:37     ` Eric Abrahamsen
2021-05-10  7:14       ` Jean Louis
2021-05-10 14:02         ` [External] : " Drew Adams
2021-05-10 16:26           ` Jean Louis [this message]
2021-05-10 16:34             ` Drew Adams
2021-05-10 17:05               ` Jean Louis
2021-05-09 15:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-09 17:19   ` Jean Louis
2021-05-09 18:00     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-09 19:03       ` Jean Louis
2021-05-09 23:33         ` Emanuel Berg via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YJleqrIWWPiEaGmA@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=drew.adams@oracle.com \
    --cc=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).