Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 23:31:52 +00:00
parent 341252fec1
commit 5855cf8a6f
77 changed files with 972 additions and 1051 deletions

View File

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