Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-07 21:32:49 +00:00
parent f9da7d4ed7
commit d0bc3b95dd
54 changed files with 1115 additions and 372 deletions

View File

@@ -1,27 +1,33 @@
async function findShortestPath(graph, startNode, endNode) {
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js');
const findShortestPath = async (graph, start, end) => {
const cdn = 'https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js';
const { default: PriorityQueue } = await import(cdn);
const distances = { [startNode]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
const distances = Object.fromEntries(
Object.keys(graph).map(node => [node, Infinity])
);
distances[start] = 0;
pq.queue({ value: startNode, priority: 0 });
const pq = new PriorityQueue({
comparator: (a, b) => a.priority - b.priority
});
pq.queue({ value: start, priority: 0 });
while (pq.length) {
const { value: currentNode } = pq.dequeue();
const { value: current } = pq.dequeue();
if (currentNode === endNode) break;
if (current === end) break;
const neighbors = graph[currentNode] ?? {};
const neighbors = graph[current] || {};
for (const [neighbor, weight] of Object.entries(neighbors)) {
const newDist = distances[currentNode] + weight;
const newDist = distances[current] + weight;
if (newDist < (distances[neighbor] ?? Infinity)) {
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ value: neighbor, priority: newDist });
}
}
}
return distances[endNode] ?? Infinity;
}
return distances[end];
};
export default findShortestPath;