[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HAMT iterator
From: |
Marc Nieper-Wißkirchen |
Subject: |
Re: HAMT iterator |
Date: |
Sun, 11 Oct 2020 13:08:08 +0200 |
Am So., 11. Okt. 2020 um 13:02 Uhr schrieb Bruno Haible <bruno@clisp.org>:
>
> Hi Marc,
>
> > I am going to implement the following iterator API as well:
> >
> > /* An alternative interface to iterating through the entry of a hamt
> > that does not make use of a higher-order function like
> > hamt_do_while uses the opaque Hamt_iterator type. */
> > typedef struct hamt_iterator Hamt_iterator;
> >
> > /* Return a newly created iterator for HAMT. */
> > extern Hamt_iterator *hamt_iterator_create (const Hamt *hamt);
>
> The pointer return here is overkill. A prototype
>
> extern Hamt_iterator hamt_iterator_create (const Hamt *hamt);
>
> is sufficient, because the way such an iterator is used is:
>
> Hamt_iterator iter = hamt_iterator_create (hamt);
>
> for (...)
> {
> ...
> Hamt_entry *elt;
> if (hamt_iterator_next (&iter, &elt))
> {
> ...
> }
> ...
> }
>
> hamt_iterator_free (&iter);
>
> > /* Return an independent copy of ITER that is initially in the same
> > state. */
> > extern Hamt_iterator *hamt_iterator_copy (Hamt_iterator *iter);
>
> Then a copy function is not needed, because the user's program can do
>
> Hamt_iterator iter_clone = iter;
The hamt itself has to be copied (to increase the reference counter).
> > /* Return true if ITER is not at the end, place the current element in
> > *ELT_PTR and move the iterator forward. Otherwise, return
> > *false. */
> > extern bool hamt_iterator_next (Hamt_iterator *iter,
> > Hamt_entry *const *elt_ptr);
>
> The 'const' here forbids assigning to *ELT_PTR.
Yes. Wrong position of const.
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), (continued)
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Paul Eggert, 2020/10/10
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Marc Nieper-Wißkirchen, 2020/10/10
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Marc Nieper-Wißkirchen, 2020/10/10
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Bruno Haible, 2020/10/10
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Marc Nieper-Wißkirchen, 2020/10/11
- Re: [New module] Persistent Hash Array Mapped Tries (HAMTs), Marc Nieper-Wißkirchen, 2020/10/11
- Re: HAMT iterator, Bruno Haible, 2020/10/11
- Re: HAMT iterator,
Marc Nieper-Wißkirchen <=
- Re: HAMT iterator, Bruno Haible, 2020/10/11
- Re: HAMT iterator, Marc Nieper-Wißkirchen, 2020/10/11
- Re: HAMT iterator, Bruno Haible, 2020/10/11
- Re: HAMT iterator, Bruno Haible, 2020/10/11
- Re: HAMT iterator, Marc Nieper-Wißkirchen, 2020/10/11
- Re: HAMT iterators, Bruno Haible, 2020/10/11
- Re: HAMT iterators, Marc Nieper-Wißkirchen, 2020/10/11
- Re: HAMT iterators, Bruno Haible, 2020/10/11
- Re: out-of-memory handling, Bruno Haible, 2020/10/11
- Re: out-of-memory handling, Marc Nieper-Wißkirchen, 2020/10/11