Hi,
I'm having difficulty understanding part of a hash table code example from my textbook. I don't understand why the pointer to a pointer to an Element "ptrUpdate" is strictly necessary when the pointer to an Element "ptrCurr" transverses the linked list of Elements in exactly the same way as ptrUpdate except for one less level of indirection.
My best current guess is that, since this example is supposed to be part of a case study on aspects of Instruction Level Parallelism and run-time hardware scheduling, the apparent redundancy is really just for exposing additional instruction level parallelism in the loops, or at least smoothing it out.
I don't trust that guess, which is why I'm asking you (it has been awhile since I coded in C).
Code:
/*I've copied this manually out of my textbook, so any typographical
errors are most likely mine */
typedef struct _Element {
int value;
struct _Element *next;
} Element;
Element element[N_ELEMENTS], *bucket[1024];
for(i=0;i< N_ELEMENTS; i++)
{
Element *ptrCurr, **ptrUpdate;
int hash_index;
hash_index =element[i].value & 1023;
ptrUpdate=&bucket[hash_index];
ptrCurr=bucket[hash_index];
while(ptrCurr && ptrCurr->value <= element[i].value)
{
ptrUpdate=&ptrCurr->next;
ptrCurr=ptrCurr->next;
}
element[i].next= *ptrUpdate;
*ptrUpdate = &element[i];
}
Couldn't the last two statements be replaced with
Code:
element[i].next=ptrCurr;
*ptrCurr=element[i];
and all the previous uses of ptrUpdate omitted?