Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-07 22:07:45 +00:00
parent b5f81c6e8a
commit 1687dca49c
42 changed files with 784 additions and 847 deletions

View File

@@ -1,28 +1,31 @@
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const distances = {};
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
const dist = Object.keys(graph).reduce((acc, node) => ({ ...acc, [node]: Infinity }), {});
dist[start] = 0;
for (const node in graph) distances[node] = Infinity;
distances[start] = 0;
pq.queue({ node: start, dist: 0 });
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
pq.queue([start, 0]);
const visited = new Set();
while (pq.length) {
const { node, dist } = pq.dequeue();
const [node, d] = pq.dequeue();
if (node === end) return dist;
if (dist > distances[node]) continue;
if (visited.has(node)) continue;
visited.add(node);
for (const neighbor in graph[node]) {
const newDist = dist + graph[node][neighbor];
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
if (node === end) return d;
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const newDist = d + weight;
if (newDist < dist[neighbor]) {
dist[neighbor] = newDist;
pq.queue([neighbor, newDist]);
}
}
}
return distances[end];
return dist[end];
}
export default findShortestPath;