Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 17:37:06 +00:00
parent 39d057f079
commit afcfd09537
84 changed files with 1086 additions and 1088 deletions

View File

@@ -1,24 +1,27 @@
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm');
const distances = Object.keys(graph).reduce((acc, node) => ({ ...acc, [node]: Infinity }), {});
distances[start] = 0;
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const distances = {};
const visited = new Set();
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
for (const node in graph) distances[node] = Infinity;
distances[start] = 0;
pq.queue({ node: start, dist: 0 });
const visited = new Set();
while (pq.length > 0) {
while (pq.length) {
const { node, dist } = pq.dequeue();
if (visited.has(node)) continue;
visited.add(node);
if (node === end) return dist;
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const newDist = dist + weight;
visited.add(node);
for (const neighbor in graph[node]) {
if (visited.has(neighbor)) continue;
const newDist = dist + graph[node][neighbor];
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
@@ -26,6 +29,6 @@ async function findShortestPath(graph, start, end) {
}
}
return distances[end];
return Infinity;
}
export default findShortestPath;

View File

@@ -1,36 +1,34 @@
const findShortestPath = async (graph, startNode, endNode) => {
const findShortestPath = async (graph, start, end) => {
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js');
const distances = Object.fromEntries(
Object.keys(graph).map(node => [node, 1 / 0])
const dists = Object.fromEntries(
Object.keys(graph).map(node => [node, Infinity])
);
distances[startNode] = 0;
const pq = new PriorityQueue({
comparator: (a, b) => a.priority - b.priority
});
pq.queue({ node: startNode, priority: 0 });
const pq = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
dists[start] = 0;
pq.queue({ node: start, priority: 0 });
while (pq.length) {
const { node: u, priority: dist } = pq.dequeue();
const { node: u, priority: currentDist } = pq.dequeue();
if (dist > distances[u]) {
if (currentDist > dists[u]) {
continue;
}
if (u === endNode) {
break;
}
if (u === end) break;
for (const [v, weight] of Object.entries(graph[u] ?? {})) {
const newDist = distances[u] + weight;
if (newDist < distances[v]) {
distances[v] = newDist;
pq.queue({ node: v, priority: newDist });
for (const [v, weight] of Object.entries(graph[u])) {
const distThroughU = dists[u] + weight;
if (distThroughU < dists[v]) {
dists[v] = distThroughU;
pq.queue({ node: v, priority: distThroughU });
}
}
}
return distances[endNode];
return dists[end];
};
export default findShortestPath;

View File

@@ -0,0 +1,19 @@
const findShortestPath = async (g, s, e) => {
const { default: P } = await import('https://cdn.skypack.dev/js-priority-queue')
const d = { [s]: 0 }, q = new P({ comparator: (a, b) => a.w - b.w })
q.queue({ w: 0, n: s })
while (q.length) {
const { w, n } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1 / 0)) continue
for (const v in g[n]) {
const t = w + g[n][v]
if (t < (d[v] ?? 1 / 0)) {
d[v] = t
q.queue({ w: t, n: v })
}
}
}
return 1 / 0
}
export default findShortestPath;

View File

@@ -1,35 +1,24 @@
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]]
});
const { default: Q } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/index.min.js');
const dist = { [start]: 0 }, visited = new Set();
const pq = new Q({ comparator: (a, b) => dist[a] - dist[b] });
pq.queue(start);
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]);
const node = pq.dequeue();
if (node === end) return dist[end];
if (visited.has(node)) continue;
visited.add(node);
const nodeDist = dist[node];
for (const [adj, weight] of Object.entries(graph[node] || {})) {
if (visited.has(adj)) continue;
const newDist = nodeDist + weight;
if (newDist < (dist[adj] ?? Infinity)) {
dist[adj] = newDist;
pq.queue(adj);
}
}
}
return Infinity;
}
export default findShortestPath;

View File

@@ -1,23 +0,0 @@
async function findShortestPath(g,s,e){
const {default:Q}=await import('https://cdn.jsdelivr.net/npm/js-priority-queue@latest/dist/priority-queue.min.js')
const d={},v={}
for(const k in g)d[k]=Infinity
d[s]=0
const q=new Q({comparator:(a,b)=>a[1]-b[1]})
q.queue([s,0])
while(q.length){
const [n,w]=q.dequeue()
if(v[n])continue
v[n]=1
if(n===e)return w
for(const k in g[n]){
const nw=w+g[n][k]
if(nw<d[k]){
d[k]=nw
q.queue([k,nw])
}
}
}
return Infinity
}
export default findShortestPath;

View File

@@ -1,20 +1,24 @@
const findShortestPath=async(g,s,t)=>{
if(s===t)return 0
const{default:PriorityQueue}=await import('https://cdn.skypack.dev/js-priority-queue')
if(!g[s]||!g[t])return Infinity
const seen=new Map([[s,0]])
const pq=new PriorityQueue({comparator:(a,b)=>a[1]-b[1]})
pq.queue([s,0])
const src='https://esm.sh/js-priority-queue@1'
let load
const getPQ=()=>load||(load=import(src).then(m=>m.default))
const findShortestPath=async(g,s,e)=>{
const PQ=await getPQ()
const pq=new PQ({comparator:(a,b)=>a[0]-b[0]})
const dist=new Map([[s,0]])
const done=new Set
pq.queue([0,s])
while(pq.length){
const[n,d]=pq.dequeue()
if(d>(seen.get(n)??Infinity))continue
if(n===t)return d
const nbrs=g[n]||{}
for(const k in nbrs){
const nd=d+nbrs[k]
if(nd<(seen.get(k)??Infinity)){
seen.set(k,nd)
pq.queue([k,nd])
const [d,n]=pq.dequeue()
if(done.has(n))continue
done.add(n)
if(n===e)return d
const edges=g[n]
if(!edges)continue
for(const k in edges){
const w=d+edges[k]
if(w<(dist.get(k)??Infinity)){
dist.set(k,w)
pq.queue([w,k])
}
}
}

View File

@@ -1,20 +0,0 @@
async function findShortestPath(graph, start, end) {
const { PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
const dist = {}; Object.keys(graph).forEach(n => dist[n] = Infinity); dist[start] = 0;
pq.queue([start, 0]);
while (!pq.isEmpty()) {
const [u, d] = pq.dequeue();
if (u === end) return d;
if (d > dist[u]) continue;
for (const [v, w] of Object.entries(graph[u] || {})) {
const nd = d + w;
if (nd < dist[v]) {
dist[v] = nd;
pq.queue([v, nd]);
}
}
}
return Infinity;
}
export default findShortestPath;

View File

@@ -1,19 +1,20 @@
async function findShortestPath(graph,start,end){
const{PriorityQueue}=await import('https://cdn.skypack.dev/js-priority-queue');
const{default:PriorityQueue}=await import('https://cdn.skypack.dev/js-priority-queue');
const dist={};
for(let n in graph)dist[n]=Infinity;
const pq=new PriorityQueue({comparator:(x,y)=>x.d-y.d});
for(const n of Object.keys(graph))dist[n]=Infinity;
dist[start]=0;
const pq=new PriorityQueue({comparator:(a,b)=>a.d-b.d});
pq.queue({node:start,d:0});
pq.queue({n:start,d:0});
while(!pq.isEmpty()){
const{node,d}=pq.dequeue();
if(d>dist[node])continue;
if(node===end)return d;
for(let nei in graph[node]){
const alt=d+graph[node][nei];
const{n:n,d:d}=pq.dequeue();
if(d>dist[n])continue;
if(n===end)return d;
for(let nei in graph[n]){
const w=graph[n][nei];
const alt=d+w;
if(alt<dist[nei]){
dist[nei]=alt;
pq.queue({node:nei,d:alt});
pq.queue({n:nei,d:alt});
}
}
}