Question about double pointer to a reference

I can't seem to wrap my mind around what is going on here. My teacher gave us an implementation of a copy constructor for a separately chained hash table.

Basically we traverse down each bucket index, and scan for each node in a linked list, copying each value from a source to a target along the way.

In the code, we go through a for loop until we hit the amount of buckets in our map. From there, I don't really know what is going on?

1
2
Node** prevNode = &hashTable[i];
*prevNode = nullptr;


This is declared before a while loop. What are we storing into prevNode in line 1? Is it the address of a hash table at a specific index into a pointer into a pointer into a previous node? What exactly is this doing?

Also what is *prevNode referring to? We end up changing *prevNode to equal a copied node later on.

After this, in a while loop, we initialize a new pointer called copy, which we construct a new node of, and transfer a source nodes values into. Like this:

1
2
3
4
Node* copy = new Node(); // create a new Node to store data to
copy->key = sourceNode->key; // copy username
copy->value = sourceNode->value; // copy password
copy->next = nullptr; // set next to nullptr 


This I understand, but after this we have the lines:

1
2
3
*prevNode = copy;
prevNode = &copy->next;
sourceNode = sourceNode->next;


I understand traversing sourceNode in the last line. The thing I'm having trouble with is understanding what "prevNode = &copy->next" does.

Thanks for any tips you can give me.
What are we storing into prevNode in line 1?
hashTable is a sequence of pointers to Nodes. hashTable[i] is a pointer to a Node. Since &x gets a pointer to x, &hashTable[i] gets a pointer to a pointer to a Node. Note that &hashTable[i] == &(hashTable[i]).
If hashTable is a pointer or an array, &hashTable[i] happens to be equivalent to hashTable + i.

The thing I'm having trouble with is understanding what "prevNode = &copy->next" does.
It makes prevNode point to the pointer copy->next. That is, these two pieces of code have the same effect:
1
2
prevNode = &copy->next;
copy->next = nullptr;

1
2
prevNode = &copy->next;
*prevNode = nullptr;
Topic archived. No new replies allowed.