@ac-kit/algo 0.1.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 +7 -0
- package/LICENSE +28 -0
- package/README.md +70 -0
- package/dist/distribute/spread-evenly.d.ts +17 -0
- package/dist/distribute/spread-evenly.d.ts.map +1 -0
- package/dist/distribute/spread-evenly.js +41 -0
- package/dist/distribute/spread-evenly.js.map +1 -0
- package/dist/graph/_search-by-priority.d.ts +42 -0
- package/dist/graph/_search-by-priority.d.ts.map +1 -0
- package/dist/graph/_search-by-priority.js +56 -0
- package/dist/graph/_search-by-priority.js.map +1 -0
- package/dist/graph/a-star.d.ts +19 -0
- package/dist/graph/a-star.d.ts.map +1 -0
- package/dist/graph/a-star.js +20 -0
- package/dist/graph/a-star.js.map +1 -0
- package/dist/graph/best-first-search.d.ts +25 -0
- package/dist/graph/best-first-search.d.ts.map +1 -0
- package/dist/graph/best-first-search.js +26 -0
- package/dist/graph/best-first-search.js.map +1 -0
- package/dist/graph/dfs.d.ts +46 -0
- package/dist/graph/dfs.d.ts.map +1 -0
- package/dist/graph/dfs.js +49 -0
- package/dist/graph/dfs.js.map +1 -0
- package/dist/group/_partition-into.d.ts +3 -0
- package/dist/group/_partition-into.d.ts.map +1 -0
- package/dist/group/_partition-into.js +11 -0
- package/dist/group/_partition-into.js.map +1 -0
- package/dist/group/group-by.d.ts +33 -0
- package/dist/group/group-by.d.ts.map +1 -0
- package/dist/group/group-by.js +51 -0
- package/dist/group/group-by.js.map +1 -0
- package/dist/group/partition-indices.d.ts +11 -0
- package/dist/group/partition-indices.d.ts.map +1 -0
- package/dist/group/partition-indices.js +13 -0
- package/dist/group/partition-indices.js.map +1 -0
- package/dist/group/partition.d.ts +10 -0
- package/dist/group/partition.d.ts.map +1 -0
- package/dist/group/partition.js +12 -0
- package/dist/group/partition.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/interval/is-in-sorted-intervals.d.ts +17 -0
- package/dist/interval/is-in-sorted-intervals.d.ts.map +1 -0
- package/dist/interval/is-in-sorted-intervals.js +21 -0
- package/dist/interval/is-in-sorted-intervals.js.map +1 -0
- package/dist/optimize/backtrack.d.ts +38 -0
- package/dist/optimize/backtrack.d.ts.map +1 -0
- package/dist/optimize/backtrack.js +56 -0
- package/dist/optimize/backtrack.js.map +1 -0
- package/dist/optimize/beam-search.d.ts +34 -0
- package/dist/optimize/beam-search.d.ts.map +1 -0
- package/dist/optimize/beam-search.js +42 -0
- package/dist/optimize/beam-search.js.map +1 -0
- package/dist/ordered/_binary-search.d.ts +13 -0
- package/dist/ordered/_binary-search.d.ts.map +1 -0
- package/dist/ordered/_binary-search.js +24 -0
- package/dist/ordered/_binary-search.js.map +1 -0
- package/dist/ordered/bisect-center.d.ts +18 -0
- package/dist/ordered/bisect-center.d.ts.map +1 -0
- package/dist/ordered/bisect-center.js +29 -0
- package/dist/ordered/bisect-center.js.map +1 -0
- package/dist/ordered/bisect-left.d.ts +15 -0
- package/dist/ordered/bisect-left.d.ts.map +1 -0
- package/dist/ordered/bisect-left.js +18 -0
- package/dist/ordered/bisect-left.js.map +1 -0
- package/dist/ordered/bisect-right.d.ts +15 -0
- package/dist/ordered/bisect-right.d.ts.map +1 -0
- package/dist/ordered/bisect-right.js +18 -0
- package/dist/ordered/bisect-right.js.map +1 -0
- package/dist/ordered/bisect.d.ts +2 -0
- package/dist/ordered/bisect.d.ts.map +1 -0
- package/dist/ordered/bisect.js +2 -0
- package/dist/ordered/bisect.js.map +1 -0
- package/dist/ordered/create-bisector.d.ts +30 -0
- package/dist/ordered/create-bisector.d.ts.map +1 -0
- package/dist/ordered/create-bisector.js +32 -0
- package/dist/ordered/create-bisector.js.map +1 -0
- package/dist/sample/shuffle.d.ts +31 -0
- package/dist/sample/shuffle.d.ts.map +1 -0
- package/dist/sample/shuffle.js +33 -0
- package/dist/sample/shuffle.js.map +1 -0
- package/dist/select/_extreme-by.d.ts +11 -0
- package/dist/select/_extreme-by.d.ts.map +1 -0
- package/dist/select/_extreme-by.js +23 -0
- package/dist/select/_extreme-by.js.map +1 -0
- package/dist/select/max-by.d.ts +13 -0
- package/dist/select/max-by.d.ts.map +1 -0
- package/dist/select/max-by.js +15 -0
- package/dist/select/max-by.js.map +1 -0
- package/dist/select/min-by.d.ts +13 -0
- package/dist/select/min-by.d.ts.map +1 -0
- package/dist/select/min-by.js +15 -0
- package/dist/select/min-by.js.map +1 -0
- package/dist/select/quickselect.d.ts +15 -0
- package/dist/select/quickselect.d.ts.map +1 -0
- package/dist/select/quickselect.js +47 -0
- package/dist/select/quickselect.js.map +1 -0
- package/dist/select/select-at.d.ts +11 -0
- package/dist/select/select-at.d.ts.map +1 -0
- package/dist/select/select-at.js +13 -0
- package/dist/select/select-at.js.map +1 -0
- package/dist/set/difference.d.ts +13 -0
- package/dist/set/difference.d.ts.map +1 -0
- package/dist/set/difference.js +20 -0
- package/dist/set/difference.js.map +1 -0
- package/dist/set/intersection.d.ts +16 -0
- package/dist/set/intersection.d.ts.map +1 -0
- package/dist/set/intersection.js +43 -0
- package/dist/set/intersection.js.map +1 -0
- package/dist/set/is-disjoint-from.d.ts +13 -0
- package/dist/set/is-disjoint-from.d.ts.map +1 -0
- package/dist/set/is-disjoint-from.js +20 -0
- package/dist/set/is-disjoint-from.js.map +1 -0
- package/dist/set/is-subset-of.d.ts +13 -0
- package/dist/set/is-subset-of.d.ts.map +1 -0
- package/dist/set/is-subset-of.js +20 -0
- package/dist/set/is-subset-of.js.map +1 -0
- package/dist/set/is-superset-of.d.ts +14 -0
- package/dist/set/is-superset-of.d.ts.map +1 -0
- package/dist/set/is-superset-of.js +21 -0
- package/dist/set/is-superset-of.js.map +1 -0
- package/dist/set/symmetric-difference.d.ts +13 -0
- package/dist/set/symmetric-difference.d.ts.map +1 -0
- package/dist/set/symmetric-difference.js +20 -0
- package/dist/set/symmetric-difference.js.map +1 -0
- package/dist/set/union.d.ts +13 -0
- package/dist/set/union.d.ts.map +1 -0
- package/dist/set/union.js +28 -0
- package/dist/set/union.js.map +1 -0
- package/dist/set/uniq-by.d.ts +25 -0
- package/dist/set/uniq-by.d.ts.map +1 -0
- package/dist/set/uniq-by.js +48 -0
- package/dist/set/uniq-by.js.map +1 -0
- package/dist/set/uniq.d.ts +14 -0
- package/dist/set/uniq.d.ts.map +1 -0
- package/dist/set/uniq.js +34 -0
- package/dist/set/uniq.js.map +1 -0
- package/dist/sort/radix-sort.d.ts +14 -0
- package/dist/sort/radix-sort.d.ts.map +1 -0
- package/dist/sort/radix-sort.js +58 -0
- package/dist/sort/radix-sort.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { compareNaturalAscending } from "@ac-kit/core";
|
|
2
|
+
import { bisectCenter } from "./bisect-center.js";
|
|
3
|
+
import { bisectLeft } from "./bisect-left.js";
|
|
4
|
+
import { bisectRight } from "./bisect-right.js";
|
|
5
|
+
/**
|
|
6
|
+
* Builds a {@link Bisector} that locates `value` among `items` by comparing
|
|
7
|
+
* `valueOf(item)` instead of `item` itself, in ascending natural order
|
|
8
|
+
* (`<`/`>`) — so `items` can be sorted by any derived key, not just `T`'s own
|
|
9
|
+
* order.
|
|
10
|
+
*
|
|
11
|
+
* `valueOf` is called once per comparison during each search, not once per item
|
|
12
|
+
* up front — binary search stays O(log n), it never materialises a mapped
|
|
13
|
+
* array.
|
|
14
|
+
*
|
|
15
|
+
* `center` is exposed only for a numeric key, since "nearest" needs a distance
|
|
16
|
+
* and no distance can be derived from an arbitrary ordering.
|
|
17
|
+
*
|
|
18
|
+
* @param valueOf Extracts the sort key from an item.
|
|
19
|
+
* @returns Bound `left` and `right` bisect functions, plus `center` for a
|
|
20
|
+
* numeric key.
|
|
21
|
+
*/
|
|
22
|
+
export function createBisector(valueOf) {
|
|
23
|
+
const compare = (item, value) => compareNaturalAscending(valueOf(item), value);
|
|
24
|
+
// `center` is present at runtime regardless; the return type is what hides
|
|
25
|
+
// it from callers whose key is not numeric.
|
|
26
|
+
return {
|
|
27
|
+
left: (items, value) => bisectLeft(items, value, compare),
|
|
28
|
+
right: (items, value) => bisectRight(items, value, compare),
|
|
29
|
+
center: (items, value) => bisectCenter(items, value, valueOf),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=create-bisector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-bisector.js","sourceRoot":"","sources":["../../src/ordered/create-bisector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAahD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAC7B,OAAyB;IAEzB,MAAM,OAAO,GAAG,CAAC,IAAO,EAAE,KAAQ,EAAE,EAAE,CACrC,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAE/C,2EAA2E;IAC3E,4CAA4C;IAC5C,OAAO;QACN,IAAI,EAAE,CAAC,KAAmB,EAAE,KAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC;QAC1E,KAAK,EAAE,CAAC,KAAmB,EAAE,KAAQ,EAAE,EAAE,CACxC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC;QACnC,MAAM,EAAE,CAAC,KAAmB,EAAE,KAAa,EAAE,EAAE,CAC9C,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAgC,CAAC;KAC3C,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Callable } from "@ac-kit/core";
|
|
2
|
+
export type ShuffleAlgorithm = "fisherYates" | "sattolo";
|
|
3
|
+
export type ShuffleOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* A random number generator function that returns a number in the range [0,
|
|
6
|
+
* 1).
|
|
7
|
+
*
|
|
8
|
+
* Defaults to `Math.random` if not provided.
|
|
9
|
+
*/
|
|
10
|
+
rand?: Callable<[], number>;
|
|
11
|
+
/**
|
|
12
|
+
* The shuffle algorithm to use.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to "fisherYates".
|
|
15
|
+
*/
|
|
16
|
+
algorithm?: ShuffleAlgorithm;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Shuffles `items` using the Fisher-Yates algorithm and returns a new shuffled
|
|
20
|
+
* array.
|
|
21
|
+
*
|
|
22
|
+
* Time complexity: O(n), one swap per element. Takes an array rather than an
|
|
23
|
+
* `Iterable` because the swap step indexes freely, so a stream would have to be
|
|
24
|
+
* materialized anyway.
|
|
25
|
+
*
|
|
26
|
+
* @param items - The items to shuffle. Not modified; a new array is returned.
|
|
27
|
+
* @param options - Optional shuffle options.
|
|
28
|
+
* @returns A new array containing the shuffled elements of the input.
|
|
29
|
+
*/
|
|
30
|
+
export declare function shuffle<T>(items: readonly T[], options?: ShuffleOptions): T[];
|
|
31
|
+
//# sourceMappingURL=shuffle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shuffle.d.ts","sourceRoot":"","sources":["../../src/sample/shuffle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,SAAS,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC5B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAE5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC,EAAE,CAuB7E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shuffles `items` using the Fisher-Yates algorithm and returns a new shuffled
|
|
3
|
+
* array.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(n), one swap per element. Takes an array rather than an
|
|
6
|
+
* `Iterable` because the swap step indexes freely, so a stream would have to be
|
|
7
|
+
* materialized anyway.
|
|
8
|
+
*
|
|
9
|
+
* @param items - The items to shuffle. Not modified; a new array is returned.
|
|
10
|
+
* @param options - Optional shuffle options.
|
|
11
|
+
* @returns A new array containing the shuffled elements of the input.
|
|
12
|
+
*/
|
|
13
|
+
export function shuffle(items, options) {
|
|
14
|
+
const rand = options?.rand ?? Math.random;
|
|
15
|
+
const algorithm = options?.algorithm ?? "fisherYates";
|
|
16
|
+
const randomize = (i) => {
|
|
17
|
+
if (algorithm === "sattolo") {
|
|
18
|
+
return Math.floor(rand() * i);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return Math.floor(rand() * (i + 1));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const out = items.slice();
|
|
25
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
26
|
+
const j = randomize(i);
|
|
27
|
+
const tmp = out[i];
|
|
28
|
+
out[i] = out[j];
|
|
29
|
+
out[j] = tmp;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=shuffle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shuffle.js","sourceRoot":"","sources":["../../src/sample/shuffle.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAI,KAAmB,EAAE,OAAwB;IACvE,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC;IAC1C,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,aAAa,CAAC;IAEtD,MAAM,SAAS,GAAG,CAAC,CAAS,EAAU,EAAE;QACvC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAEvB,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAE,CAAC;QACpB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAE,CAAC;QACjB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACd,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Callable, Predicate } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The shared single-pass scan behind `minBy` and `maxBy`, parameterized only by
|
|
4
|
+
* which of two projected values wins.
|
|
5
|
+
*
|
|
6
|
+
* `valueOf` is called exactly once per item rather than once per comparison,
|
|
7
|
+
* which is the whole reason the accessor forms exist beside the comparator
|
|
8
|
+
* ones.
|
|
9
|
+
*/
|
|
10
|
+
export declare function extremeBy_<T>(iterable: Iterable<T>, valueOf: Callable<[T], number>, isBetter: Predicate<[value: number, best: number]>): T | null;
|
|
11
|
+
//# sourceMappingURL=_extreme-by.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_extreme-by.d.ts","sourceRoot":"","sources":["../../src/select/_extreme-by.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAC9B,QAAQ,EAAE,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAChD,CAAC,GAAG,IAAI,CAgBV"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared single-pass scan behind `minBy` and `maxBy`, parameterized only by
|
|
3
|
+
* which of two projected values wins.
|
|
4
|
+
*
|
|
5
|
+
* `valueOf` is called exactly once per item rather than once per comparison,
|
|
6
|
+
* which is the whole reason the accessor forms exist beside the comparator
|
|
7
|
+
* ones.
|
|
8
|
+
*/
|
|
9
|
+
export function extremeBy_(iterable, valueOf, isBetter) {
|
|
10
|
+
let best;
|
|
11
|
+
let bestValue = 0;
|
|
12
|
+
let hasBest = false;
|
|
13
|
+
for (const item of iterable) {
|
|
14
|
+
const value = valueOf(item);
|
|
15
|
+
if (!hasBest || isBetter(value, bestValue)) {
|
|
16
|
+
best = item;
|
|
17
|
+
bestValue = value;
|
|
18
|
+
hasBest = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return hasBest ? best : null;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=_extreme-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_extreme-by.js","sourceRoot":"","sources":["../../src/select/_extreme-by.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACzB,QAAqB,EACrB,OAA8B,EAC9B,QAAkD;IAElD,IAAI,IAAO,CAAC;IACZ,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5C,IAAI,GAAG,IAAI,CAAC;YACZ,SAAS,GAAG,KAAK,CAAC;YAClB,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAC,IAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Callable } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the item with the largest `valueOf(item)`, or `null` if the iterable
|
|
4
|
+
* is empty. Ties resolve to the first item seen.
|
|
5
|
+
*
|
|
6
|
+
* Time complexity: O(n), with one `valueOf` call per item.
|
|
7
|
+
*
|
|
8
|
+
* @param iterable - The input iterable.
|
|
9
|
+
* @param valueOf - Numeric key extractor.
|
|
10
|
+
* @returns The maximum item, or `null` for an empty iterable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function maxBy<T>(iterable: Iterable<T>, valueOf: Callable<[T], number>): T | null;
|
|
13
|
+
//# sourceMappingURL=max-by.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-by.d.ts","sourceRoot":"","sources":["../../src/select/max-by.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC5B,CAAC,GAAG,IAAI,CAEV"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { extremeBy_ } from "./_extreme-by.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the item with the largest `valueOf(item)`, or `null` if the iterable
|
|
4
|
+
* is empty. Ties resolve to the first item seen.
|
|
5
|
+
*
|
|
6
|
+
* Time complexity: O(n), with one `valueOf` call per item.
|
|
7
|
+
*
|
|
8
|
+
* @param iterable - The input iterable.
|
|
9
|
+
* @param valueOf - Numeric key extractor.
|
|
10
|
+
* @returns The maximum item, or `null` for an empty iterable.
|
|
11
|
+
*/
|
|
12
|
+
export function maxBy(iterable, valueOf) {
|
|
13
|
+
return extremeBy_(iterable, valueOf, (value, best) => value > best);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=max-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-by.js","sourceRoot":"","sources":["../../src/select/max-by.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,UAAU,KAAK,CACpB,QAAqB,EACrB,OAA8B;IAE9B,OAAO,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Callable } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the item with the smallest `valueOf(item)`, or `null` if the iterable
|
|
4
|
+
* is empty. Ties resolve to the first item seen.
|
|
5
|
+
*
|
|
6
|
+
* Time complexity: O(n), with one `valueOf` call per item.
|
|
7
|
+
*
|
|
8
|
+
* @param iterable - The input iterable.
|
|
9
|
+
* @param valueOf - Numeric key extractor.
|
|
10
|
+
* @returns The minimum item, or `null` for an empty iterable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function minBy<T>(iterable: Iterable<T>, valueOf: Callable<[T], number>): T | null;
|
|
13
|
+
//# sourceMappingURL=min-by.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"min-by.d.ts","sourceRoot":"","sources":["../../src/select/min-by.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC5B,CAAC,GAAG,IAAI,CAEV"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { extremeBy_ } from "./_extreme-by.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the item with the smallest `valueOf(item)`, or `null` if the iterable
|
|
4
|
+
* is empty. Ties resolve to the first item seen.
|
|
5
|
+
*
|
|
6
|
+
* Time complexity: O(n), with one `valueOf` call per item.
|
|
7
|
+
*
|
|
8
|
+
* @param iterable - The input iterable.
|
|
9
|
+
* @param valueOf - Numeric key extractor.
|
|
10
|
+
* @returns The minimum item, or `null` for an empty iterable.
|
|
11
|
+
*/
|
|
12
|
+
export function minBy(iterable, valueOf) {
|
|
13
|
+
return extremeBy_(iterable, valueOf, (value, best) => value < best);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=min-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"min-by.js","sourceRoot":"","sources":["../../src/select/min-by.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,UAAU,KAAK,CACpB,QAAqB,EACrB,OAA8B;IAE9B,OAAO,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Comparator } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Rearranges `items` in place until the element at index `k` is the one a full
|
|
4
|
+
* sort by `compare` would have put there, and returns it — Hoare's selection
|
|
5
|
+
* algorithm.
|
|
6
|
+
*
|
|
7
|
+
* O(n) average, O(n²) worst case.
|
|
8
|
+
*
|
|
9
|
+
* @param items Working array, modified in place. `k` must be a valid index.
|
|
10
|
+
* @param k The rank to resolve (0-based).
|
|
11
|
+
* @param compare Total order to select by.
|
|
12
|
+
* @returns The value that belongs at index `k`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function quickselect<T>(items: T[], k: number, compare: Comparator<T>): T;
|
|
15
|
+
//# sourceMappingURL=quickselect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickselect.d.ts","sourceRoot":"","sources":["../../src/select/quickselect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EAAE,EACV,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GACpB,CAAC,CAmCH"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rearranges `items` in place until the element at index `k` is the one a full
|
|
3
|
+
* sort by `compare` would have put there, and returns it — Hoare's selection
|
|
4
|
+
* algorithm.
|
|
5
|
+
*
|
|
6
|
+
* O(n) average, O(n²) worst case.
|
|
7
|
+
*
|
|
8
|
+
* @param items Working array, modified in place. `k` must be a valid index.
|
|
9
|
+
* @param k The rank to resolve (0-based).
|
|
10
|
+
* @param compare Total order to select by.
|
|
11
|
+
* @returns The value that belongs at index `k`.
|
|
12
|
+
*/
|
|
13
|
+
export function quickselect(items, k, compare) {
|
|
14
|
+
let left = 0;
|
|
15
|
+
let right = items.length - 1;
|
|
16
|
+
while (left < right) {
|
|
17
|
+
const pivot = items[(left + right) >> 1];
|
|
18
|
+
let lower = left;
|
|
19
|
+
let upper = right;
|
|
20
|
+
while (lower <= upper) {
|
|
21
|
+
while (compare(items[lower], pivot) < 0) {
|
|
22
|
+
lower++;
|
|
23
|
+
}
|
|
24
|
+
while (compare(items[upper], pivot) > 0) {
|
|
25
|
+
upper--;
|
|
26
|
+
}
|
|
27
|
+
if (lower <= upper) {
|
|
28
|
+
const swap = items[lower];
|
|
29
|
+
items[lower] = items[upper];
|
|
30
|
+
items[upper] = swap;
|
|
31
|
+
lower++;
|
|
32
|
+
upper--;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (k <= upper) {
|
|
36
|
+
right = upper;
|
|
37
|
+
}
|
|
38
|
+
else if (k >= lower) {
|
|
39
|
+
left = lower;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return items[k];
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=quickselect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickselect.js","sourceRoot":"","sources":["../../src/select/quickselect.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAC1B,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,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAE,CAAC;QAC1C,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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns elements of `array` at the given `indices`.
|
|
3
|
+
*
|
|
4
|
+
* Equivalent to lodash's `_.at`. All indices must be valid.
|
|
5
|
+
*
|
|
6
|
+
* @param array - The source array.
|
|
7
|
+
* @param indices - Positions to select.
|
|
8
|
+
* @returns A new array of elements at those positions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function selectAt<T>(array: readonly T[], indices: readonly number[]): T[];
|
|
11
|
+
//# sourceMappingURL=select-at.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-at.d.ts","sourceRoot":"","sources":["../../src/select/select-at.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,OAAO,EAAE,SAAS,MAAM,EAAE,GACxB,CAAC,EAAE,CAEL"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns elements of `array` at the given `indices`.
|
|
3
|
+
*
|
|
4
|
+
* Equivalent to lodash's `_.at`. All indices must be valid.
|
|
5
|
+
*
|
|
6
|
+
* @param array - The source array.
|
|
7
|
+
* @param indices - Positions to select.
|
|
8
|
+
* @returns A new array of elements at those positions.
|
|
9
|
+
*/
|
|
10
|
+
export function selectAt(array, indices) {
|
|
11
|
+
return indices.map((i) => array[i]);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=select-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-at.js","sourceRoot":"","sources":["../../src/select/select-at.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CACvB,KAAmB,EACnB,OAA0B;IAE1B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the elements in `a` that are not in `b`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The iterable to subtract from.
|
|
8
|
+
* @param b The iterable of elements to exclude.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns A `Set` of the elements present in `a` but not in `b`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function difference<T>(a: Iterable<T>, b: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): Iterable<T>;
|
|
13
|
+
//# sourceMappingURL=difference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"difference.d.ts","sourceRoot":"","sources":["../../src/set/difference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,QAAQ,CAAC,CAAC,CAAC,CASb"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnhancedSet } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the elements in `a` that are not in `b`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The iterable to subtract from.
|
|
8
|
+
* @param b The iterable of elements to exclude.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns A `Set` of the elements present in `a` but not in `b`.
|
|
11
|
+
*/
|
|
12
|
+
export function difference(a, b, comparisonStrategy = "sameValueZero") {
|
|
13
|
+
if (comparisonStrategy === "sameValueZero") {
|
|
14
|
+
return new Set(a).difference(new Set(b));
|
|
15
|
+
}
|
|
16
|
+
const sa = new EnhancedSet(a, { comparisonStrategy });
|
|
17
|
+
const sb = new EnhancedSet(b, { comparisonStrategy });
|
|
18
|
+
return sa.difference(sb);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=difference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"difference.js","sourceRoot":"","sources":["../../src/set/difference.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACzB,CAAc,EACd,CAAc,EACd,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the intersection of any number of iterables.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(n) total across every source iterable — one `Set` is built
|
|
6
|
+
* per iterable after the first, and the running result is filtered against it,
|
|
7
|
+
* rather than re-scanning an array per candidate (which would make this
|
|
8
|
+
* quadratic). That holds under the default `"sameValueZero"`.
|
|
9
|
+
*
|
|
10
|
+
* @param iterables The iterables to intersect.
|
|
11
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
12
|
+
* @returns An iterable containing only the elements common to every input
|
|
13
|
+
* iterable.
|
|
14
|
+
*/
|
|
15
|
+
export declare function intersection<T>(iterables: readonly Iterable<T>[], comparisonStrategy?: EqualityComparisonStrategy<T, T>): Iterable<T>;
|
|
16
|
+
//# sourceMappingURL=intersection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../src/set/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC7B,SAAS,EAAE,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,EACjC,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,QAAQ,CAAC,CAAC,CAAC,CAoCb"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EnhancedSet } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the intersection of any number of iterables.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(n) total across every source iterable — one `Set` is built
|
|
6
|
+
* per iterable after the first, and the running result is filtered against it,
|
|
7
|
+
* rather than re-scanning an array per candidate (which would make this
|
|
8
|
+
* quadratic). That holds under the default `"sameValueZero"`.
|
|
9
|
+
*
|
|
10
|
+
* @param iterables The iterables to intersect.
|
|
11
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
12
|
+
* @returns An iterable containing only the elements common to every input
|
|
13
|
+
* iterable.
|
|
14
|
+
*/
|
|
15
|
+
export function intersection(iterables, comparisonStrategy = "sameValueZero") {
|
|
16
|
+
const [first, ...rest] = iterables;
|
|
17
|
+
if (first === undefined) {
|
|
18
|
+
return new Set();
|
|
19
|
+
}
|
|
20
|
+
if (comparisonStrategy === "sameValueZero") {
|
|
21
|
+
let result = new Set(first);
|
|
22
|
+
for (const iterable of rest) {
|
|
23
|
+
// Short-circuit if the running intersection is empty.
|
|
24
|
+
if (result.size === 0) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
const lookup = new Set(iterable);
|
|
28
|
+
result = result.intersection(lookup);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
let result = new EnhancedSet(first, { comparisonStrategy });
|
|
33
|
+
for (const iterable of rest) {
|
|
34
|
+
// Short-circuit if the running intersection is empty.
|
|
35
|
+
if (result.count() === 0) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const lookup = new EnhancedSet(iterable, { comparisonStrategy });
|
|
39
|
+
result = result.intersection(lookup);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../src/set/intersection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC3B,SAAiC,EACjC,kBAAkB,GAAqC,eAAe;IAEtE,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IAEnC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,IAAI,GAAG,EAAK,CAAC;IACrB,CAAC;IAED,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,IAAI,MAAM,GAAG,IAAI,GAAG,CAAI,KAAK,CAAC,CAAC;QAE/B,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC7B,sDAAsD;YACtD,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM;YACP,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;YACjC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED,IAAI,MAAM,GAAG,IAAI,WAAW,CAAI,KAAK,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE/D,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC7B,sDAAsD;QACtD,IAAI,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM;QACP,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,WAAW,CAAI,QAAQ,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;QACpE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether `a` and `b` share no elements.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The first iterable.
|
|
8
|
+
* @param b The second iterable.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` and `b` have no elements in common.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isDisjointFrom<T>(a: Iterable<T>, b: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): boolean;
|
|
13
|
+
//# sourceMappingURL=is-disjoint-from.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-disjoint-from.d.ts","sourceRoot":"","sources":["../../src/set/is-disjoint-from.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC/B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,OAAO,CAST"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnhancedSet } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether `a` and `b` share no elements.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The first iterable.
|
|
8
|
+
* @param b The second iterable.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` and `b` have no elements in common.
|
|
11
|
+
*/
|
|
12
|
+
export function isDisjointFrom(a, b, comparisonStrategy = "sameValueZero") {
|
|
13
|
+
if (comparisonStrategy === "sameValueZero") {
|
|
14
|
+
return new Set(a).isDisjointFrom(new Set(b));
|
|
15
|
+
}
|
|
16
|
+
const sa = new EnhancedSet(a, { comparisonStrategy });
|
|
17
|
+
const sb = new EnhancedSet(b, { comparisonStrategy });
|
|
18
|
+
return sa.isDisjointFrom(sb);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=is-disjoint-from.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-disjoint-from.js","sourceRoot":"","sources":["../../src/set/is-disjoint-from.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC7B,CAAc,EACd,CAAc,EACd,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether every element of `a` is also in `b`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The candidate subset.
|
|
8
|
+
* @param b The candidate superset.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` is a subset of `b` (every element of `a` is in `b`).
|
|
11
|
+
*/
|
|
12
|
+
export declare function isSubsetOf<T>(a: Iterable<T>, b: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): boolean;
|
|
13
|
+
//# sourceMappingURL=is-subset-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-subset-of.d.ts","sourceRoot":"","sources":["../../src/set/is-subset-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,OAAO,CAST"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnhancedSet } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether every element of `a` is also in `b`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The candidate subset.
|
|
8
|
+
* @param b The candidate superset.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` is a subset of `b` (every element of `a` is in `b`).
|
|
11
|
+
*/
|
|
12
|
+
export function isSubsetOf(a, b, comparisonStrategy = "sameValueZero") {
|
|
13
|
+
if (comparisonStrategy === "sameValueZero") {
|
|
14
|
+
return new Set(a).isSubsetOf(new Set(b));
|
|
15
|
+
}
|
|
16
|
+
const sa = new EnhancedSet(a, { comparisonStrategy });
|
|
17
|
+
const sb = new EnhancedSet(b, { comparisonStrategy });
|
|
18
|
+
return sa.isSubsetOf(sb);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=is-subset-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-subset-of.js","sourceRoot":"","sources":["../../src/set/is-subset-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACzB,CAAc,EACd,CAAc,EACd,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether every element of `b` is also in `a`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The candidate superset.
|
|
8
|
+
* @param b The candidate subset.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` is a superset of `b` (every element of `b` is in
|
|
11
|
+
* `a`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSupersetOf<T>(a: Iterable<T>, b: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): boolean;
|
|
14
|
+
//# sourceMappingURL=is-superset-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-superset-of.d.ts","sourceRoot":"","sources":["../../src/set/is-superset-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC7B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,OAAO,CAST"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EnhancedSet } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether every element of `b` is also in `a`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The candidate superset.
|
|
8
|
+
* @param b The candidate subset.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns `true` if `a` is a superset of `b` (every element of `b` is in
|
|
11
|
+
* `a`).
|
|
12
|
+
*/
|
|
13
|
+
export function isSupersetOf(a, b, comparisonStrategy = "sameValueZero") {
|
|
14
|
+
if (comparisonStrategy === "sameValueZero") {
|
|
15
|
+
return new Set(a).isSupersetOf(new Set(b));
|
|
16
|
+
}
|
|
17
|
+
const sa = new EnhancedSet(a, { comparisonStrategy });
|
|
18
|
+
const sb = new EnhancedSet(b, { comparisonStrategy });
|
|
19
|
+
return sa.isSupersetOf(sb);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=is-superset-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-superset-of.js","sourceRoot":"","sources":["../../src/set/is-superset-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAC3B,CAAc,EACd,CAAc,EACd,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAI,CAAC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type EqualityComparisonStrategy } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the elements present in exactly one of `a` or `b`.
|
|
4
|
+
*
|
|
5
|
+
* Time complexity: O(|a| + |b|) under the default `"sameValueZero"`.
|
|
6
|
+
*
|
|
7
|
+
* @param a The first iterable.
|
|
8
|
+
* @param b The second iterable.
|
|
9
|
+
* @param comparisonStrategy The equality comparison strategy to use.
|
|
10
|
+
* @returns A `Set` of the elements in `a` or `b` but not both.
|
|
11
|
+
*/
|
|
12
|
+
export declare function symmetricDifference<T>(a: Iterable<T>, b: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): Iterable<T>;
|
|
13
|
+
//# sourceMappingURL=symmetric-difference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symmetric-difference.d.ts","sourceRoot":"","sources":["../../src/set/symmetric-difference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACpC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EACd,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,QAAQ,CAAC,CAAC,CAAC,CASb"}
|