Wed 01 Sep 2004 10:57:31 AM UTC, comment #1:
I agree this function is useful, however, I think the patch is
incorrect. Marcus was very careful to make sure that a break in
HURD_IHASH_ITERATE would really break out of the iteration. We should
strive to preserve this functionality in HURD_IHASH_ITERATE_KEYS.
The problem, of course, is that we can only declare a variables of a
single type in a for loop initializer section and Marcus automatically
declares the VAL variable for the user. I think this is actually
detrimental as then it becomes inaccessible outside of the loop and
makes things like this impossible:
hurd_ihash_t ht;
HURD_IHASH_ITERATE (ht, val)
if (condition1_p (val) || condition2_p (val))
break;
...
/* Examine val. */
So, I think we should have the user declare VAL (and in the case of
your extension, KEY).
I have attached a patch which does this. It updates libihash
but not the rest of the users. If Marcus agrees then I can make a
patch to do this.
Here is a test case:
#include <stdio.h>
#include <ihash.h>
int
main (int argc, char *argv[])
{
hurd_ihash_t ht;
hurd_ihash_create (&ht, HURD_IHASH_NO_LOCP);
hurd_ihash_add (ht, (hurd_ihash_key_t) 2, (hurd_ihash_value_t) -2);
hurd_ihash_add (ht, (hurd_ihash_key_t) 3, (hurd_ihash_value_t) -3);
hurd_ihash_add (ht, (hurd_ihash_key_t) 4, (hurd_ihash_value_t) -4);
hurd_ihash_key_t key;
hurd_ihash_value_t val;
HURD_IHASH_ITERATE(ht, val)
printf ("%d\n", (int) val);
HURD_IHASH_ITERATE_KEY(ht, key, val)
printf ("%d -> %d\n", (int) key, (int) val);
return 0;
}
|