mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 16:47:55 +00:00
Docs: Update benchmark for minimax/minimax-m2
This commit is contained in:
37
tests/1_dijkstra/outputs/minimax_minimax-m2.js
Normal file
37
tests/1_dijkstra/outputs/minimax_minimax-m2.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export async function findShortestPath(graph, start, end) {
|
||||
if (start === end) return 0;
|
||||
if (!graph || !graph[start] || !graph[end]) return Infinity;
|
||||
|
||||
const { default: PQ } = await import('https://cdn.skypack.dev/js-priority-queue@0.2.0?min') ||
|
||||
(await import('https://unpkg.com/js-priority-queue@0.2.0/dist/js-priority-queue.min.js')) ||
|
||||
{ default: self.PriorityQueue };
|
||||
const pq = new PQ({ comparator: (a, b) => a.d - b.d });
|
||||
|
||||
const dist = Object.create(null);
|
||||
const q = new Set(Object.keys(graph));
|
||||
|
||||
for (const k of q) dist[k] = Infinity;
|
||||
dist[start] = 0;
|
||||
pq.enqueue({ n: start, d: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const { n: u, d: du } = pq.dequeue();
|
||||
if (du !== dist[u]) continue;
|
||||
if (u === end) return du;
|
||||
const nb = graph[u] || {};
|
||||
for (const v in nb) {
|
||||
if (!q.has(v)) continue;
|
||||
const w = +nb[v];
|
||||
if (!isFinite(w)) continue;
|
||||
const nd = du + w;
|
||||
if (nd < dist[v]) {
|
||||
dist[v] = nd;
|
||||
pq.enqueue({ n: v, d: nd });
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 18.720s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user