mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark for moonshotai/kimi-k2-thinking
This commit is contained in:
35
tests/1_dijkstra/outputs/moonshotai_kimi-k2-thinking.js
Normal file
35
tests/1_dijkstra/outputs/moonshotai_kimi-k2-thinking.js
Normal file
@@ -0,0 +1,35 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
let PriorityQueue;
|
||||
try {
|
||||
const mod = await import('https://esm.sh/js-priority-queue@1.0.0');
|
||||
PriorityQueue = mod.default || mod;
|
||||
} catch {
|
||||
throw new Error('Failed to load priority queue library');
|
||||
}
|
||||
|
||||
if (!(start in graph) || !(end in graph)) return Infinity;
|
||||
if (start === end) return 0;
|
||||
|
||||
const dist = { [start]: 0 };
|
||||
const pq = new PriorityQueue({
|
||||
comparator: (a, b) => a[1] - b[1],
|
||||
initialValues: [[start, 0]]
|
||||
});
|
||||
|
||||
while (pq.length) {
|
||||
const [node, d] = pq.dequeue();
|
||||
if (node === end) return d;
|
||||
if (d > (dist[node] ?? Infinity)) continue;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[node])) {
|
||||
const newDist = d + weight;
|
||||
if (newDist < (dist[neighbor] ?? Infinity)) {
|
||||
dist[neighbor] = newDist;
|
||||
pq.queue([neighbor, newDist]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
Reference in New Issue
Block a user