Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-10-13 18:37:08 +00:00
parent eaf29ad08d
commit af1053eeb0
28 changed files with 558 additions and 20 deletions

View File

@@ -0,0 +1,35 @@
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 visited = new Set();
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;
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
}
}
}
return distances[end];
}
export default findShortestPath;

View File

@@ -1,23 +1,35 @@
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 pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
pq.queue([start, 0]);
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;
}, {});
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
const visited = new Set();
while (pq.length > 0) {
const [current, currentDist] = pq.dequeue();
if (visited.has(current)) continue;
visited.add(current);
if (current === end) return currentDist;
for (const [neighbor, weight] of Object.entries(graph[current] || {})) {
const newDist = currentDist + weight;
pq.queue({ node: start, dist: 0 });
while (pq.length) {
const { node, dist } = pq.dequeue();
if (visited.has(node)) continue;
if (node === end) return dist;
visited.add(node);
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const newDist = dist + weight;
if (newDist < distances[neighbor]) {
distances[neighbor] = newDist;
pq.queue([neighbor, newDist]);
pq.queue({ node: neighbor, dist: newDist });
}
}
}
return distances[end];
}
};
export default findShortestPath;

View File

@@ -0,0 +1,27 @@
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

@@ -0,0 +1,27 @@
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.priority - b.priority });
pq.queue({ value: startNode, priority: 0 });
while (pq.length) {
const { value: currentNode } = pq.dequeue();
if (currentNode === endNode) break;
const neighbors = graph[currentNode] ?? {};
for (const [neighbor, weight] of Object.entries(neighbors)) {
const newDist = distances[currentNode] + weight;
if (newDist < (distances[neighbor] ?? Infinity)) {
distances[neighbor] = newDist;
pq.queue({ value: neighbor, priority: newDist });
}
}
}
return distances[endNode] ?? Infinity;
}
export default findShortestPath;

View File

@@ -1,2 +1,32 @@
const findShortestPath = async (graph, start, end) => (async () => { const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js'); const dists = Object.fromEntries(Object.keys(graph).map(k => [k, Infinity])), pq = new PQ({ comparator: (a, b) => a[1] - b[1] }); dists[start] = 0; pq.queue([start, 0]); while (pq.length) { const [node] = pq.dequeue(); if (node === end) break; for (const [neighbor, weight] of Object.entries(graph[node] || {})) { const newDist = dists[node] + weight; if (newDist < dists[neighbor]) { dists[neighbor] = newDist; pq.queue([neighbor, newDist]); } } } return dists[end]; })();
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,2 +1,29 @@
async function findShortestPath(graph,start,end){const{default:PriorityQueue}=await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.3.0/dist/priority-queue.esm.js');if(start==null||end==null)return Infinity;if(start===end)return 0;if(!graph||!Object.prototype.hasOwnProperty.call(graph,start))return Infinity;const visited=new Set;const dist=new Map([[start,0]]);const pq=new PriorityQueue({comparator:(a,b)=>a[0]-b[0]});pq.queue([0,start]);for(;pq.length;){const[d,node]=pq.dequeue();if(visited.has(node))continue;visited.add(node);if(node===end)return d;const neighbors=graph[node]||{};for(const[neighbor,weight]of Object.entries(neighbors)){if(typeof weight!=='number'||weight<0)continue;const alt=d+weight;if(alt<(dist.get(neighbor)??Infinity)){dist.set(neighbor,alt);pq.queue([alt,neighbor]);}}}return Infinity;}
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;
}
export default findShortestPath;

View File

@@ -0,0 +1,29 @@
async function findConvexHull(points) {
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = arr => {
const hull = [];
for (const p of arr) {
while (hull.length > 1 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
return [...lower, ...upper].reverse();
}
export default findConvexHull;

View File

@@ -0,0 +1,26 @@
async function findConvexHull(points) {
const { sortBy, uniqWith } = await import('https://cdn.skypack.dev/lodash');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = arr => {
const hull = [];
for (const p of arr) {
while (hull.length > 1 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
}
export default findConvexHull;

View File

@@ -0,0 +1,29 @@
async function findConvexHull(points) {
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, isEqual), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = (pts) => {
const hull = [];
for (const p of pts) {
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
return [...lower, ...upper].reverse();
}
export default findConvexHull;

View File

@@ -0,0 +1,33 @@
async function findConvexHull(points) {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const uniquePoints = _.uniqWith(points, _.isEqual);
if (uniquePoints.length < 3) {
return uniquePoints;
}
const sorted = _.sortBy(uniquePoints, ['x', 'y']);
const crossProduct = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const buildHalfHull = (pts) => {
const hull = [];
for (const p of pts) {
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
hull.pop();
}
hull.push(p);
}
return hull;
};
const lower = buildHalfHull(sorted);
const upper = buildHalfHull([...sorted].reverse());
const hull = [...lower.slice(0, -1), ...upper.slice(0, -1)];
return [hull[0], ...hull.slice(1).reverse()];
}
export default findConvexHull;

View File

@@ -0,0 +1,34 @@
async function findConvexHull(points) {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const uniqueSortedPoints = _.sortBy(
_.uniqBy(points, p => `${p.x}:${p.y}`),
['x', 'y']
);
if (uniqueSortedPoints.length < 3) {
return uniqueSortedPoints;
}
const crossProduct = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const buildHalfHull = pts => {
const half = [];
for (const p of pts) {
while (half.length >= 2 && crossProduct(half.at(-2), half.at(-1), p) <= 0) {
half.pop();
}
half.push(p);
}
return half;
};
const lower = buildHalfHull(uniqueSortedPoints);
const upper = buildHalfHull([...uniqueSortedPoints].reverse());
const ccwHull = lower.slice(0, -1).concat(upper.slice(0, -1));
return [ccwHull[0], ...ccwHull.slice(1).reverse()];
}
export default findConvexHull;

View File

@@ -0,0 +1,35 @@
const findConvexHull = async (points) => {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
const sortedPoints = _.sortBy(points, ['x', 'y']);
const uniquePoints = _.uniqWith(sortedPoints, _.isEqual);
if (uniquePoints.length < 3) {
return uniquePoints;
}
const crossProduct = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const lower = [];
for (const p of uniquePoints) {
while (lower.length >= 2 && crossProduct(lower.at(-2), lower.at(-1), p) <= 0) {
lower.pop();
}
lower.push(p);
}
const upper = [];
for (let i = uniquePoints.length - 1; i >= 0; i--) {
const p = uniquePoints[i];
while (upper.length >= 2 && crossProduct(upper.at(-2), upper.at(-1), p) <= 0) {
upper.pop();
}
upper.push(p);
}
const hull = [...lower.slice(0, -1), ...upper.slice(0, -1)];
return hull.reverse();
};
export default findConvexHull;

View File

@@ -0,0 +1,23 @@
const lod=import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
export async function findConvexHull(input){
if(!Array.isArray(input)) return [];
const {uniqBy:uniq,sortBy:sort}=await lod;
const pts=sort(uniq(input.filter(p=>p&&Number.isFinite(p.x)&&Number.isFinite(p.y)).map(p=>({x:+p.x,y:+p.y})),p=>`${p.x}:${p.y}`),['x','y']);
if(pts.length<2) return pts;
const area=(a,b,c)=>(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
const walk=list=>{
const res=[];
for(const p of list){
while(res.length>1&&area(res[res.length-2],res[res.length-1],p)<=0)res.pop();
res.push(p);
}
return res;
};
const low=walk(pts);
const up=walk(pts.slice().reverse());
const hull=low.slice(0,-1).concat(up.slice(0,-1));
const out=hull.length?hull:pts.slice(0,2);
return out.length<3?out:out.reverse();
}
export default findConvexHull;

View File

@@ -0,0 +1,17 @@
const findLISLength = async (arr) => {
if (!arr?.length) return 0;
const { bisectLeft } = await import('https://cdn.skypack.dev/d3-array');
const tails = [];
for (const num of arr) {
const pos = bisectLeft(tails, num);
tails[pos] = num;
}
return tails.length;
};
export default findLISLength;
export default findLISLength;

View File

@@ -0,0 +1,15 @@
const findLISLength = async (arr) => {
if (!arr?.length) return 0;
const { bisectLeft } = await import('https://cdn.skypack.dev/d3-array');
const tails = [];
for (const num of arr) {
const pos = bisectLeft(tails, num);
tails[pos] = num;
}
return tails.length;
};
export default findLISLength;

View File

@@ -0,0 +1,15 @@
const findLISLength = async (nums) => {
const { bisectLeft } = await import('https://cdn.skypack.dev/d3-array');
if (!nums?.length) return 0;
const tails = [];
for (const num of nums) {
const idx = bisectLeft(tails, num);
tails[idx] = num;
}
return tails.length;
};
export default findLISLength;

View File

@@ -0,0 +1,14 @@
const findLISLength = async (nums) => {
if (!nums?.length) return 0;
const { bisectLeft } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm');
const tails = [];
for (const num of nums) {
tails[bisectLeft(tails, num)] = num;
}
return tails.length;
};
export default findLISLength;

View File

@@ -0,0 +1,13 @@
const findLISLength = async (nums) => {
if (!nums?.length) return 0;
const { bisectLeft } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm');
const tails = [];
for (const num of nums) {
tails[bisectLeft(tails, num)] = num;
}
return tails.length;
};
export default findLISLength;

View File

@@ -0,0 +1,13 @@
const findLISLength = async (nums) => {
if (!Array.isArray(nums) || !nums.length) return 0;
const { bisectLeft } = await import("https://cdn.jsdelivr.net/npm/d3-array");
const tails = [];
for (const num of nums) {
tails[bisectLeft(tails, num)] = num;
}
return tails.length;
};
export default findLISLength;

View File

@@ -0,0 +1,14 @@
const loadBisectLeft=(()=>{let cache;return()=>cache||(cache=import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm').then(({bisectLeft})=>bisectLeft));})();
export async function findLISLength(nums){
if(!Array.isArray(nums)) throw new TypeError('Expected an array');
if(!nums.length) return 0;
const bisectLeft=await loadBisectLeft();
const tails=[];
for(const value of nums){
if(!Number.isFinite(value)) throw new TypeError('Array must contain only finite numbers');
const index=bisectLeft(tails,value,0,tails.length);
tails[index]=value;
}
return tails.length;
}
export default findLISLength;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@13.0.0/es/index.js');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@13.0.0/es/index.js');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async (matrix) => {
const { det } = await import('https://esm.sh/mathjs');
return det(matrix);
};
export default calculateDeterminant;

View File

@@ -0,0 +1,7 @@
const src='https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm'
export const calculateDeterminant=async m=>{
if(!Array.isArray(m)||!m.length||m.some(r=>!Array.isArray(r)||r.length!==m.length))throw new TypeError('Matrix must be square')
const{det}=await import(src)
return det(m)
}
export default calculateDeterminant;