Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-10-13 18:37:08 +00:00
parent eaf29ad08d
commit af1053eeb0
28 changed files with 558 additions and 20 deletions

View File

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