bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
To: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
Cc: bug-gnulib@gnu.org, Bruno Haible <bruno@clisp.org>
Subject: Re: Non-opaque hamt type?
Date: Sat, 3 Apr 2021 11:08:56 +0200	[thread overview]
Message-ID: <CAEYrNrQh6x37yzkEckcp+3tvuJyrhne-Yyxi=W93ea5DDaq24Q@mail.gmail.com> (raw)
In-Reply-To: <CAEYrNrTHwBzKsdDyQVfUOLZvn7HnLpqf22hu7dodPQqtaLmL8g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3308 bytes --]

Please excuse the delay in finalizing the new module. I was distracted due
to the start of the semester in October last year and then forgot to finish
my work.

To summarize, I have finally come to the conclusion not to change the API
as theorized in this thread.

First of all, the benefits of making the hamt type non-opaque are too small
compared with the possible drawbacks (the non-opaqueness, the inability to
return NULL in future API extensions, etc.).

Secondly, after having given it some more thought, the alternative protocol
(which we have called more robust) seems to be harder to understand because
"p != e" could then mean two different things. So I will leave the original
protocol in place, which is easy to comprehend: If "old_hamt == new_hamt",
no insertion has taken place and one has manually free the element one has
attempted to insert. If "old_hamt != new_hamt" the element has been
inserted and has now to eventually free "new_hamt" besides "old_hamt".

After I have rebased my code to HEAD, I will commit the new module to
Gnulib.

Thank you for your patience.

Marc

Am So., 18. Okt. 2020 um 20:11 Uhr schrieb Marc Nieper-Wißkirchen <
marc.nieper+gnu@gmail.com>:

> Okay, if you find the latter protocol better anyway, I will switch to
> this protocol, and hamts will be stack-allocated (just two words) and
> passed by value.
>
> Thanks,
>
> Marc
>
> Am So., 18. Okt. 2020 um 19:58 Uhr schrieb Bruno Haible <bruno@clisp.org>:
> >
> > Marc Nieper-Wißkirchen wrote:
> > > The existing protocol is as follows:
> > >
> > > Hamt_entry *e = hamt_entry (...);
> > > Hamt_entry *p = e;
> > > Hamt *new_hamt = hamt_insert (old_hamt, &p);
> > > if (old_hamt == new_hamt)
> > >   {
> > >     /* The element hasn't been insert as an equivalent element has
> already been in the hamt. p now holds a reference to the entry that already
> existed in the hamt.
> > >     element_free (e);
> > >     ...
> > >     hamt_free (old_hamt); /* We don't have to free new_hamt because no
> new hamt was created. */
> > >   }
> > > else
> > >   {
> > >     /* The element has been inserted. p hasn't changed. */
> > >     ...
> > >     hamt_free (old_hamt);  /* This frees all hamts */
> > >     hamt_free (new_hamt); /* and all elements inserted, including e. */
> > >   }
> > >
> > > A protocol where no pointer values need to be compared could use p to
> > > carry the information:
> > >
> > > Hamt_entry *e = hamt_entry ();
> > > Hamt_entry *p = e;
> > > Hamt new_hamt = hamt_insert (old_hamt, &p);
> > > if (p == e)
> > >   {
> > >     /* The element has been inserted. */
> > >     ... /* See above. */
> > >   }
> > > else if (p == NULL)
> > >   {
> > >     /* The element e already existed in the hamt. */
> > >    ... /* See above. */
> > >   }
> > > else /* p != e && p != NULL */
> > >   {
> > >     /* An element equivalent to e already existed in the hamt. p now
> holds this element. */
> > >     ... /* See above. */
> > >   }
> >
> > I find the latter protocol more robust: it does not depend on details of
> > the implementation of hamt_insert.
> >
> > Can you decide on your original question (allow stack-allocated HAMTs)?
> > I don't feel I can help you decide this.
> >
> > Bruno
> >
>

[-- Attachment #2: Type: text/html, Size: 4998 bytes --]

  reply	other threads:[~2021-04-03  9:09 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 21:07 [New module] Persistent Hash Array Mapped Tries (HAMTs) Marc Nieper-Wißkirchen
2020-10-10 14:35 ` Bruno Haible
2020-10-10 14:46   ` Marc Nieper-Wißkirchen
2020-10-10 17:34     ` Bruno Haible
2020-10-10 14:54 ` Bruno Haible
2020-10-10 15:01   ` Marc Nieper-Wißkirchen
2020-10-10 15:04     ` Marc Nieper-Wißkirchen
2020-10-10 17:41       ` Bruno Haible
2020-10-10 17:49         ` Marc Nieper-Wißkirchen
2020-10-10 18:19       ` Paul Eggert
2020-10-10 21:24         ` Marc Nieper-Wißkirchen
2020-10-10 21:46           ` Marc Nieper-Wißkirchen
2020-10-11  1:28             ` Bruno Haible
2020-10-11  8:20               ` Marc Nieper-Wißkirchen
2020-10-11  9:43                 ` Marc Nieper-Wißkirchen
2020-10-11 11:02                   ` HAMT iterator Bruno Haible
2020-10-11 11:08                     ` Marc Nieper-Wißkirchen
2020-10-11 12:04                       ` Bruno Haible
2020-10-11 12:25                         ` Marc Nieper-Wißkirchen
2020-10-11 13:52                           ` Bruno Haible
2020-10-11 12:14                       ` Bruno Haible
2020-10-11 12:22                         ` Marc Nieper-Wißkirchen
2020-10-11 10:29                 ` HAMT iterators Bruno Haible
2020-10-11 12:44                   ` Marc Nieper-Wißkirchen
2020-10-11 13:47                     ` Bruno Haible
2020-10-11 10:53                 ` out-of-memory handling Bruno Haible
2020-10-11 11:07                   ` Marc Nieper-Wißkirchen
2020-10-11 11:56                     ` Bruno Haible
2020-10-11 12:20                       ` Marc Nieper-Wißkirchen
2020-10-11 14:01                         ` HAMT for gl_set and gl_map Bruno Haible
2020-10-11 17:32                 ` [New module] Persistent Hash Array Mapped Tries (HAMTs) Marc Nieper-Wißkirchen
2020-10-11 18:22                   ` Draft #3 (with iterators) Marc Nieper-Wißkirchen
2020-10-11 19:09                     ` Bruno Haible
2020-10-12  6:06                       ` Non-opaque hamt type? Marc Nieper-Wißkirchen
2020-10-18 14:39                         ` Bruno Haible
2020-10-18 15:29                           ` Marc Nieper-Wißkirchen
2020-10-18 17:58                             ` Bruno Haible
2020-10-18 18:11                               ` Marc Nieper-Wißkirchen
2021-04-03  9:08                                 ` Marc Nieper-Wißkirchen [this message]
2021-04-03 10:26                                   ` Bruno Haible
2020-10-11 14:14             ` terminology Bruno Haible
2020-10-11 14:20               ` terminology Marc Nieper-Wißkirchen
2020-10-10 22:39         ` _Atomic Bruno Haible
2020-10-11 20:15           ` _Atomic Paul Eggert
2020-10-11 21:47             ` _Atomic Bruno Haible

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://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to='CAEYrNrQh6x37yzkEckcp+3tvuJyrhne-Yyxi=W93ea5DDaq24Q@mail.gmail.com' \
    --to=marc.nieper+gnu@gmail.com \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@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).