mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-06-30 21:32:13 +00:00
Docs: Update benchmark results
This commit is contained in:
27
tests/1_dijkstra/outputs/google_gemini-2.5-pro TEMP_0.7.js
Normal file
27
tests/1_dijkstra/outputs/google_gemini-2.5-pro TEMP_0.7.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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 distances = { [startNode]: 0 };
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
|
||||
|
||||
pq.queue({ value: startNode, priority: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const { value: currentNode } = pq.dequeue();
|
||||
|
||||
if (currentNode === endNode) break;
|
||||
|
||||
const neighbors = graph[currentNode] ?? {};
|
||||
for (const [neighbor, weight] of Object.entries(neighbors)) {
|
||||
const newDist = distances[currentNode] + weight;
|
||||
|
||||
if (newDist < (distances[neighbor] ?? Infinity)) {
|
||||
distances[neighbor] = newDist;
|
||||
pq.queue({ value: neighbor, priority: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distances[endNode] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
Reference in New Issue
Block a user