Skip to content

Commit

Permalink
refactor(arrays): update imports, use new Fn types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 5, 2020
1 parent a3a2d7b commit 1e3b6ac
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/arrays/src/binary-search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Comparator, Fn, FnU2 } from "@thi.ng/api";
import type { Comparator, Fn, FnN, FnN2 } from "@thi.ng/api";
import { compare, compareNumAsc } from "@thi.ng/compare";

/**
Expand Down Expand Up @@ -157,14 +157,14 @@ export const binarySearch32 = (buf: ArrayLike<number>, x: number) => {
*
* @param i - binarySearch result index
*/
export const bsLT = (i: number) => (i < 0 ? -i - 2 : i - 1);
export const bsLT: FnN = (i) => (i < 0 ? -i - 2 : i - 1);

/**
* Similar to {@link bsLT}, but for less-than-equals queries.
*
* @param i - binarySearch result index
*/
export const bsLE = (i: number) => (i < 0 ? -i - 2 : i);
export const bsLE: FnN = (i) => (i < 0 ? -i - 2 : i);

/**
* {@link binarySearch} result index classifier for successor queries.
Expand All @@ -185,7 +185,7 @@ export const bsLE = (i: number) => (i < 0 ? -i - 2 : i);
* @param i - binarySearch result index
* @param n - array length
*/
export const bsGT: FnU2<number> = (i, n) => (
export const bsGT: FnN2 = (i, n) => (
(i = i < 0 ? -i - 1 : i + 1), i < n ? i : -1
);

Expand All @@ -195,14 +195,12 @@ export const bsGT: FnU2<number> = (i, n) => (
* @param i - binarySearch result index
* @param n - array length
*/
export const bsGE: FnU2<number> = (i, n) => (
(i = i < 0 ? -i - 1 : i), i < n ? i : -1
);
export const bsGE: FnN2 = (i, n) => ((i = i < 0 ? -i - 1 : i), i < n ? i : -1);

/**
* {@link binarySearch} result index classifier for equals queries.
* Merely syntax sugar, casting any non-found result indices to -1.
*
* @param i - binarySearch result index
*/
export const bsEQ = (i: number) => (i < 0 ? -1 : i);
export const bsEQ: FnN = (i) => (i < 0 ? -1 : i);

0 comments on commit 1e3b6ac

Please sign in to comment.