Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-10-13 17:40:23 +00:00
parent bbce5cf740
commit def79ffc8a
4 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
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 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;
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue([neighbor, newDist]);
}
}
}
return distances[end];
}
export default findShortestPath;