mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 03:11:01 +00:00
Docs: Update benchmark for z-ai/glm-5
This commit is contained in:
36
tests/12_mst_pipeline/outputs/z-ai_glm-5.js
Normal file
36
tests/12_mst_pipeline/outputs/z-ai_glm-5.js
Normal file
@@ -0,0 +1,36 @@
|
||||
async function computeMST(tomlStr) {
|
||||
const [{ parse }, { Heap }, { default: table }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/smol-toml/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/mnemonist/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/text-table/+esm')
|
||||
]);
|
||||
|
||||
const { edges } = parse(tomlStr);
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
edges.forEach(e => heap.push(e));
|
||||
|
||||
const p = new Map, r = new Map;
|
||||
const find = x => p.get(x) === x ? x : p.set(x, find(p.get(x))).get(x);
|
||||
const mk = n => p.has(n) || (p.set(n, n) && r.set(n, 0));
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size) {
|
||||
const { from, to, weight } = heap.pop();
|
||||
mk(from); mk(to);
|
||||
let [x, y] = [find(from), find(to)];
|
||||
if (x !== y) {
|
||||
if (r.get(x) < r.get(y)) [x, y] = [y, x];
|
||||
p.set(y, x);
|
||||
if (r.get(x) === r.get(y)) r.set(x, r.get(x) + 1);
|
||||
mst.push([from, to, String(weight)]);
|
||||
totalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
return { table: table([['From', 'To', 'Weight'], ...mst]), totalWeight };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 368.359s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user