Code

wgraph.go — the skeleton

Create wgraph.go. The last skeleton in the course.

Most of it is code you have already written:

  • WGraph is lesson 14's Graph with one extra field on the edge;
  • BFSW is that same BFS, carried across unchanged;
  • NodeHeap is lesson 13's heap with a different payload. The same array-tree, the same 2i+1 and (i−1)/2, the same sift-up and sift-down. Only what sits in the array changed.

Genuinely new: DijkstraHeap and DijkstraScan.

Worth noting:

  • The counter counts FRONTIER work — every comparison the queue makes while choosing what comes next. In the heap that is the sift comparisons; in the linear scan it is every node looked at. It is the only quantity step 5 compares, and it is what transit's diagnostics report too.
  • Lazy deletion, not decrease-key. When a cheaper route appears, push the node again. When you pop a node that is already done, skip it.
  • Return settled too — how many nodes were finalised. Both versions must return the same number; if they do not, one of them is doing something else.
  • DijkstraScan is not to be fixed. It is slow on purpose.
Gotcha

Check if v == to when you pop, not when you push.

Return the path the moment to first enters the queue and you get the first route found, not the cheapest — because a cheaper one may still arrive. It is exactly the mistake lesson 14 made by marking seen in the wrong place, except that here it costs correctness rather than path length.

The heap's promise holds at the pop: only then is it known that nothing cheaper remains.