mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 11:21:00 +00:00
Docs: Update benchmark for google/gemini-3.1-pro-preview
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
async function computeMST(str) {
|
||||
const [T, M, X] = await Promise.all(
|
||||
['smol-toml', 'mnemonist', 'text-table'].map(m => import(`https://esm.sh/${m}`))
|
||||
);
|
||||
const Q = new M.Heap((a, b) => a.weight - b.weight);
|
||||
const S = new Set(), p = {}, r = {};
|
||||
|
||||
for (const e of T.parse(str).edges ?? []) {
|
||||
Q.push(e);
|
||||
S.add(e.from).add(e.to);
|
||||
}
|
||||
|
||||
S.forEach(x => (p[x] = x, r[x] = 0));
|
||||
|
||||
const f = x => p[x] === x ? x : (p[x] = f(p[x]));
|
||||
const A = [['From', 'To', 'Weight']];
|
||||
let W = 0, c = 0, L = S.size - 1;
|
||||
|
||||
while (Q.size && c < L) {
|
||||
const e = Q.pop(), u = f(e.from), v = f(e.to);
|
||||
if (u !== v) {
|
||||
r[u] < r[v] ? p[u] = v : r[u] > r[v] ? p[v] = u : (p[v] = u, r[u]++);
|
||||
A.push([e.from, e.to, `${e.weight}`]);
|
||||
W += e.weight;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
return { table: X.default(A), totalWeight: W };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 32.324s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user