🔨 rename package compute -> solver

This commit is contained in:
platane
2021-01-11 23:50:00 +01:00
parent fd7202c05e
commit a3f79b9ca4
35 changed files with 27 additions and 37 deletions

View File

@@ -0,0 +1,2 @@
export const arrayEquals = <T>(a: T[], b: T[]) =>
a.length === b.length && a.every((_, i) => a[i] === b[i]);

View File

@@ -0,0 +1,22 @@
export const sortPush = <T>(arr: T[], x: T, sortFn: (a: T, b: T) => number) => {
let a = 0;
let b = arr.length;
if (arr.length === 0 || sortFn(x, arr[a]) <= 0) {
arr.unshift(x);
return;
}
while (b - a > 1) {
const e = Math.ceil((a + b) / 2);
const s = sortFn(x, arr[e]);
if (s === 0) a = b = e;
else if (s > 0) a = e;
else b = e;
}
const e = Math.ceil((a + b) / 2);
arr.splice(e, 0, x);
};