Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-13 21:24:36 +00:00
parent 63fdb538ff
commit a38ae2d0c5
62 changed files with 532 additions and 1161 deletions

View File

@@ -1,25 +1,28 @@
async function findShortestPath(graph, start, end) {
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm');
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const dist = { [start]: 0 };
const pq = new PQ({ comparator: (a, b) => a[1] - b[1] });
pq.queue([start, 0]);
const distances = {};
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
for (const node in graph) distances[node] = Infinity;
distances[start] = 0;
pq.queue({ node: start, dist: 0 });
while (pq.length) {
const [node, d] = pq.dequeue();
const { node, dist } = pq.dequeue();
if (node === end) return d;
if (d > (dist[node] ?? Infinity)) continue;
if (node === end) return dist;
if (dist > distances[node]) continue;
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const newDist = d + weight;
if (newDist < (dist[neighbor] ?? Infinity)) {
dist[neighbor] = newDist;
pq.queue([neighbor, newDist]);
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 });
}
}
}
return Infinity;
return distances[end];
}
export default findShortestPath;