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;
> /* 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.
Bruno