Source explorer / trusted implementations

Same algorithm.
Different idioms.

Inspect repository-controlled Dijkstra implementations in six languages. Concept markers link semantic trace events to the lines that produce them.

Read-only by design. Code is never compiled or executed in the browser.

dijkstra.ts31 lines · read only
01export function dijkstra(graph: Graph, start: Id, goal: Id) {02  const distances = new Map<Id, number>([[start, 0]]);03  const parents = new Map<Id, Id>();04  const frontier = new MinHeap<Entry>();05  frontier.push({ nodeId: start, priority: 0 });06 07  while (!frontier.isEmpty()) {08    const current = frontier.pop()!;09    if (current.priority !== distances.get(current.nodeId)) continue;10    if (current.nodeId === goal) break;11 12    for (const edge of graph.outgoing(current.nodeId)) {13      if (edge.closed) continue;14      const candidate = current.priority + edge.weight;15      const previous = distances.get(edge.toId) ?? Infinity;16 17      if (candidate < previous) {18        distances.set(edge.toId, candidate);19        parents.set(edge.toId, current.nodeId);20        frontier.push({ nodeId: edge.toId, priority: candidate });21      }22    }23  }24 25  const path: Id[] = [];26  for (let node: Id | undefined = goal; node; node = parents.get(node)) {27    path.push(node);28    if (node === start) return path.reverse();29  }30  return [];31}
Implementation notes

Equivalent does not mean identical.

01

Native data structures

Each implementation uses the standard-library priority queue idiom its ecosystem expects.

02

Stable tie-breaking

Equal-cost candidates use node identifiers so fixtures and trace order remain reproducible.

03

Shared fixtures

The same graph inputs verify cost, path connectivity, closed roads, and unreachable destinations.