mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 03:11:01 +00:00
Refactor: Remove stale benchmark outputs
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = (await import("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js")).default
|
||||
|| await import("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js");
|
||||
|
||||
const unique = _.uniqWith(points, _.isEqual);
|
||||
const sorted = _.sortBy(unique, ["x", "y"]);
|
||||
|
||||
if (sorted.length <= 1) return sorted;
|
||||
|
||||
const cross = (O, A, B) =>
|
||||
(A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
|
||||
|
||||
const lower = [];
|
||||
for (const p of sorted) {
|
||||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0)
|
||||
lower.pop();
|
||||
lower.push(p);
|
||||
}
|
||||
|
||||
const upper = [];
|
||||
for (let i = sorted.length - 1; i >= 0; i--) {
|
||||
const p = sorted[i];
|
||||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0)
|
||||
upper.pop();
|
||||
upper.push(p);
|
||||
}
|
||||
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
|
||||
return lower.concat(upper);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 5.615s
|
||||
// Result: PASS
|
||||
@@ -1,33 +0,0 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = (await import("https://cdn.jsdelivr.net/npm/lodash-es/lodash.js")).default;
|
||||
|
||||
const unique = _.uniqWith(points, _.isEqual);
|
||||
const sorted = _.sortBy(unique, ["x", "y"]);
|
||||
|
||||
if (sorted.length <= 1) return sorted;
|
||||
|
||||
const cross = (O, A, B) =>
|
||||
(A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
|
||||
|
||||
const lower = [];
|
||||
for (const p of sorted) {
|
||||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0)
|
||||
lower.pop();
|
||||
lower.push(p);
|
||||
}
|
||||
|
||||
const upper = [];
|
||||
for (const p of _.reverse([...sorted])) {
|
||||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0)
|
||||
upper.pop();
|
||||
upper.push(p);
|
||||
}
|
||||
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
|
||||
return [...lower, ...upper];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 5.094s
|
||||
// Result: PASS
|
||||
@@ -1,27 +0,0 @@
|
||||
export const findConvexHull = async (points) => {
|
||||
const _ = (await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')).default;
|
||||
const sorted = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
||||
|
||||
if (sorted.length < 3) return sorted;
|
||||
|
||||
const crossProduct = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
||||
|
||||
const buildChain = (arr) => {
|
||||
const chain = [];
|
||||
for (const p of arr) {
|
||||
while (chain.length >= 2 && crossProduct(chain[chain.length - 2], chain[chain.length - 1], p) <= 0) {
|
||||
chain.pop();
|
||||
}
|
||||
chain.push(p);
|
||||
}
|
||||
return chain;
|
||||
};
|
||||
|
||||
const lower = buildChain(sorted);
|
||||
const upper = buildChain([...sorted].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 12.985s
|
||||
// Result: PASS
|
||||
@@ -1,32 +0,0 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm");
|
||||
|
||||
const sortedPoints = _.sortBy([...points], ["x", "y"]);
|
||||
const uniquePoints = _.uniqWith(sortedPoints, (a, b) => a.x === b.x && a.y === b.y);
|
||||
|
||||
if (uniquePoints.length <= 2) return uniquePoints;
|
||||
|
||||
const crossProduct = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const lower = [];
|
||||
for (const point of uniquePoints) {
|
||||
while (lower.length >= 2 && crossProduct(lower[lower.length - 2], lower[lower.length - 1], point) <= 0) {
|
||||
lower.pop();
|
||||
}
|
||||
lower.push(point);
|
||||
}
|
||||
|
||||
const upper = [];
|
||||
for (let i = uniquePoints.length - 1; i >= 0; i--) {
|
||||
const point = uniquePoints[i];
|
||||
while (upper.length >= 2 && crossProduct(upper[upper.length - 2], upper[upper.length - 1], point) <= 0) {
|
||||
upper.pop();
|
||||
}
|
||||
upper.push(point);
|
||||
}
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 11.859s
|
||||
// Result: FAIL
|
||||
@@ -1,25 +0,0 @@
|
||||
export async function findConvexHull(points) {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
|
||||
if (!Array.isArray(points)) points = [];
|
||||
const uniq = _.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y);
|
||||
const pts = _.sortBy(uniq, p => [p.x, p.y]);
|
||||
if (pts.length <= 1) return pts.slice();
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const lower = [];
|
||||
for (const p of pts) {
|
||||
while (lower.length > 1 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0) lower.pop();
|
||||
lower.push(p);
|
||||
}
|
||||
const upper = [];
|
||||
for (let i = pts.length - 1; i >= 0; i--) {
|
||||
const p = pts[i];
|
||||
while (upper.length > 1 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0) upper.pop();
|
||||
upper.push(p);
|
||||
}
|
||||
upper.pop();
|
||||
lower.pop();
|
||||
return lower.concat(upper);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 14.502s
|
||||
// Result: PASS
|
||||
@@ -1,23 +0,0 @@
|
||||
async function findConvexHull(p) {
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'),
|
||||
u = _.uniqWith(_.sortBy(p, 'x', 'y'), (a, b) => a.x === b.x && a.y === b.y);
|
||||
if (u.length < 3) return u;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x),
|
||||
build = (pts) => {
|
||||
const h = [];
|
||||
for (const q of pts) {
|
||||
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], q) <= 0) h.pop();
|
||||
h.push(q);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const l = build(u),
|
||||
r = build([...u].reverse());
|
||||
|
||||
return [...l.slice(0, -1), ...r.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 147.393s
|
||||
// Result: FAIL
|
||||
@@ -1,22 +0,0 @@
|
||||
async function findConvexHull(a) {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
a = uniqWith(a, isEqual);
|
||||
if (a.length < 4) return a;
|
||||
const b = sortBy(a, [v => v.x, v => v.y]);
|
||||
const c = (o, p, q) => (p.x - o.x) * (q.y - o.y) - (p.y - o.y) * (q.x - o.x);
|
||||
const d = [];
|
||||
for (const p of b) {
|
||||
while (d.length > 1 && c(d[d.length - 2], d[d.length - 1], p) <= 0) d.pop();
|
||||
d.push(p);
|
||||
}
|
||||
const e = [];
|
||||
for (let i = b.length; i--;) {
|
||||
const p = b[i];
|
||||
while (e.length > 1 && c(e[e.length - 2], e[e.length - 1], p) <= 0) e.pop();
|
||||
e.push(p);
|
||||
}
|
||||
return uniqWith([...d, ...e], isEqual);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 16.314s
|
||||
// Result: PASS
|
||||
@@ -1,19 +0,0 @@
|
||||
export async function findConvexHull(pts){
|
||||
const {default:_}=await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const p=_.orderBy(_.uniqWith(pts,(a,b)=>a.x===b.x&&a.y===b.y),['x','y']);
|
||||
if(p.length<3)return p;
|
||||
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
const l=[],u=[];
|
||||
for(const v of p){
|
||||
while(l.length>1&&c(l[l.length-2],l[l.length-1],v)<=0)l.pop();
|
||||
l.push(v);
|
||||
}
|
||||
for(const v of [...p].reverse()){
|
||||
while(u.length>1&&c(u[u.length-2],u[u.length-1],v)<=0)u.pop();
|
||||
u.push(v);
|
||||
}
|
||||
return l.slice(0,-1).concat(u.slice(0,-1));
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 10.565s
|
||||
// Result: PASS
|
||||
@@ -1,41 +0,0 @@
|
||||
const loadLodash = (() => {
|
||||
let p;
|
||||
return () =>
|
||||
p || (p = import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm")
|
||||
.then(m => m.default || m)
|
||||
.catch(e => (p = null, Promise.reject(e))));
|
||||
})();
|
||||
|
||||
async function findConvexHull(points) {
|
||||
const _ = await loadLodash();
|
||||
if (!Array.isArray(points)) throw new TypeError("Expected an array of points");
|
||||
|
||||
const pts = _.uniqBy(
|
||||
points.filter(p => p && Number.isFinite(p.x) && Number.isFinite(p.y)),
|
||||
p => `${p.x}|${p.y}`
|
||||
);
|
||||
|
||||
if (pts.length < 2) return pts.slice();
|
||||
|
||||
const s = _.sortBy(pts, ["x", "y"]);
|
||||
const cross = (o, a, b) =>
|
||||
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const build = arr => {
|
||||
const h = [];
|
||||
for (const p of arr) {
|
||||
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const lo = build(s);
|
||||
const up = build(s.slice().reverse());
|
||||
lo.pop();
|
||||
up.pop();
|
||||
return lo.concat(up);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 134.929s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user