hashset.c
hashset.c copied to clipboard
hashset_iterator: skipping over index 0
In the Hashset itr code here:
hashset_itr_t hashset_iterator(hashset_t set)
{
hashset_itr_t itr = calloc(1, sizeof(struct hashset_itr_st));
if (itr == NULL)
return NULL;
itr->set = set;
itr->index = 0;
/* advance to the first item if one is present */
if (set->nitems > 0)
hashset_iterator_next(itr);
return itr;
}
On trying to use this code to iterate through my hashset, every so often an item would go to index 0 in the set. The code below would promptly be skipped over by the code below. I'm not sure what the goal this code was, but if there isn't any outstanding reason for it, it should probably be removed!
if (set->nitems > 0)
hashset_iterator_next(itr);