From: Heime <heimeborgia@protonmail.com>
To: Heime <heimeborgia@protonmail.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, help-gnu-emacs@gnu.org
Subject: Re: [External] : Use of an associated list with completing-read
Date: Sat, 20 Apr 2024 06:37:08 +0000 [thread overview]
Message-ID: <ccUBJmxSVinzTPyuTmOWJJ8eHDI36pm548W7sL4T_QE1WgnOR8MAiYNWAoHBzijP1-x2lM35zqosvQxY7AZW6RKqt6fkoeP25p8W6jxi3-k=@protonmail.com> (raw)
In-Reply-To: <VyQIAYMFlW8HtMhFi01uVsCa3AB7IqUR3yESfQfIrcBtl-Zk5bqooGfZ-lCvWFL9kAmr9iCQt2QqTvxp7cCK1sSDwViu5RKoFxgJYnEQu6w=@protonmail.com>
On Saturday, April 20th, 2024 at 6:14 PM, Heime <heimeborgia@protonmail.com> wrote:
> On Saturday, April 20th, 2024 at 1:52 PM, Stefan Monnier via Users list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
>
> > > > > (setq-local tema-lugar
> > > > > (append tema--lugar (list (cons lnum strg))))
> > > >
> > > > This is the classic recipe for poor scaling performance since the above
> > > > operation takes time proportional to the length of the list, so if you
> > > > execute this N times (in a loop), the loop builds a list of length N
> > > > but takes time N² to do it. When N is small, noone notices, and as it gets
> > > > large the performance starts to suck.
> > >
> > > Heime:
> > >
> > > One programming cliche for this is to
> > > (1) start with a list that you create
> > > (e.g., a let-binding to nil), so you
> > > don't modify any existing list that
> > > you might not want to mess with, (2)
> > > use `nconc' instead of` append', to
> > > append quickly (the list structure
> > > is modified - destructive), (3) being
> > > sure to set your list variable to the
> > > result of each modification.
> >
> > While this is slightly better because it avoid the O(N²) memory
> > allocation, it's still O(N²) operations.
> >
> > > An even more common cliche for doing
> > > the same thing is to do #1, then (2)
> > > cons instead of append, and (3) when
> > > finished adding list elements, do an
> > > `nreverse' of the list you created.
> > > That too is a destructive operation.
> >
> > That's the usual solution, with the desired linear
> > (i.e. optimal) complexity, indeed. - Stefan
>
>
> How would the implementation be like exactly ?
Would a solution be like this ?
(push (cons kfrz lnum) tema-lugar)
next prev parent reply other threads:[~2024-04-20 6:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 23:48 Use of an associated list with completing-read Heime
2024-04-19 2:14 ` [External] : " Drew Adams
2024-04-19 2:59 ` Heime
2024-04-19 3:10 ` Heime
2024-04-19 15:10 ` Drew Adams
2024-04-19 19:09 ` Heime
2024-04-19 23:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20 1:13 ` Drew Adams
2024-04-20 1:52 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20 1:59 ` Emanuel Berg
2024-04-20 6:14 ` Heime
2024-04-20 6:37 ` Heime [this message]
2024-04-23 4:44 ` Jean Louis
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='ccUBJmxSVinzTPyuTmOWJJ8eHDI36pm548W7sL4T_QE1WgnOR8MAiYNWAoHBzijP1-x2lM35zqosvQxY7AZW6RKqt6fkoeP25p8W6jxi3-k=@protonmail.com' \
--to=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).