@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.
Files changed (144) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +28 -0
  3. package/README.md +70 -0
  4. package/dist/distribute/spread-evenly.d.ts +17 -0
  5. package/dist/distribute/spread-evenly.d.ts.map +1 -0
  6. package/dist/distribute/spread-evenly.js +41 -0
  7. package/dist/distribute/spread-evenly.js.map +1 -0
  8. package/dist/graph/_search-by-priority.d.ts +42 -0
  9. package/dist/graph/_search-by-priority.d.ts.map +1 -0
  10. package/dist/graph/_search-by-priority.js +56 -0
  11. package/dist/graph/_search-by-priority.js.map +1 -0
  12. package/dist/graph/a-star.d.ts +19 -0
  13. package/dist/graph/a-star.d.ts.map +1 -0
  14. package/dist/graph/a-star.js +20 -0
  15. package/dist/graph/a-star.js.map +1 -0
  16. package/dist/graph/best-first-search.d.ts +25 -0
  17. package/dist/graph/best-first-search.d.ts.map +1 -0
  18. package/dist/graph/best-first-search.js +26 -0
  19. package/dist/graph/best-first-search.js.map +1 -0
  20. package/dist/graph/dfs.d.ts +46 -0
  21. package/dist/graph/dfs.d.ts.map +1 -0
  22. package/dist/graph/dfs.js +49 -0
  23. package/dist/graph/dfs.js.map +1 -0
  24. package/dist/group/_partition-into.d.ts +3 -0
  25. package/dist/group/_partition-into.d.ts.map +1 -0
  26. package/dist/group/_partition-into.js +11 -0
  27. package/dist/group/_partition-into.js.map +1 -0
  28. package/dist/group/group-by.d.ts +33 -0
  29. package/dist/group/group-by.d.ts.map +1 -0
  30. package/dist/group/group-by.js +51 -0
  31. package/dist/group/group-by.js.map +1 -0
  32. package/dist/group/partition-indices.d.ts +11 -0
  33. package/dist/group/partition-indices.d.ts.map +1 -0
  34. package/dist/group/partition-indices.js +13 -0
  35. package/dist/group/partition-indices.js.map +1 -0
  36. package/dist/group/partition.d.ts +10 -0
  37. package/dist/group/partition.d.ts.map +1 -0
  38. package/dist/group/partition.js +12 -0
  39. package/dist/group/partition.js.map +1 -0
  40. package/dist/index.d.ts +31 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +31 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/interval/is-in-sorted-intervals.d.ts +17 -0
  45. package/dist/interval/is-in-sorted-intervals.d.ts.map +1 -0
  46. package/dist/interval/is-in-sorted-intervals.js +21 -0
  47. package/dist/interval/is-in-sorted-intervals.js.map +1 -0
  48. package/dist/optimize/backtrack.d.ts +38 -0
  49. package/dist/optimize/backtrack.d.ts.map +1 -0
  50. package/dist/optimize/backtrack.js +56 -0
  51. package/dist/optimize/backtrack.js.map +1 -0
  52. package/dist/optimize/beam-search.d.ts +34 -0
  53. package/dist/optimize/beam-search.d.ts.map +1 -0
  54. package/dist/optimize/beam-search.js +42 -0
  55. package/dist/optimize/beam-search.js.map +1 -0
  56. package/dist/ordered/_binary-search.d.ts +13 -0
  57. package/dist/ordered/_binary-search.d.ts.map +1 -0
  58. package/dist/ordered/_binary-search.js +24 -0
  59. package/dist/ordered/_binary-search.js.map +1 -0
  60. package/dist/ordered/bisect-center.d.ts +18 -0
  61. package/dist/ordered/bisect-center.d.ts.map +1 -0
  62. package/dist/ordered/bisect-center.js +29 -0
  63. package/dist/ordered/bisect-center.js.map +1 -0
  64. package/dist/ordered/bisect-left.d.ts +15 -0
  65. package/dist/ordered/bisect-left.d.ts.map +1 -0
  66. package/dist/ordered/bisect-left.js +18 -0
  67. package/dist/ordered/bisect-left.js.map +1 -0
  68. package/dist/ordered/bisect-right.d.ts +15 -0
  69. package/dist/ordered/bisect-right.d.ts.map +1 -0
  70. package/dist/ordered/bisect-right.js +18 -0
  71. package/dist/ordered/bisect-right.js.map +1 -0
  72. package/dist/ordered/bisect.d.ts +2 -0
  73. package/dist/ordered/bisect.d.ts.map +1 -0
  74. package/dist/ordered/bisect.js +2 -0
  75. package/dist/ordered/bisect.js.map +1 -0
  76. package/dist/ordered/create-bisector.d.ts +30 -0
  77. package/dist/ordered/create-bisector.d.ts.map +1 -0
  78. package/dist/ordered/create-bisector.js +32 -0
  79. package/dist/ordered/create-bisector.js.map +1 -0
  80. package/dist/sample/shuffle.d.ts +31 -0
  81. package/dist/sample/shuffle.d.ts.map +1 -0
  82. package/dist/sample/shuffle.js +33 -0
  83. package/dist/sample/shuffle.js.map +1 -0
  84. package/dist/select/_extreme-by.d.ts +11 -0
  85. package/dist/select/_extreme-by.d.ts.map +1 -0
  86. package/dist/select/_extreme-by.js +23 -0
  87. package/dist/select/_extreme-by.js.map +1 -0
  88. package/dist/select/max-by.d.ts +13 -0
  89. package/dist/select/max-by.d.ts.map +1 -0
  90. package/dist/select/max-by.js +15 -0
  91. package/dist/select/max-by.js.map +1 -0
  92. package/dist/select/min-by.d.ts +13 -0
  93. package/dist/select/min-by.d.ts.map +1 -0
  94. package/dist/select/min-by.js +15 -0
  95. package/dist/select/min-by.js.map +1 -0
  96. package/dist/select/quickselect.d.ts +15 -0
  97. package/dist/select/quickselect.d.ts.map +1 -0
  98. package/dist/select/quickselect.js +47 -0
  99. package/dist/select/quickselect.js.map +1 -0
  100. package/dist/select/select-at.d.ts +11 -0
  101. package/dist/select/select-at.d.ts.map +1 -0
  102. package/dist/select/select-at.js +13 -0
  103. package/dist/select/select-at.js.map +1 -0
  104. package/dist/set/difference.d.ts +13 -0
  105. package/dist/set/difference.d.ts.map +1 -0
  106. package/dist/set/difference.js +20 -0
  107. package/dist/set/difference.js.map +1 -0
  108. package/dist/set/intersection.d.ts +16 -0
  109. package/dist/set/intersection.d.ts.map +1 -0
  110. package/dist/set/intersection.js +43 -0
  111. package/dist/set/intersection.js.map +1 -0
  112. package/dist/set/is-disjoint-from.d.ts +13 -0
  113. package/dist/set/is-disjoint-from.d.ts.map +1 -0
  114. package/dist/set/is-disjoint-from.js +20 -0
  115. package/dist/set/is-disjoint-from.js.map +1 -0
  116. package/dist/set/is-subset-of.d.ts +13 -0
  117. package/dist/set/is-subset-of.d.ts.map +1 -0
  118. package/dist/set/is-subset-of.js +20 -0
  119. package/dist/set/is-subset-of.js.map +1 -0
  120. package/dist/set/is-superset-of.d.ts +14 -0
  121. package/dist/set/is-superset-of.d.ts.map +1 -0
  122. package/dist/set/is-superset-of.js +21 -0
  123. package/dist/set/is-superset-of.js.map +1 -0
  124. package/dist/set/symmetric-difference.d.ts +13 -0
  125. package/dist/set/symmetric-difference.d.ts.map +1 -0
  126. package/dist/set/symmetric-difference.js +20 -0
  127. package/dist/set/symmetric-difference.js.map +1 -0
  128. package/dist/set/union.d.ts +13 -0
  129. package/dist/set/union.d.ts.map +1 -0
  130. package/dist/set/union.js +28 -0
  131. package/dist/set/union.js.map +1 -0
  132. package/dist/set/uniq-by.d.ts +25 -0
  133. package/dist/set/uniq-by.d.ts.map +1 -0
  134. package/dist/set/uniq-by.js +48 -0
  135. package/dist/set/uniq-by.js.map +1 -0
  136. package/dist/set/uniq.d.ts +14 -0
  137. package/dist/set/uniq.d.ts.map +1 -0
  138. package/dist/set/uniq.js +34 -0
  139. package/dist/set/uniq.js.map +1 -0
  140. package/dist/sort/radix-sort.d.ts +14 -0
  141. package/dist/sort/radix-sort.d.ts.map +1 -0
  142. package/dist/sort/radix-sort.js +58 -0
  143. package/dist/sort/radix-sort.js.map +1 -0
  144. package/package.json +64 -0
@@ -0,0 +1,20 @@
1
+ import { EnhancedSet } from "@ac-kit/data";
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 function symmetricDifference(a, b, comparisonStrategy = "sameValueZero") {
13
+ if (comparisonStrategy === "sameValueZero") {
14
+ return new Set(a).symmetricDifference(new Set(b));
15
+ }
16
+ const sa = new EnhancedSet(a, { comparisonStrategy });
17
+ const sb = new EnhancedSet(b, { comparisonStrategy });
18
+ return sa.symmetricDifference(sb);
19
+ }
20
+ //# sourceMappingURL=symmetric-difference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symmetric-difference.js","sourceRoot":"","sources":["../../src/set/symmetric-difference.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAClC,CAAc,EACd,CAAc,EACd,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,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,mBAAmB,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type EqualityComparisonStrategy } from "@ac-kit/core";
2
+ /**
3
+ * Computes the union of any number of iterables.
4
+ *
5
+ * Time complexity: O(n) total across every source iterable, under the default
6
+ * `"sameValueZero"`.
7
+ *
8
+ * @param iterables The iterables to union.
9
+ * @param comparisonStrategy The equality comparison strategy to use.
10
+ * @returns A `Set` containing every distinct element across all iterables.
11
+ */
12
+ export declare function union<T>(iterables: readonly Iterable<T>[], comparisonStrategy?: EqualityComparisonStrategy<T, T>): Iterable<T>;
13
+ //# sourceMappingURL=union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/set/union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACtB,SAAS,EAAE,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,EACjC,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,QAAQ,CAAC,CAAC,CAAC,CAoBb"}
@@ -0,0 +1,28 @@
1
+ import { EnhancedSet } from "@ac-kit/data";
2
+ /**
3
+ * Computes the union of any number of iterables.
4
+ *
5
+ * Time complexity: O(n) total across every source iterable, under the default
6
+ * `"sameValueZero"`.
7
+ *
8
+ * @param iterables The iterables to union.
9
+ * @param comparisonStrategy The equality comparison strategy to use.
10
+ * @returns A `Set` containing every distinct element across all iterables.
11
+ */
12
+ export function union(iterables, comparisonStrategy = "sameValueZero") {
13
+ if (comparisonStrategy === "sameValueZero") {
14
+ const result = new Set();
15
+ for (const iterable of iterables) {
16
+ for (const item of iterable) {
17
+ result.add(item);
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ const result = new EnhancedSet(undefined, { comparisonStrategy });
23
+ for (const iterable of iterables) {
24
+ result.addAll(iterable);
25
+ }
26
+ return result;
27
+ }
28
+ //# sourceMappingURL=union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/set/union.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,KAAK,CACpB,SAAiC,EACjC,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAK,CAAC;QAE5B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,WAAW,CAAI,SAAS,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAErE,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type Callable, type EqualityComparisonStrategy } from "@ac-kit/core";
2
+ /**
3
+ * Yields the first item seen for each distinct `keyOf(item)`, in
4
+ * first-occurrence order.
5
+ *
6
+ * Time complexity: O(n) under the default `"sameValueZero"`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const array = [
11
+ * { id: 1, name: "Alice" },
12
+ * { id: 2, name: "Bob" },
13
+ * { id: 1, name: "Alice" },
14
+ * ];
15
+ * [...uniqBy(array, (item) => item.id)];
16
+ * // [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]
17
+ * ```;
18
+ *
19
+ * @param iterable The input iterable.
20
+ * @param keyOf A function that takes an item and returns a key.
21
+ * @param comparisonStrategy The equality comparison strategy for keys.
22
+ * @returns An iterator over the first item seen for each distinct key.
23
+ */
24
+ export declare function uniqBy<T, U>(iterable: Iterable<T>, keyOf: Callable<[T], U>, comparisonStrategy?: EqualityComparisonStrategy<U, U>): IterableIterator<T>;
25
+ //# sourceMappingURL=uniq-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniq-by.d.ts","sourceRoot":"","sources":["../../src/set/uniq-by.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,0BAA0B,EAE/B,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAiB,MAAM,CAAC,CAAC,EAAE,CAAC,EAC3B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,gBAAgB,CAAC,CAAC,CAAC,CAyBrB"}
@@ -0,0 +1,48 @@
1
+ import { FastSet, } from "@ac-kit/core";
2
+ import { EnhancedSet } from "@ac-kit/data";
3
+ /**
4
+ * Yields the first item seen for each distinct `keyOf(item)`, in
5
+ * first-occurrence order.
6
+ *
7
+ * Time complexity: O(n) under the default `"sameValueZero"`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const array = [
12
+ * { id: 1, name: "Alice" },
13
+ * { id: 2, name: "Bob" },
14
+ * { id: 1, name: "Alice" },
15
+ * ];
16
+ * [...uniqBy(array, (item) => item.id)];
17
+ * // [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]
18
+ * ```;
19
+ *
20
+ * @param iterable The input iterable.
21
+ * @param keyOf A function that takes an item and returns a key.
22
+ * @param comparisonStrategy The equality comparison strategy for keys.
23
+ * @returns An iterator over the first item seen for each distinct key.
24
+ */
25
+ export function* uniqBy(iterable, keyOf, comparisonStrategy = "sameValueZero") {
26
+ if (comparisonStrategy === "sameValueZero") {
27
+ const seen = new FastSet();
28
+ for (const item of iterable) {
29
+ const key = keyOf(item);
30
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#same-value-zero_equality
31
+ if (!seen.has(key)) {
32
+ seen.add(key);
33
+ yield item;
34
+ }
35
+ }
36
+ }
37
+ else {
38
+ const seen = new EnhancedSet(undefined, { comparisonStrategy });
39
+ for (const item of iterable) {
40
+ const key = keyOf(item);
41
+ if (!seen.has(key)) {
42
+ seen.add(key);
43
+ yield item;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ //# sourceMappingURL=uniq-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniq-by.js","sourceRoot":"","sources":["../../src/set/uniq-by.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,OAAO,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CACtB,QAAqB,EACrB,KAAuB,EACvB,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,OAAO,EAAK,CAAC;QAE9B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAExB,2HAA2H;YAC3H,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,IAAI,CAAC;YACZ,CAAC;QACF,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,GAAG,IAAI,WAAW,CAAI,SAAS,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAEnE,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAExB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,IAAI,CAAC;YACZ,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { DefinedValue, EqualityComparisonStrategy } from "@ac-kit/core";
2
+ /**
3
+ * Yields each distinct value of an iterable, in first-occurrence order.
4
+ *
5
+ * Time complexity: O(n) under the default `"sameValueZero"` strategy. **Any
6
+ * other strategy is O(n²)**.
7
+ *
8
+ * @param iterable The input iterable.
9
+ * @param comparisonStrategy The equality comparison strategy to use (default is
10
+ * "sameValueZero").
11
+ * @returns An iterator over the distinct values.
12
+ */
13
+ export declare function uniq<T extends DefinedValue>(iterable: Iterable<T>, comparisonStrategy?: EqualityComparisonStrategy<T, T>): IterableIterator<T>;
14
+ //# sourceMappingURL=uniq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/set/uniq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAGxE;;;;;;;;;;GAUG;AACH,wBAAiB,IAAI,CAAC,CAAC,SAAS,YAAY,EAC3C,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,kBAAkB,GAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAmB,GACpE,gBAAgB,CAAC,CAAC,CAAC,CAqBrB"}
@@ -0,0 +1,34 @@
1
+ import { EnhancedSet } from "@ac-kit/data";
2
+ /**
3
+ * Yields each distinct value of an iterable, in first-occurrence order.
4
+ *
5
+ * Time complexity: O(n) under the default `"sameValueZero"` strategy. **Any
6
+ * other strategy is O(n²)**.
7
+ *
8
+ * @param iterable The input iterable.
9
+ * @param comparisonStrategy The equality comparison strategy to use (default is
10
+ * "sameValueZero").
11
+ * @returns An iterator over the distinct values.
12
+ */
13
+ export function* uniq(iterable, comparisonStrategy = "sameValueZero") {
14
+ if (comparisonStrategy === "sameValueZero") {
15
+ const seen = new Set();
16
+ for (const item of iterable) {
17
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#same-value-zero_equality
18
+ if (!seen.has(item)) {
19
+ seen.add(item);
20
+ yield item;
21
+ }
22
+ }
23
+ }
24
+ else {
25
+ const seen = new EnhancedSet(undefined, { comparisonStrategy });
26
+ for (const item of iterable) {
27
+ if (!seen.has(item)) {
28
+ seen.add(item);
29
+ yield item;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ //# sourceMappingURL=uniq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniq.js","sourceRoot":"","sources":["../../src/set/uniq.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,SAAS,CAAC,CAAC,IAAI,CACpB,QAAqB,EACrB,kBAAkB,GAAqC,eAAe;IAEtE,IAAI,kBAAkB,KAAK,eAAe,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAK,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC7B,2HAA2H;YAC3H,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACf,MAAM,IAAI,CAAC;YACZ,CAAC;QACF,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,SAAS,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAEhE,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACf,MAAM,IAAI,CAAC;YACZ,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ /**
3
+ * Sorts `items` ascending by a non-negative integer key, stable — LSD radix
4
+ * sort, O(n · k) for k the number of 8-bit digits the largest key needs. Never
5
+ * calls a comparator, so it beats comparison sorts by a wide margin on large
6
+ * collections of integer-keyed items (raw numbers, coordinates, counts).
7
+ *
8
+ * @param items The items to sort. Not modified; a new array is returned.
9
+ * @param valueOf Extracts the non-negative integer sort key from an item.
10
+ * @returns A new array of `items` sorted ascending by `valueOf`.
11
+ * @throws {RangeError} If any key is negative or not a safe integer.
12
+ */
13
+ export declare function radixSort<T>(items: readonly T[], valueOf: Callable<[T], number>): T[];
14
+ //# sourceMappingURL=radix-sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radix-sort.d.ts","sourceRoot":"","sources":["../../src/sort/radix-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAK7C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC5B,CAAC,EAAE,CAkDL"}
@@ -0,0 +1,58 @@
1
+ const RADIX_BITS = 8;
2
+ const RADIX = 1 << RADIX_BITS;
3
+ /**
4
+ * Sorts `items` ascending by a non-negative integer key, stable — LSD radix
5
+ * sort, O(n · k) for k the number of 8-bit digits the largest key needs. Never
6
+ * calls a comparator, so it beats comparison sorts by a wide margin on large
7
+ * collections of integer-keyed items (raw numbers, coordinates, counts).
8
+ *
9
+ * @param items The items to sort. Not modified; a new array is returned.
10
+ * @param valueOf Extracts the non-negative integer sort key from an item.
11
+ * @returns A new array of `items` sorted ascending by `valueOf`.
12
+ * @throws {RangeError} If any key is negative or not a safe integer.
13
+ */
14
+ export function radixSort(items, valueOf) {
15
+ if (items.length <= 1) {
16
+ return items.slice();
17
+ }
18
+ const keys = Array.from({ length: items.length });
19
+ let maxKey = 0;
20
+ for (let index = 0; index < items.length; index++) {
21
+ const key = valueOf(items[index]);
22
+ if (!Number.isSafeInteger(key) || key < 0) {
23
+ throw new RangeError("radixSort keys must be non-negative safe integers");
24
+ }
25
+ keys[index] = key;
26
+ if (key > maxKey) {
27
+ maxKey = key;
28
+ }
29
+ }
30
+ let source = items.slice();
31
+ let sourceKeys = keys;
32
+ // One counting-sort pass per base-256 digit, least significant first.
33
+ // `divisor` is always a power of two, so dividing a safe integer by it
34
+ // stays exact in floating point regardless of magnitude.
35
+ for (let divisor = 1; Math.floor(maxKey / divisor) > 0; divisor *= RADIX) {
36
+ const counts = new Uint32Array(RADIX + 1);
37
+ for (let index = 0; index < sourceKeys.length; index++) {
38
+ const digit = Math.floor(sourceKeys[index] / divisor) % RADIX;
39
+ counts[digit + 1]++;
40
+ }
41
+ for (let digit = 0; digit < RADIX; digit++) {
42
+ counts[digit + 1] += counts[digit];
43
+ }
44
+ const destination = Array.from({ length: source.length });
45
+ const destinationKeys = Array.from({ length: source.length });
46
+ for (let index = 0; index < source.length; index++) {
47
+ const key = sourceKeys[index];
48
+ const digit = Math.floor(key / divisor) % RADIX;
49
+ const position = counts[digit]++;
50
+ destination[position] = source[index];
51
+ destinationKeys[position] = key;
52
+ }
53
+ source = destination;
54
+ sourceKeys = destinationKeys;
55
+ }
56
+ return source;
57
+ }
58
+ //# sourceMappingURL=radix-sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radix-sort.js","sourceRoot":"","sources":["../../src/sort/radix-sort.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@ac-kit/algo",
3
+ "version": "0.1.0",
4
+ "description": "Classic algorithms that work on your own types rather than on numbers: searching, sorting, grouping, graph traversal and string distance.",
5
+ "keywords": [
6
+ "algorithms",
7
+ "graph",
8
+ "search",
9
+ "sort",
10
+ "typescript"
11
+ ],
12
+ "homepage": "https://anthochamp.github.io/node-essentials/api/algo/",
13
+ "bugs": {
14
+ "url": "https://github.com/anthochamp/node-essentials/issues"
15
+ },
16
+ "license": "BSD-3-Clause",
17
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
21
+ "directory": "packages/algo"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.js",
29
+ "exports": {
30
+ ".": "./dist/index.js"
31
+ },
32
+ "publishConfig": {
33
+ "main": "./dist/index.js",
34
+ "exports": {
35
+ ".": "./dist/index.js"
36
+ },
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
41
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
42
+ "clean": "rimraf dist",
43
+ "build": "yarn clean && yarn compile",
44
+ "test": "yarn run -T vitest run",
45
+ "prepack": "yarn build"
46
+ },
47
+ "dependencies": {
48
+ "@ac-kit/core": "^0.1.0",
49
+ "@ac-kit/data": "^0.1.0",
50
+ "@types/web": "^0.0.354"
51
+ },
52
+ "devDependencies": {
53
+ "@ac-kit/tsconfig": "0.1.0",
54
+ "@ac-kit/typedoc-config": "0.1.0",
55
+ "@ac-kit/vitest-config": "0.1.0",
56
+ "@typescript/native": "typescript@7.0.2",
57
+ "rimraf": "6.1.3",
58
+ "typedoc": "0.28.20",
59
+ "typescript": "@typescript/typescript6@6.0.2"
60
+ },
61
+ "engines": {
62
+ "node": ">=24"
63
+ }
64
+ }