Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-07 21:32:49 +00:00
parent f9da7d4ed7
commit d0bc3b95dd
54 changed files with 1115 additions and 372 deletions

View File

@@ -0,0 +1,28 @@
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const distances = {};
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 });
while (pq.length) {
const { node, dist } = pq.dequeue();
if (node === end) return dist;
if (dist > distances[node]) continue;
for (const neighbor in graph[node]) {
const newDist = dist + graph[node][neighbor];
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
}
}
}
return distances[end];
}
export default findShortestPath;

View File

@@ -1,35 +1,29 @@
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] = node === start ? 0 : Infinity;
return acc;
}, {});
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
pq.queue({ node: start, dist: 0 });
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const dist = { [start]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
const visited = new Set();
pq.queue([start, 0]);
while (pq.length) {
const { node, dist } = pq.dequeue();
const [node, d] = pq.dequeue();
if (visited.has(node)) continue;
visited.add(node);
if (node === end) return dist;
if (node === end) return d;
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const newDist = dist + weight;
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
const newDist = d + weight;
if (newDist < (dist[neighbor] ?? Infinity)) {
dist[neighbor] = newDist;
pq.queue([neighbor, newDist]);
}
}
}
return distances[end];
return Infinity;
}
export default findShortestPath;

View File

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

View File

@@ -1,27 +0,0 @@
async function findShortestPath(graph, startNode, endNode) {
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js');
const distances = { [startNode]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
pq.queue({ node: startNode, dist: 0 });
while (pq.length) {
const { node: u, dist: uDist } = pq.dequeue();
if (u === endNode) return uDist;
if (uDist > (distances[u] ?? Infinity)) continue;
for (const v in graph[u] || {}) {
const newDist = uDist + graph[u][v];
if (newDist < (distances[v] ?? Infinity)) {
distances[v] = newDist;
pq.queue({ node: v, dist: newDist });
}
}
}
return Infinity;
}
export default findShortestPath;

View File

@@ -1,27 +1,33 @@
async function findShortestPath(graph, startNode, endNode) {
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js');
const findShortestPath = async (graph, start, end) => {
const cdn = 'https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js';
const { default: PriorityQueue } = await import(cdn);
const distances = { [startNode]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
const distances = Object.fromEntries(
Object.keys(graph).map(node => [node, Infinity])
);
distances[start] = 0;
pq.queue({ value: startNode, priority: 0 });
const pq = new PriorityQueue({
comparator: (a, b) => a.priority - b.priority
});
pq.queue({ value: start, priority: 0 });
while (pq.length) {
const { value: currentNode } = pq.dequeue();
const { value: current } = pq.dequeue();
if (currentNode === endNode) break;
if (current === end) break;
const neighbors = graph[currentNode] ?? {};
const neighbors = graph[current] || {};
for (const [neighbor, weight] of Object.entries(neighbors)) {
const newDist = distances[currentNode] + weight;
const newDist = distances[current] + weight;
if (newDist < (distances[neighbor] ?? Infinity)) {
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ value: neighbor, priority: newDist });
}
}
}
return distances[endNode] ?? Infinity;
}
return distances[end];
};
export default findShortestPath;

View File

@@ -1,32 +0,0 @@
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 dist = { [start]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a.weight - b.weight });
pq.enqueue({ node: start, weight: 0 });
while (pq.length) {
const { node: u, weight: uWeight } = pq.dequeue();
if (uWeight > (dist[u] ?? Infinity)) {
continue;
}
if (u === end) {
return uWeight;
}
for (const v in graph[u] || {}) {
const newWeight = uWeight + graph[u][v];
if (newWeight < (dist[v] ?? Infinity)) {
dist[v] = newWeight;
pq.enqueue({ node: v, weight: newWeight });
}
}
}
return Infinity;
};
export default findShortestPath;

View File

@@ -1,29 +1,24 @@
let u;
const loadQueue=async()=> (u=u||import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.2.0/es6.js')).then(r=>r.default);
export async function findShortestPath(graph,start,end){
if(start===end) return 0;
if(!graph||typeof graph!=='object') return Infinity;
const own=Object.prototype.hasOwnProperty;
if(!own.call(graph,start)||!own.call(graph,end)) return Infinity;
const PriorityQueue=await loadQueue();
const dist=new Map([[start,0]]);
const heap=new PriorityQueue({comparator:(a,b)=>a[1]-b[1]});
heap.queue([start,0]);
while(heap.length){
const [node,score]=heap.dequeue();
if(score>dist.get(node)) continue;
if(node===end) return score;
const edges=graph[node];
if(!edges) continue;
for(const [next,weight] of Object.entries(edges)){
const total=score+weight;
if(total<(dist.get(next)??Infinity)){
dist.set(next,total);
heap.queue([next,total]);
}
}
}
return Infinity;
let u
const o=()=>u||(u=import('https://cdn.skypack.dev/js-priority-queue').then(r=>r.default||r))
async function findShortestPath(g,s,t){
const PQ=await o()
if(s===t)return 0
const d={},q=new PQ({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(w>d[n])continue
if(n===t)return w
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;

View File

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