mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 11:21:00 +00:00
Refactor: Remove stale benchmark outputs
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import(
|
||||
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.4.1/+esm"
|
||||
);
|
||||
|
||||
const dist = {};
|
||||
for (const node in graph) dist[node] = Infinity;
|
||||
dist[start] = 0;
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
pq.queue([start, 0]);
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length > 0) {
|
||||
const [node, d] = pq.dequeue();
|
||||
|
||||
if (visited.has(node)) continue;
|
||||
visited.add(node);
|
||||
|
||||
if (node === end) return d;
|
||||
|
||||
const neighbors = graph[node] || {};
|
||||
for (const neighbor in neighbors) {
|
||||
if (visited.has(neighbor)) continue;
|
||||
const newDist = d + neighbors[neighbor];
|
||||
if (newDist < dist[neighbor]) {
|
||||
dist[neighbor] = newDist;
|
||||
pq.queue([neighbor, newDist]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dist[end] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 5.576s
|
||||
// Result: FAIL
|
||||
@@ -1,37 +0,0 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import(
|
||||
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.4.1/+esm"
|
||||
);
|
||||
|
||||
const dist = {};
|
||||
for (const node in graph) dist[node] = Infinity;
|
||||
dist[start] = 0;
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
pq.queue([start, 0]);
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length > 0) {
|
||||
const [node, d] = pq.dequeue();
|
||||
|
||||
if (node === end) return d;
|
||||
if (visited.has(node)) continue;
|
||||
visited.add(node);
|
||||
|
||||
if (!graph[node]) 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 dist[end] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 5.349s
|
||||
// Result: FAIL
|
||||
@@ -1,28 +0,0 @@
|
||||
export const findShortestPath = async (graph, start, end) => {
|
||||
const { default: PQ } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
|
||||
const dists = { [start]: 0 };
|
||||
const pq = new PQ({ comparator: (a, b) => a.w - b.w });
|
||||
|
||||
pq.queue({ n: start, w: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const { n, w } = pq.dequeue();
|
||||
|
||||
if (n === end) return w;
|
||||
if (w > (dists[n] ?? Infinity)) continue;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[n] ?? {})) {
|
||||
const total = w + weight;
|
||||
if (total < (dists[neighbor] ?? Infinity)) {
|
||||
dists[neighbor] = total;
|
||||
pq.queue({ n: neighbor, w: total });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
};
|
||||
export default findShortestPath;
|
||||
// Generation time: 12.594s
|
||||
// Result: PASS
|
||||
@@ -1,34 +0,0 @@
|
||||
export async function findShortestPath(graph, start, end) {
|
||||
const { PriorityQueue } = await import("https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.15/+esm");
|
||||
|
||||
const distances = {};
|
||||
const visited = new Set();
|
||||
const queue = new PriorityQueue({ comparator: (a, b) => a.distance - b.distance });
|
||||
|
||||
for (const node in graph) {
|
||||
distances[node] = Infinity;
|
||||
}
|
||||
distances[start] = 0;
|
||||
queue.enqueue({ node: start, distance: 0 });
|
||||
|
||||
while (queue.length > 0) {
|
||||
const { node: current, distance } = queue.dequeue();
|
||||
|
||||
if (current === end) return distance;
|
||||
if (visited.has(current)) continue;
|
||||
visited.add(current);
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[current] || {})) {
|
||||
const newDistance = distance + weight;
|
||||
if (newDistance < distances[neighbor]) {
|
||||
distances[neighbor] = newDistance;
|
||||
queue.enqueue({ node: neighbor, distance: newDistance });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 4.700s
|
||||
// Result: FAIL
|
||||
@@ -1,37 +0,0 @@
|
||||
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
|
||||
@@ -1,27 +0,0 @@
|
||||
let PQ;
|
||||
export async function findShortestPath(g, s, e) {
|
||||
if (!(s in g) || !(e in g)) return Infinity;
|
||||
if (!PQ) ({ default: PQ } = await import('https://cdn.skypack.dev/js-priority-queue@0.1.5'));
|
||||
const d = new Map([[s, 0]]);
|
||||
const q = new PQ({ comparator: (a, b) => a[1] - b[1] });
|
||||
const v = new Set();
|
||||
q.queue([s, 0]);
|
||||
while (q.length) {
|
||||
const [n, c] = q.dequeue();
|
||||
if (n === e) return c;
|
||||
if (v.has(n)) continue;
|
||||
v.add(n);
|
||||
if (c > (d.get(n) ?? Infinity)) continue;
|
||||
for (const [p, w] of Object.entries(g[n] || {})) {
|
||||
const t = c + w;
|
||||
if (t < (d.get(p) ?? Infinity)) {
|
||||
d.set(p, t);
|
||||
q.queue([p, t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return d.get(e) ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 95.484s
|
||||
// Result: PASS
|
||||
@@ -1,22 +0,0 @@
|
||||
async function findShortestPath(g,s,t){
|
||||
let {default:P}=await import('https://cdn.skypack.dev/js-priority-queue')
|
||||
if(!(s in g)||!(t in g))return Infinity
|
||||
let d={},u=new Set,q=new P({comparator:(a,b)=>a[0]-b[0]})
|
||||
Object.keys(g).forEach(k=>d[k]=Infinity)
|
||||
d[s]=0
|
||||
q.queue([0,s])
|
||||
while(q.length){
|
||||
let [w,n]=q.dequeue()
|
||||
if(u.has(n))continue
|
||||
if(n===t)return w
|
||||
u.add(n)
|
||||
for(let m in g[n]){
|
||||
let nw=w+g[n][m]
|
||||
if(nw<d[m])d[m]=nw,q.queue([nw,m])
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 15.370s
|
||||
// Result: PASS
|
||||
@@ -1,24 +0,0 @@
|
||||
export const findShortestPath=async(g,s,e)=>{
|
||||
const{default:Q}=await import('https://esm.sh/js-priority-queue')
|
||||
const d={},v=new Set(),q=new Q({comparator:(a,b)=>a[1]-b[1]})
|
||||
for(const k in g)d[k]=Infinity
|
||||
d[s]=0
|
||||
q.queue([s,0])
|
||||
while(q.length){
|
||||
const[n,w]=q.dequeue()
|
||||
if(v.has(n))continue
|
||||
if(n===e)return w
|
||||
v.add(n)
|
||||
for(const[nb,c]of Object.entries(g[n]||{})){
|
||||
const nw=w+c
|
||||
if(nw<d[nb]){
|
||||
d[nb]=nw
|
||||
q.queue([nb,nw])
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 9.436s
|
||||
// Result: PASS
|
||||
@@ -1,34 +0,0 @@
|
||||
let _pqP;
|
||||
const _loadPQ = () =>
|
||||
_pqP || (_pqP = import("https://esm.sh/js-priority-queue@0.1.5"));
|
||||
|
||||
async function findShortestPath(graph, start, end) {
|
||||
if (start === end) return 0;
|
||||
if (!graph) return Infinity;
|
||||
|
||||
const { default: PriorityQueue } = await _loadPQ();
|
||||
const dist = Object.create(null);
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
|
||||
|
||||
dist[start] = 0;
|
||||
pq.queue([0, start]);
|
||||
|
||||
while (pq.length) {
|
||||
const [d, u] = pq.dequeue();
|
||||
if (d !== dist[u]) continue;
|
||||
if (u === end) return d;
|
||||
|
||||
for (const [v, w] of Object.entries(graph[u] || {})) {
|
||||
const nd = d + +w;
|
||||
if (nd < (dist[v] ?? Infinity)) {
|
||||
dist[v] = nd;
|
||||
pq.queue([nd, v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 91.630s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user