@ac-kit/algo 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.md +60 -18
- package/dist/combinatorics/cartesian-product.d.ts +46 -0
- package/dist/combinatorics/cartesian-product.d.ts.map +1 -0
- package/dist/combinatorics/cartesian-product.js +79 -0
- package/dist/combinatorics/cartesian-product.js.map +1 -0
- package/dist/combinatorics/permutations.d.ts +41 -0
- package/dist/combinatorics/permutations.d.ts.map +1 -0
- package/dist/combinatorics/permutations.js +70 -0
- package/dist/combinatorics/permutations.js.map +1 -0
- package/dist/combinatorics/power-set.d.ts +40 -0
- package/dist/combinatorics/power-set.d.ts.map +1 -0
- package/dist/combinatorics/power-set.js +67 -0
- package/dist/combinatorics/power-set.js.map +1 -0
- package/dist/graph/bfs.d.ts +66 -0
- package/dist/graph/bfs.d.ts.map +1 -0
- package/dist/graph/bfs.js +89 -0
- package/dist/graph/bfs.js.map +1 -0
- package/dist/graph/connected-components.d.ts +35 -0
- package/dist/graph/connected-components.d.ts.map +1 -0
- package/dist/graph/connected-components.js +75 -0
- package/dist/graph/connected-components.js.map +1 -0
- package/dist/graph/find-cycle.d.ts +5 -3
- package/dist/graph/find-cycle.d.ts.map +1 -1
- package/dist/graph/find-cycle.js +23 -3
- package/dist/graph/find-cycle.js.map +1 -1
- package/dist/graph/floyd-warshall.d.ts +67 -0
- package/dist/graph/floyd-warshall.d.ts.map +1 -0
- package/dist/graph/floyd-warshall.js +106 -0
- package/dist/graph/floyd-warshall.js.map +1 -0
- package/dist/graph/graph-cycle-error.d.ts +16 -0
- package/dist/graph/graph-cycle-error.d.ts.map +1 -0
- package/dist/graph/graph-cycle-error.js +20 -0
- package/dist/graph/graph-cycle-error.js.map +1 -0
- package/dist/graph/hierarchy-from-parents.js.map +1 -1
- package/dist/graph/lowest-common-ancestor.d.ts +32 -0
- package/dist/graph/lowest-common-ancestor.d.ts.map +1 -0
- package/dist/graph/lowest-common-ancestor.js +56 -0
- package/dist/graph/lowest-common-ancestor.js.map +1 -0
- package/dist/graph/topological-sort.d.ts +51 -0
- package/dist/graph/topological-sort.d.ts.map +1 -0
- package/dist/graph/topological-sort.js +124 -0
- package/dist/graph/topological-sort.js.map +1 -0
- package/dist/group/_nest-by.d.ts +19 -0
- package/dist/group/_nest-by.d.ts.map +1 -0
- package/dist/group/_nest-by.js +85 -0
- package/dist/group/_nest-by.js.map +1 -0
- package/dist/group/count-by.d.ts +31 -0
- package/dist/group/count-by.d.ts.map +1 -0
- package/dist/group/count-by.js +35 -0
- package/dist/group/count-by.js.map +1 -0
- package/dist/group/flat-group-by.d.ts +28 -0
- package/dist/group/flat-group-by.d.ts.map +1 -0
- package/dist/group/flat-group-by.js +30 -0
- package/dist/group/flat-group-by.js.map +1 -0
- package/dist/group/group-adjacent-by.d.ts +31 -0
- package/dist/group/group-adjacent-by.d.ts.map +1 -0
- package/dist/group/group-adjacent-by.js +50 -0
- package/dist/group/group-adjacent-by.js.map +1 -0
- package/dist/group/group-sort.d.ts +38 -0
- package/dist/group/group-sort.d.ts.map +1 -0
- package/dist/group/group-sort.js +49 -0
- package/dist/group/group-sort.js.map +1 -0
- package/dist/group/index-by.d.ts +33 -0
- package/dist/group/index-by.d.ts.map +1 -0
- package/dist/group/index-by.js +42 -0
- package/dist/group/index-by.js.map +1 -0
- package/dist/group/nested-map.d.ts +12 -0
- package/dist/group/nested-map.d.ts.map +1 -0
- package/dist/group/nested-map.js +2 -0
- package/dist/group/nested-map.js.map +1 -0
- package/dist/group/rollup-by.d.ts +62 -0
- package/dist/group/rollup-by.d.ts.map +1 -0
- package/dist/group/rollup-by.js +72 -0
- package/dist/group/rollup-by.js.map +1 -0
- package/dist/group/run-length-encode.d.ts +41 -0
- package/dist/group/run-length-encode.d.ts.map +1 -0
- package/dist/group/run-length-encode.js +66 -0
- package/dist/group/run-length-encode.js.map +1 -0
- package/dist/index.d.ts +39 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/ordered/_fractional-key.d.ts +38 -0
- package/dist/ordered/_fractional-key.d.ts.map +1 -0
- package/dist/ordered/_fractional-key.js +251 -0
- package/dist/ordered/_fractional-key.js.map +1 -0
- package/dist/ordered/bisect-right-numbers-array.d.ts +20 -0
- package/dist/ordered/bisect-right-numbers-array.d.ts.map +1 -0
- package/dist/ordered/bisect-right-numbers-array.js +42 -0
- package/dist/ordered/bisect-right-numbers-array.js.map +1 -0
- package/dist/ordered/bisect-right-numbers.d.ts +19 -0
- package/dist/ordered/bisect-right-numbers.d.ts.map +1 -0
- package/dist/ordered/bisect-right-numbers.js +32 -0
- package/dist/ordered/bisect-right-numbers.js.map +1 -0
- package/dist/ordered/create-bisector.js.map +1 -1
- package/dist/ordered/fractional-key-alphabet.d.ts +41 -0
- package/dist/ordered/fractional-key-alphabet.d.ts.map +1 -0
- package/dist/ordered/fractional-key-alphabet.js +67 -0
- package/dist/ordered/fractional-key-alphabet.js.map +1 -0
- package/dist/ordered/fractional-key-error.d.ts +15 -0
- package/dist/ordered/fractional-key-error.d.ts.map +1 -0
- package/dist/ordered/fractional-key-error.js +20 -0
- package/dist/ordered/fractional-key-error.js.map +1 -0
- package/dist/ordered/fractional-key.d.ts +82 -0
- package/dist/ordered/fractional-key.d.ts.map +1 -0
- package/dist/ordered/fractional-key.js +199 -0
- package/dist/ordered/fractional-key.js.map +1 -0
- package/dist/ordered/is-sorted.d.ts +33 -0
- package/dist/ordered/is-sorted.d.ts.map +1 -0
- package/dist/ordered/is-sorted.js +39 -0
- package/dist/ordered/is-sorted.js.map +1 -0
- package/dist/sample/sample-without-replacement.d.ts +26 -0
- package/dist/sample/sample-without-replacement.d.ts.map +1 -0
- package/dist/sample/sample-without-replacement.js +41 -0
- package/dist/sample/sample-without-replacement.js.map +1 -0
- package/dist/sample/shuffle.d.ts +2 -2
- package/dist/sample/shuffle.d.ts.map +1 -1
- package/dist/sample/shuffle.js +3 -3
- package/dist/sample/shuffle.js.map +1 -1
- package/dist/sample/weighted-choice-index.d.ts +29 -0
- package/dist/sample/weighted-choice-index.d.ts.map +1 -0
- package/dist/sample/weighted-choice-index.js +62 -0
- package/dist/sample/weighted-choice-index.js.map +1 -0
- package/dist/sample/weighted-choice.d.ts +28 -0
- package/dist/sample/weighted-choice.d.ts.map +1 -0
- package/dist/sample/weighted-choice.js +31 -0
- package/dist/sample/weighted-choice.js.map +1 -0
- package/dist/select/minmax.d.ts +52 -0
- package/dist/select/minmax.d.ts.map +1 -0
- package/dist/select/minmax.js +109 -0
- package/dist/select/minmax.js.map +1 -0
- package/dist/select/{quickselect.d.ts → quickselect-in-place.d.ts} +2 -2
- package/dist/select/quickselect-in-place.d.ts.map +1 -0
- package/dist/select/{quickselect.js → quickselect-in-place.js} +3 -3
- package/dist/select/quickselect-in-place.js.map +1 -0
- package/dist/sequence/_matching-runs.d.ts +16 -0
- package/dist/sequence/_matching-runs.d.ts.map +1 -0
- package/dist/sequence/_matching-runs.js +178 -0
- package/dist/sequence/_matching-runs.js.map +1 -0
- package/dist/sequence/common-prefix-length.d.ts +26 -0
- package/dist/sequence/common-prefix-length.d.ts.map +1 -0
- package/dist/sequence/common-prefix-length.js +34 -0
- package/dist/sequence/common-prefix-length.js.map +1 -0
- package/dist/sequence/diff-sequences.d.ts +59 -0
- package/dist/sequence/diff-sequences.d.ts.map +1 -0
- package/dist/sequence/diff-sequences.js +67 -0
- package/dist/sequence/diff-sequences.js.map +1 -0
- package/dist/sequence/levenshtein-distance.d.ts +43 -0
- package/dist/sequence/levenshtein-distance.d.ts.map +1 -0
- package/dist/sequence/levenshtein-distance.js +102 -0
- package/dist/sequence/levenshtein-distance.js.map +1 -0
- package/dist/sequence/longest-common-subsequence.d.ts +28 -0
- package/dist/sequence/longest-common-subsequence.d.ts.map +1 -0
- package/dist/sequence/longest-common-subsequence.js +39 -0
- package/dist/sequence/longest-common-subsequence.js.map +1 -0
- package/dist/sequence/longest-increasing-subsequence.d.ts +28 -0
- package/dist/sequence/longest-increasing-subsequence.d.ts.map +1 -0
- package/dist/sequence/longest-increasing-subsequence.js +47 -0
- package/dist/sequence/longest-increasing-subsequence.js.map +1 -0
- package/dist/sort/_sort-primitives.d.ts +6 -0
- package/dist/sort/_sort-primitives.d.ts.map +1 -0
- package/dist/sort/_sort-primitives.js +18 -0
- package/dist/sort/_sort-primitives.js.map +1 -0
- package/dist/sort/counting-sort.d.ts +40 -0
- package/dist/sort/counting-sort.d.ts.map +1 -0
- package/dist/sort/counting-sort.js +51 -0
- package/dist/sort/counting-sort.js.map +1 -0
- package/dist/sort/merge-sort.d.ts +26 -0
- package/dist/sort/merge-sort.d.ts.map +1 -0
- package/dist/sort/merge-sort.js +73 -0
- package/dist/sort/merge-sort.js.map +1 -0
- package/dist/sort/quick-sort-in-place.d.ts +35 -0
- package/dist/sort/quick-sort-in-place.d.ts.map +1 -0
- package/dist/sort/quick-sort-in-place.js +98 -0
- package/dist/sort/quick-sort-in-place.js.map +1 -0
- package/dist/sort/radix-index-sorter.d.ts +57 -0
- package/dist/sort/radix-index-sorter.d.ts.map +1 -0
- package/dist/sort/radix-index-sorter.js +204 -0
- package/dist/sort/radix-index-sorter.js.map +1 -0
- package/dist/sort/rank.d.ts +64 -0
- package/dist/sort/rank.d.ts.map +1 -0
- package/dist/sort/rank.js +107 -0
- package/dist/sort/rank.js.map +1 -0
- package/dist/sort/sort-range.d.ts +48 -0
- package/dist/sort/sort-range.d.ts.map +1 -0
- package/dist/sort/sort-range.js +267 -0
- package/dist/sort/sort-range.js.map +1 -0
- package/package.json +6 -5
- package/dist/select/quickselect.d.ts.map +0 -1
- package/dist/select/quickselect.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { weightedChoiceIndex } from "./weighted-choice-index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Picks one element of `items` with probability proportional to its weight: a
|
|
4
|
+
* loot table, a weighted A/B split, a sampled next token.
|
|
5
|
+
*
|
|
6
|
+
* One draw of {@link weightedChoiceIndex}, whose contract it shares. For many
|
|
7
|
+
* draws from one distribution, a precomputed alias table (Vose) answers each in
|
|
8
|
+
* O(1) instead.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n), one call to `random`. Memory: O(n).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* weightedChoice(prizes, (prize) => prize.odds, Math.random);
|
|
15
|
+
* ```;
|
|
16
|
+
*
|
|
17
|
+
* @param items - The candidates.
|
|
18
|
+
* @param weightOf - The weight of an item, a finite number `≥ 0`; an item of
|
|
19
|
+
* weight `0` is never picked.
|
|
20
|
+
* @param random - A source in `[0, 1)`; not called when no weight is positive.
|
|
21
|
+
* @returns An element, or `undefined` when `items` is empty or every weight is
|
|
22
|
+
* `0` (so an array that holds `undefined` cannot tell the two apart: use
|
|
23
|
+
* {@link weightedChoiceIndex}).
|
|
24
|
+
* @throws {RangeError} When a weight is negative, `NaN` or infinite, or the
|
|
25
|
+
* total weight overflows to `Infinity`.
|
|
26
|
+
*/
|
|
27
|
+
export function weightedChoice(items, weightOf, random) {
|
|
28
|
+
const index = weightedChoiceIndex(items, weightOf, random);
|
|
29
|
+
return index < 0 ? undefined : items[index];
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=weighted-choice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weighted-choice.js","sourceRoot":"","sources":["../../src/sample/weighted-choice.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAmB,EACnB,QAA4C,EAC5C,MAAgB;IAEhB,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3D,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Callable, Comparator } from "@ac-kit/core";
|
|
2
|
+
/** The smallest and the largest item of a collection. */
|
|
3
|
+
export type MinMaxItems<T> = {
|
|
4
|
+
min: T;
|
|
5
|
+
max: T;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The smallest and the largest item under `compare`, in one pass — the
|
|
9
|
+
* comparator form of {@link minmaxBy}, named after `@ac-kit/core`'s `minmax`
|
|
10
|
+
* over numbers (d3's `extent`).
|
|
11
|
+
*
|
|
12
|
+
* Takes the items in pairs, ordering each pair first and then testing only its
|
|
13
|
+
* smaller item against the minimum and its larger against the maximum: three
|
|
14
|
+
* comparisons per two items rather than the four of two separate scans. Ties
|
|
15
|
+
* resolve to the first item seen, for the minimum and the maximum alike.
|
|
16
|
+
*
|
|
17
|
+
* Time complexity: O(n), about `3n / 2` calls to `compare`. Memory: O(1).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* minmax(["pear", "fig", "apple"], compareNaturalAscending);
|
|
22
|
+
* // { min: "apple", max: "pear" }
|
|
23
|
+
* ```;
|
|
24
|
+
*
|
|
25
|
+
* @param items - The items, read once.
|
|
26
|
+
* @param compare - A strict weak ordering of the items.
|
|
27
|
+
* @returns The minimum and maximum, or `null` for an empty input.
|
|
28
|
+
*/
|
|
29
|
+
export declare function minmax<T>(items: Iterable<T>, compare: Comparator<T>): MinMaxItems<T> | null;
|
|
30
|
+
/**
|
|
31
|
+
* The items with the smallest and the largest `valueOf(item)`, in one pass —
|
|
32
|
+
* the accessor form of {@link minmax}, as `minBy` and `maxBy` are of their
|
|
33
|
+
* comparator forms.
|
|
34
|
+
*
|
|
35
|
+
* `valueOf` is called once per item. An item whose value is `NaN` has no place
|
|
36
|
+
* in the order and is skipped, so it is never returned. Ties resolve to the
|
|
37
|
+
* first item seen; `-0` and `0` tie.
|
|
38
|
+
*
|
|
39
|
+
* Time complexity: O(n). Memory: O(1).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* minmaxBy(orders, (order) => order.total); // cheapest and dearest order
|
|
44
|
+
* ```;
|
|
45
|
+
*
|
|
46
|
+
* @param items - The items, read once.
|
|
47
|
+
* @param valueOf - The numeric key of an item.
|
|
48
|
+
* @returns The items with the minimum and maximum key, or `null` when no item
|
|
49
|
+
* has a key other than `NaN`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function minmaxBy<T>(items: Iterable<T>, valueOf: Callable<[T], number>): MinMaxItems<T> | null;
|
|
52
|
+
//# sourceMappingURL=minmax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minmax.d.ts","sourceRoot":"","sources":["../../src/select/minmax.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzD,yDAAyD;AACzD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,GAAG,EAAE,CAAC,CAAC;IACP,GAAG,EAAE,CAAC,CAAC;CACP,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACvB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GACpB,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAiCvB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACzB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC5B,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CA4BvB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest and the largest item under `compare`, in one pass — the
|
|
3
|
+
* comparator form of {@link minmaxBy}, named after `@ac-kit/core`'s `minmax`
|
|
4
|
+
* over numbers (d3's `extent`).
|
|
5
|
+
*
|
|
6
|
+
* Takes the items in pairs, ordering each pair first and then testing only its
|
|
7
|
+
* smaller item against the minimum and its larger against the maximum: three
|
|
8
|
+
* comparisons per two items rather than the four of two separate scans. Ties
|
|
9
|
+
* resolve to the first item seen, for the minimum and the maximum alike.
|
|
10
|
+
*
|
|
11
|
+
* Time complexity: O(n), about `3n / 2` calls to `compare`. Memory: O(1).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* minmax(["pear", "fig", "apple"], compareNaturalAscending);
|
|
16
|
+
* // { min: "apple", max: "pear" }
|
|
17
|
+
* ```;
|
|
18
|
+
*
|
|
19
|
+
* @param items - The items, read once.
|
|
20
|
+
* @param compare - A strict weak ordering of the items.
|
|
21
|
+
* @returns The minimum and maximum, or `null` for an empty input.
|
|
22
|
+
*/
|
|
23
|
+
export function minmax(items, compare) {
|
|
24
|
+
const iterator = items[Symbol.iterator]();
|
|
25
|
+
const first = iterator.next();
|
|
26
|
+
if (first.done === true) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
let min = first.value;
|
|
30
|
+
let max = first.value;
|
|
31
|
+
for (;;) {
|
|
32
|
+
const one = iterator.next();
|
|
33
|
+
if (one.done === true) {
|
|
34
|
+
return { min, max };
|
|
35
|
+
}
|
|
36
|
+
const other = iterator.next();
|
|
37
|
+
if (other.done === true) {
|
|
38
|
+
if (compare(one.value, min) < 0) {
|
|
39
|
+
min = one.value;
|
|
40
|
+
}
|
|
41
|
+
else if (compare(one.value, max) > 0) {
|
|
42
|
+
max = one.value;
|
|
43
|
+
}
|
|
44
|
+
return { min, max };
|
|
45
|
+
}
|
|
46
|
+
const order = compare(one.value, other.value);
|
|
47
|
+
// On a tie both candidates are the earlier item, `one`.
|
|
48
|
+
const smaller = order > 0 ? other.value : one.value;
|
|
49
|
+
const larger = order < 0 ? other.value : one.value;
|
|
50
|
+
if (compare(smaller, min) < 0) {
|
|
51
|
+
min = smaller;
|
|
52
|
+
}
|
|
53
|
+
if (compare(larger, max) > 0) {
|
|
54
|
+
max = larger;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The items with the smallest and the largest `valueOf(item)`, in one pass —
|
|
60
|
+
* the accessor form of {@link minmax}, as `minBy` and `maxBy` are of their
|
|
61
|
+
* comparator forms.
|
|
62
|
+
*
|
|
63
|
+
* `valueOf` is called once per item. An item whose value is `NaN` has no place
|
|
64
|
+
* in the order and is skipped, so it is never returned. Ties resolve to the
|
|
65
|
+
* first item seen; `-0` and `0` tie.
|
|
66
|
+
*
|
|
67
|
+
* Time complexity: O(n). Memory: O(1).
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* minmaxBy(orders, (order) => order.total); // cheapest and dearest order
|
|
72
|
+
* ```;
|
|
73
|
+
*
|
|
74
|
+
* @param items - The items, read once.
|
|
75
|
+
* @param valueOf - The numeric key of an item.
|
|
76
|
+
* @returns The items with the minimum and maximum key, or `null` when no item
|
|
77
|
+
* has a key other than `NaN`.
|
|
78
|
+
*/
|
|
79
|
+
export function minmaxBy(items, valueOf) {
|
|
80
|
+
let min;
|
|
81
|
+
let max;
|
|
82
|
+
let minValue = Infinity;
|
|
83
|
+
let maxValue = -Infinity;
|
|
84
|
+
let found = false;
|
|
85
|
+
for (const item of items) {
|
|
86
|
+
const value = valueOf(item);
|
|
87
|
+
if (value !== value) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!found) {
|
|
91
|
+
min = item;
|
|
92
|
+
max = item;
|
|
93
|
+
minValue = value;
|
|
94
|
+
maxValue = value;
|
|
95
|
+
found = true;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (value < minValue) {
|
|
99
|
+
min = item;
|
|
100
|
+
minValue = value;
|
|
101
|
+
}
|
|
102
|
+
else if (value > maxValue) {
|
|
103
|
+
max = item;
|
|
104
|
+
maxValue = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return found ? { min: min, max: max } : null;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=minmax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minmax.js","sourceRoot":"","sources":["../../src/select/minmax.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CACrB,KAAkB,EAClB,OAAsB;IAEtB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC;IACtB,IAAI,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC;IACtB,SAAS,CAAC;QACT,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACvB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC;QACD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACzB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC;YACjB,CAAC;iBAAM,IAAI,OAAO,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ACZ,GAAG,GAAG,IAAI,CAAC;YACX,GAAG,GAAG,IAAI,CAAC;YACX,QAAQ,GAAG,KAAK,CAAC;YACjB,QAAQ,GAAG,KAAK,CAAC;YACjB,KAAK,GAAG,IAAI,CAAC;YACb,SAAS;QACV,CAAC;QACD,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YACtB,GAAG,GAAG,IAAI,CAAC;YACX,QAAQ,GAAG,KAAK,CAAC;QAClB,CAAC;aAAM,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YAC7B,GAAG,GAAG,IAAI,CAAC;YACX,QAAQ,GAAG,KAAK,CAAC;QAClB,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAI,EAAE,GAAG,EAAE,GAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC"}
|
|
@@ -11,5 +11,5 @@ import type { Comparator } from "@ac-kit/core";
|
|
|
11
11
|
* @param compare Total order to select by.
|
|
12
12
|
* @returns The value that belongs at index `k`.
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
//# sourceMappingURL=quickselect.d.ts.map
|
|
14
|
+
export declare function quickselectInPlace<T>(items: T[], k: number, compare: Comparator<T>): T;
|
|
15
|
+
//# sourceMappingURL=quickselect-in-place.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickselect-in-place.d.ts","sourceRoot":"","sources":["../../src/select/quickselect-in-place.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EACnC,KAAK,EAAE,CAAC,EAAE,EACV,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GACpB,CAAC,CAmCH"}
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* @param compare Total order to select by.
|
|
11
11
|
* @returns The value that belongs at index `k`.
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
13
|
+
export function quickselectInPlace(items, k, compare) {
|
|
14
14
|
let left = 0;
|
|
15
15
|
let right = items.length - 1;
|
|
16
16
|
while (left < right) {
|
|
17
|
-
const pivot = items[
|
|
17
|
+
const pivot = items[left + Math.floor((right - left) / 2)];
|
|
18
18
|
let lower = left;
|
|
19
19
|
let upper = right;
|
|
20
20
|
while (lower <= upper) {
|
|
@@ -44,4 +44,4 @@ export function quickselect(items, k, compare) {
|
|
|
44
44
|
}
|
|
45
45
|
return items[k];
|
|
46
46
|
}
|
|
47
|
-
//# sourceMappingURL=quickselect.js.map
|
|
47
|
+
//# sourceMappingURL=quickselect-in-place.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickselect-in-place.js","sourceRoot":"","sources":["../../src/select/quickselect-in-place.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAU,EACV,CAAS,EACT,OAAsB;IAEtB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAE7B,OAAO,IAAI,GAAG,KAAK,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC;QAC5D,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,IAAI,KAAK,GAAG,KAAK,CAAC;QAElB,OAAO,KAAK,IAAI,KAAK,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1C,KAAK,EAAE,CAAC;YACT,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1C,KAAK,EAAE,CAAC;YACT,CAAC;YACD,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;gBACpB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;gBAC3B,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;gBAC7B,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;gBACpB,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;YACT,CAAC;QACF,CAAC;QAED,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;YAChB,KAAK,GAAG,KAAK,CAAC;QACf,CAAC;aAAM,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,GAAG,KAAK,CAAC;QACd,CAAC;aAAM,CAAC;YACP,MAAM;QACP,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,CAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EqualityComparator } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The runs `a[aStart … aStart + length)` equal to `b[bStart … bStart + length)`
|
|
4
|
+
* of a shortest edit script turning `a` into `b`, as flat `[aStart, bStart,
|
|
5
|
+
* length, …]` triples in order and merged where contiguous; their items form a
|
|
6
|
+
* longest common subsequence.
|
|
7
|
+
*
|
|
8
|
+
* Myers' O(ND) algorithm in its linear-space form (Myers, 1986, §4b): the
|
|
9
|
+
* forward and backward searches meet on a "middle snake", which splits the
|
|
10
|
+
* problem in two; each part is trimmed of its common prefix and suffix and
|
|
11
|
+
* split again. The parts wait on an explicit stack, so there is no recursion,
|
|
12
|
+
* and the two diagonal arrays are allocated once for the largest part. O((n +
|
|
13
|
+
* m) · D) time for `D` the edit distance, O(n + m) memory.
|
|
14
|
+
*/
|
|
15
|
+
export declare function matchingRuns_<T>(a: ArrayLike<T>, b: ArrayLike<T>, equals: EqualityComparator<T, T>): number[];
|
|
16
|
+
//# sourceMappingURL=_matching-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_matching-runs.d.ts","sourceRoot":"","sources":["../../src/sequence/_matching-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC9B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC9B,MAAM,EAAE,CA6EV"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runs `a[aStart … aStart + length)` equal to `b[bStart … bStart + length)`
|
|
3
|
+
* of a shortest edit script turning `a` into `b`, as flat `[aStart, bStart,
|
|
4
|
+
* length, …]` triples in order and merged where contiguous; their items form a
|
|
5
|
+
* longest common subsequence.
|
|
6
|
+
*
|
|
7
|
+
* Myers' O(ND) algorithm in its linear-space form (Myers, 1986, §4b): the
|
|
8
|
+
* forward and backward searches meet on a "middle snake", which splits the
|
|
9
|
+
* problem in two; each part is trimmed of its common prefix and suffix and
|
|
10
|
+
* split again. The parts wait on an explicit stack, so there is no recursion,
|
|
11
|
+
* and the two diagonal arrays are allocated once for the largest part. O((n +
|
|
12
|
+
* m) · D) time for `D` the edit distance, O(n + m) memory.
|
|
13
|
+
*/
|
|
14
|
+
export function matchingRuns_(a, b, equals) {
|
|
15
|
+
const matches = [];
|
|
16
|
+
// Boxes still to align, as [aLow, aHigh, bLow, bHigh] quadruples.
|
|
17
|
+
const boxes = [0, a.length, 0, b.length];
|
|
18
|
+
let forward;
|
|
19
|
+
let backward;
|
|
20
|
+
const splitPoint = new Int32Array(2);
|
|
21
|
+
while (boxes.length > 0) {
|
|
22
|
+
let bHigh = boxes.pop();
|
|
23
|
+
let bLow = boxes.pop();
|
|
24
|
+
let aHigh = boxes.pop();
|
|
25
|
+
let aLow = boxes.pop();
|
|
26
|
+
let prefix = 0;
|
|
27
|
+
while (aLow + prefix < aHigh &&
|
|
28
|
+
bLow + prefix < bHigh &&
|
|
29
|
+
equals(a[aLow + prefix], b[bLow + prefix])) {
|
|
30
|
+
prefix++;
|
|
31
|
+
}
|
|
32
|
+
if (prefix > 0) {
|
|
33
|
+
matches.push(aLow, bLow, prefix);
|
|
34
|
+
aLow += prefix;
|
|
35
|
+
bLow += prefix;
|
|
36
|
+
}
|
|
37
|
+
let suffix = 0;
|
|
38
|
+
while (aHigh - suffix > aLow &&
|
|
39
|
+
bHigh - suffix > bLow &&
|
|
40
|
+
equals(a[aHigh - suffix - 1], b[bHigh - suffix - 1])) {
|
|
41
|
+
suffix++;
|
|
42
|
+
}
|
|
43
|
+
if (suffix > 0) {
|
|
44
|
+
matches.push(aHigh - suffix, bHigh - suffix, suffix);
|
|
45
|
+
aHigh -= suffix;
|
|
46
|
+
bHigh -= suffix;
|
|
47
|
+
}
|
|
48
|
+
if (aLow === aHigh || bLow === bHigh) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// Parts only shrink, so the first box sizes the arrays for every later one.
|
|
52
|
+
const size = aHigh - aLow + (bHigh - bLow) + 2;
|
|
53
|
+
forward ??= new Int32Array(size);
|
|
54
|
+
backward ??= new Int32Array(size);
|
|
55
|
+
const found = middleSnake_(a, b, equals, aLow, aHigh, bLow, bHigh, forward, backward, splitPoint);
|
|
56
|
+
if (!found) {
|
|
57
|
+
// Unreachable for two non-empty parts; keeps the loop finite regardless.
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const aSplit = aLow + splitPoint[0];
|
|
61
|
+
const bSplit = bLow + splitPoint[1];
|
|
62
|
+
if ((aSplit === aLow && bSplit === bLow) ||
|
|
63
|
+
(aSplit === aHigh && bSplit === bHigh)) {
|
|
64
|
+
// Unreachable too: a corner split would push the same box again.
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
boxes.push(aLow, aSplit, bLow, bSplit, aSplit, aHigh, bSplit, bHigh);
|
|
68
|
+
}
|
|
69
|
+
return sortAndMerge_(matches);
|
|
70
|
+
}
|
|
71
|
+
// Writes the meeting point of the forward and backward searches over the box,
|
|
72
|
+
// relative to its corner, to `point` as [x, y], and returns whether one was
|
|
73
|
+
// found. Follows Myers' furthest-reaching D-paths on diagonals k = x − y
|
|
74
|
+
// (forward) and on the reversed sequences (backward); `forward[offset + k]` is
|
|
75
|
+
// the furthest x on diagonal k.
|
|
76
|
+
function middleSnake_(a, b, equals, aLow, aHigh, bLow, bHigh, forward, backward, point) {
|
|
77
|
+
const n = aHigh - aLow;
|
|
78
|
+
const m = bHigh - bLow;
|
|
79
|
+
const maxD = Math.ceil((n + m) / 2);
|
|
80
|
+
const offset = maxD;
|
|
81
|
+
const length = 2 * maxD + 2;
|
|
82
|
+
forward.fill(-1, 0, length);
|
|
83
|
+
backward.fill(-1, 0, length);
|
|
84
|
+
forward[offset + 1] = 0;
|
|
85
|
+
backward[offset + 1] = 0;
|
|
86
|
+
const delta = n - m;
|
|
87
|
+
// With an odd delta the paths meet while extending forward, else backward.
|
|
88
|
+
const meetForward = delta % 2 !== 0;
|
|
89
|
+
let forwardStart = 0;
|
|
90
|
+
let forwardEnd = 0;
|
|
91
|
+
let backwardStart = 0;
|
|
92
|
+
let backwardEnd = 0;
|
|
93
|
+
for (let d = 0; d < maxD; d++) {
|
|
94
|
+
for (let k = -d + forwardStart; k <= d - forwardEnd; k += 2) {
|
|
95
|
+
const at = offset + k;
|
|
96
|
+
let x = k === -d || (k !== d && forward[at - 1] < forward[at + 1])
|
|
97
|
+
? forward[at + 1]
|
|
98
|
+
: forward[at - 1] + 1;
|
|
99
|
+
let y = x - k;
|
|
100
|
+
while (x < n && y < m && equals(a[aLow + x], b[bLow + y])) {
|
|
101
|
+
x++;
|
|
102
|
+
y++;
|
|
103
|
+
}
|
|
104
|
+
forward[at] = x;
|
|
105
|
+
if (x > n) {
|
|
106
|
+
forwardEnd += 2;
|
|
107
|
+
}
|
|
108
|
+
else if (y > m) {
|
|
109
|
+
forwardStart += 2;
|
|
110
|
+
}
|
|
111
|
+
else if (meetForward) {
|
|
112
|
+
const opposite = offset + delta - k;
|
|
113
|
+
if (opposite >= 0 && opposite < length && backward[opposite] !== -1) {
|
|
114
|
+
if (x >= n - backward[opposite]) {
|
|
115
|
+
point[0] = x;
|
|
116
|
+
point[1] = y;
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (let k = -d + backwardStart; k <= d - backwardEnd; k += 2) {
|
|
123
|
+
const at = offset + k;
|
|
124
|
+
let x = k === -d || (k !== d && backward[at - 1] < backward[at + 1])
|
|
125
|
+
? backward[at + 1]
|
|
126
|
+
: backward[at - 1] + 1;
|
|
127
|
+
let y = x - k;
|
|
128
|
+
while (x < n && y < m && equals(a[aHigh - x - 1], b[bHigh - y - 1])) {
|
|
129
|
+
x++;
|
|
130
|
+
y++;
|
|
131
|
+
}
|
|
132
|
+
backward[at] = x;
|
|
133
|
+
if (x > n) {
|
|
134
|
+
backwardEnd += 2;
|
|
135
|
+
}
|
|
136
|
+
else if (y > m) {
|
|
137
|
+
backwardStart += 2;
|
|
138
|
+
}
|
|
139
|
+
else if (!meetForward) {
|
|
140
|
+
const opposite = offset + delta - k;
|
|
141
|
+
if (opposite >= 0 && opposite < length && forward[opposite] !== -1) {
|
|
142
|
+
const forwardX = forward[opposite];
|
|
143
|
+
if (forwardX >= n - x) {
|
|
144
|
+
point[0] = forwardX;
|
|
145
|
+
point[1] = offset + forwardX - opposite;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
// Boxes finish in stack order, not left to right, but the runs of one script
|
|
155
|
+
// never overlap and increase in both sequences, so sorting by a-start orders
|
|
156
|
+
// them; touching runs are then merged.
|
|
157
|
+
function sortAndMerge_(matches) {
|
|
158
|
+
const count = matches.length / 3;
|
|
159
|
+
const order = Array.from({ length: count }, (_, index) => index);
|
|
160
|
+
order.sort((left, right) => matches[left * 3] - matches[right * 3]);
|
|
161
|
+
const merged = [];
|
|
162
|
+
for (const index of order) {
|
|
163
|
+
const aStart = matches[index * 3];
|
|
164
|
+
const bStart = matches[index * 3 + 1];
|
|
165
|
+
const length = matches[index * 3 + 2];
|
|
166
|
+
const last = merged.length - 3;
|
|
167
|
+
if (last >= 0 &&
|
|
168
|
+
merged[last] + merged[last + 2] === aStart &&
|
|
169
|
+
merged[last + 1] + merged[last + 2] === bStart) {
|
|
170
|
+
merged[last + 2] += length;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
merged.push(aStart, bStart, length);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return merged;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=_matching-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_matching-runs.js","sourceRoot":"","sources":["../../src/sequence/_matching-runs.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC5B,CAAe,EACf,CAAe,EACf,MAAgC;IAEhC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,kEAAkE;IAClE,MAAM,KAAK,GAAa,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACnD,IAAI,OAA+B,CAAC;IACpC,IAAI,QAAgC,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAErC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,IAA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,GAAG,CAAC,CAAE,IAAI,MAAM,CAAC;QAC7B,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* How many leading items two sequences share: the largest `n` with `a[i]` equal
|
|
4
|
+
* to `b[i]` for every `i < n`. The trim step every diff opens with, and what a
|
|
5
|
+
* path resolver or an autocomplete needs to find where two inputs part.
|
|
6
|
+
*
|
|
7
|
+
* Strings work as they are (one item per UTF-16 code unit); split them into
|
|
8
|
+
* code points or graphemes first when a surrogate pair must not be cut.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) for `n` the result, at most `min(a.length, b.length)`
|
|
11
|
+
* comparisons. Memory: O(1).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* commonPrefixLength(["src", "algo", "a.ts"], ["src", "algo", "b.ts"]); // 2
|
|
16
|
+
* commonPrefixLength("interstellar", "internet"); // 5
|
|
17
|
+
* ```;
|
|
18
|
+
*
|
|
19
|
+
* @param a - One sequence.
|
|
20
|
+
* @param b - The other sequence.
|
|
21
|
+
* @param comparisonStrategy - How `a[i]` is compared with `b[i]`. Default
|
|
22
|
+
* `"strict"`.
|
|
23
|
+
* @returns The length of the common prefix, in `[0, min(a.length, b.length)]`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function commonPrefixLength<T>(a: ArrayLike<T>, b: ArrayLike<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): number;
|
|
26
|
+
//# sourceMappingURL=common-prefix-length.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-prefix-length.d.ts","sourceRoot":"","sources":["../../src/sequence/common-prefix-length.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,0BAA0B,EAC/B,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EACnC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAY,GAC7D,MAAM,CAQR"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { resolveEqualityComparator, } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* How many leading items two sequences share: the largest `n` with `a[i]` equal
|
|
4
|
+
* to `b[i]` for every `i < n`. The trim step every diff opens with, and what a
|
|
5
|
+
* path resolver or an autocomplete needs to find where two inputs part.
|
|
6
|
+
*
|
|
7
|
+
* Strings work as they are (one item per UTF-16 code unit); split them into
|
|
8
|
+
* code points or graphemes first when a surrogate pair must not be cut.
|
|
9
|
+
*
|
|
10
|
+
* Time complexity: O(n) for `n` the result, at most `min(a.length, b.length)`
|
|
11
|
+
* comparisons. Memory: O(1).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* commonPrefixLength(["src", "algo", "a.ts"], ["src", "algo", "b.ts"]); // 2
|
|
16
|
+
* commonPrefixLength("interstellar", "internet"); // 5
|
|
17
|
+
* ```;
|
|
18
|
+
*
|
|
19
|
+
* @param a - One sequence.
|
|
20
|
+
* @param b - The other sequence.
|
|
21
|
+
* @param comparisonStrategy - How `a[i]` is compared with `b[i]`. Default
|
|
22
|
+
* `"strict"`.
|
|
23
|
+
* @returns The length of the common prefix, in `[0, min(a.length, b.length)]`.
|
|
24
|
+
*/
|
|
25
|
+
export function commonPrefixLength(a, b, comparisonStrategy = "strict") {
|
|
26
|
+
const equals = resolveEqualityComparator(comparisonStrategy);
|
|
27
|
+
const length = Math.min(a.length, b.length);
|
|
28
|
+
let index = 0;
|
|
29
|
+
while (index < length && equals(a[index], b[index])) {
|
|
30
|
+
index++;
|
|
31
|
+
}
|
|
32
|
+
return index;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=common-prefix-length.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-prefix-length.js","sourceRoot":"","sources":["../../src/sequence/common-prefix-length.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,yBAAyB,GAEzB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,kBAAkB,CACjC,CAAe,EACf,CAAe,EACf,kBAAkB,GAAqC,QAAQ;IAE/D,MAAM,MAAM,GAAG,yBAAyB,CAAC,kBAAkB,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAE,EAAE,CAAC,CAAC,KAAK,CAAE,CAAC,EAAE,CAAC;QACvD,KAAK,EAAE,CAAC;IACT,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/** What a {@link DiffRun} does to its stretch of the sequences. */
|
|
3
|
+
export type DiffOperation = "keep" | "delete" | "insert";
|
|
4
|
+
/** One stretch of an edit script turning `a` into `b`. */
|
|
5
|
+
export type DiffRun = {
|
|
6
|
+
/**
|
|
7
|
+
* `"keep"`: `a[aIndex …]` equals `b[bIndex …]` over `length` items;
|
|
8
|
+
* `"delete"`: `a[aIndex …]` is removed; `"insert"`: `b[bIndex …]` is added.
|
|
9
|
+
*/
|
|
10
|
+
readonly operation: DiffOperation;
|
|
11
|
+
/**
|
|
12
|
+
* Where the run starts in `a` — for an insertion, the position in `a` it is
|
|
13
|
+
* inserted before.
|
|
14
|
+
*/
|
|
15
|
+
readonly aIndex: number;
|
|
16
|
+
/**
|
|
17
|
+
* Where the run starts in `b` — for a deletion, the position in `b` that
|
|
18
|
+
* follows the gap it leaves.
|
|
19
|
+
*/
|
|
20
|
+
readonly bIndex: number;
|
|
21
|
+
/** How many items the run covers, at least 1. */
|
|
22
|
+
readonly length: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A shortest edit script turning `a` into `b`: the runs of kept, deleted and
|
|
26
|
+
* inserted items, in order — what a diff view, a patch or a keyed list update
|
|
27
|
+
* consumes. Generic over the items, so it diffs characters, lines, tokens or
|
|
28
|
+
* records alike.
|
|
29
|
+
*
|
|
30
|
+
* Myers' O(ND) algorithm in linear space (the one behind `git diff` and GNU
|
|
31
|
+
* diff), without recursion. "Shortest" counts deleted and inserted items, so
|
|
32
|
+
* the kept items form a longest common subsequence (see
|
|
33
|
+
* {@link longestCommonSubsequence}). Between two kept runs, the deletion comes
|
|
34
|
+
* before the insertion; consecutive runs never share an operation; the kept and
|
|
35
|
+
* deleted runs tile `a`, and the kept and inserted runs tile `b`.
|
|
36
|
+
*
|
|
37
|
+
* Time complexity: O((n + m) · D) for `D` the number of deleted and inserted
|
|
38
|
+
* items, so near-identical inputs diff in near-linear time; O((n + m)²) in the
|
|
39
|
+
* worst case. Memory: O(n + m).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* diffSequences(["a", "b", "c"], ["a", "x", "c"]);
|
|
44
|
+
* // [
|
|
45
|
+
* // { operation: "keep", aIndex: 0, bIndex: 0, length: 1 },
|
|
46
|
+
* // { operation: "delete", aIndex: 1, bIndex: 1, length: 1 },
|
|
47
|
+
* // { operation: "insert", aIndex: 2, bIndex: 1, length: 1 },
|
|
48
|
+
* // { operation: "keep", aIndex: 2, bIndex: 2, length: 1 },
|
|
49
|
+
* // ]
|
|
50
|
+
* ```;
|
|
51
|
+
*
|
|
52
|
+
* @param a - The source sequence.
|
|
53
|
+
* @param b - The target sequence.
|
|
54
|
+
* @param comparisonStrategy - How an item of `a` is compared with an item of
|
|
55
|
+
* `b`, always in that argument order. Default `"strict"`.
|
|
56
|
+
* @returns The runs, in order; empty when both sequences are.
|
|
57
|
+
*/
|
|
58
|
+
export declare function diffSequences<T>(a: ArrayLike<T>, b: ArrayLike<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): DiffRun[];
|
|
59
|
+
//# sourceMappingURL=diff-sequences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-sequences.d.ts","sourceRoot":"","sources":["../../src/sequence/diff-sequences.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,0BAA0B,EAC/B,MAAM,cAAc,CAAC;AAItB,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEzD,0DAA0D;AAC1D,MAAM,MAAM,OAAO,GAAG;IACrB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC9B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACf,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAY,GAC7D,OAAO,EAAE,CAiCX"}
|