@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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C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,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FractionalKeyAlphabet } from "./fractional-key-alphabet.js";
|
|
2
|
+
import { FractionalKeyError } from "./fractional-key-error.js";
|
|
3
|
+
/** The integer part's length (head included) for a head of value `head`. */
|
|
4
|
+
export declare function integerPartLength_(head: number, alphabet: FractionalKeyAlphabet): number;
|
|
5
|
+
/** Why `key` is not a key, or `null` if it is one. */
|
|
6
|
+
export declare function findKeyError_(key: string, alphabet: FractionalKeyAlphabet): FractionalKeyError | null;
|
|
7
|
+
/** Validates `key` and answers where its integer part ends. */
|
|
8
|
+
export declare function checkKey_(key: string, alphabet: FractionalKeyAlphabet): number;
|
|
9
|
+
/** Where a key already known valid ends its integer part. */
|
|
10
|
+
export declare function integerEnd_(key: string, alphabet: FractionalKeyAlphabet): number;
|
|
11
|
+
export declare function zeroInteger_(alphabet: FractionalKeyAlphabet): string;
|
|
12
|
+
export declare function isSmallestInteger_(integer: string, alphabet: FractionalKeyAlphabet): boolean;
|
|
13
|
+
/** The next integer part, or `null` past the largest one. `O(length)`. */
|
|
14
|
+
export declare function incrementInteger_(integer: string, alphabet: FractionalKeyAlphabet): string | null;
|
|
15
|
+
/** The previous integer part, or `null` below the smallest one. `O(length)`. */
|
|
16
|
+
export declare function decrementInteger_(integer: string, alphabet: FractionalKeyAlphabet): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* The fraction strictly between `lower` and `upper` (`null` for `1`) with the
|
|
19
|
+
* fewest digits, the middle one of those: the `n = 1` case of
|
|
20
|
+
* {@link fractionsBetween_}, without its arithmetic. `O(|lower| + |upper|)`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fractionBetween_(lower: string, upper: string | null, alphabet: FractionalKeyAlphabet): string;
|
|
23
|
+
/**
|
|
24
|
+
* `count ≥ 1` fractions strictly between `lower` and `upper` (`null` for `1`),
|
|
25
|
+
* ascending: the points dividing the interval into `count + 1` equal parts,
|
|
26
|
+
* rounded down at the coarsest precision that keeps them distinct, so each has
|
|
27
|
+
* at most `max(|lower|, |upper|) + ⌈log_base(count + 1)⌉` digits.
|
|
28
|
+
*
|
|
29
|
+
* Only the window of digits from the first difference on is computed, with a
|
|
30
|
+
* `bigint` while finding the precision and a digit array while stepping. `O(w² +
|
|
31
|
+
* count · (w + p))`, for a window of `w` digits after a shared prefix of `p`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fractionsBetween_(lower: string, upper: string | null, count: number, alphabet: FractionalKeyAlphabet): string[];
|
|
34
|
+
/** The key just above `key` (valid, its integer part ending at `end`). */
|
|
35
|
+
export declare function keyAfter_(key: string, end: number, alphabet: FractionalKeyAlphabet): string;
|
|
36
|
+
/** The key just below `key` (valid, its integer part ending at `end`). */
|
|
37
|
+
export declare function keyBefore_(key: string, end: number, alphabet: FractionalKeyAlphabet): string;
|
|
38
|
+
//# sourceMappingURL=_fractional-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fractional-key.d.ts","sourceRoot":"","sources":["../../src/ordered/_fractional-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAiB/D,4EAA4E;AAC5E,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CAIR;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,qBAAqB,GAC7B,kBAAkB,GAAG,IAAI,CAqC3B;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CACxB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CAOR;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAC1B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CAER;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,CAIpE;AAED,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,qBAAqB,GAC7B,OAAO,CAOT;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,GAAG,IAAI,CA4Bf;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,GAAG,IAAI,CAyBf;AAmCD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CA4BR;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,EAAE,CAmEV;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CACxB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CAKR;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CACzB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,qBAAqB,GAC7B,MAAM,CAcR"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { FractionalKeyError } from "./fractional-key-error.js";
|
|
2
|
+
/*
|
|
3
|
+
* A key is a head digit, the integer digits the head calls for, and a
|
|
4
|
+
* fraction:
|
|
5
|
+
*
|
|
6
|
+
* - With `N = ⌊base / 2⌋`, a head of value `h < N` starts a negative integer
|
|
7
|
+
* part of `N − h` digits, and `h ≥ N` a non-negative one of `h − N + 1`
|
|
8
|
+
* digits. Integer parts therefore sort by head first — longer negatives
|
|
9
|
+
* lower, longer non-negatives higher — then by their fixed-width digits.
|
|
10
|
+
* - The fraction is a base-`base` fraction `0.d₁d₂…`, possibly empty, never
|
|
11
|
+
* ending in the zero digit, so that string order on fractions is numeric
|
|
12
|
+
* order.
|
|
13
|
+
* - The smallest integer part (head 0, all zero digits) needs a fraction, so
|
|
14
|
+
* that every key has a key below it.
|
|
15
|
+
*/
|
|
16
|
+
/** The integer part's length (head included) for a head of value `head`. */
|
|
17
|
+
export function integerPartLength_(head, alphabet) {
|
|
18
|
+
const half = alphabet.base >> 1;
|
|
19
|
+
return 1 + (head < half ? half - head : head - half + 1);
|
|
20
|
+
}
|
|
21
|
+
/** Why `key` is not a key, or `null` if it is one. */
|
|
22
|
+
export function findKeyError_(key, alphabet) {
|
|
23
|
+
if (key.length === 0) {
|
|
24
|
+
return new FractionalKeyError(key, 0, "a key is never empty");
|
|
25
|
+
}
|
|
26
|
+
for (let index = 0; index < key.length; index++) {
|
|
27
|
+
if (alphabet.digitValue(key.charCodeAt(index)) < 0) {
|
|
28
|
+
return new FractionalKeyError(key, index, "not a digit of the alphabet");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const head = alphabet.digitValue(key.charCodeAt(0));
|
|
32
|
+
const end = integerPartLength_(head, alphabet);
|
|
33
|
+
if (key.length < end) {
|
|
34
|
+
return new FractionalKeyError(key, key.length, `the integer part needs ${end - 1} digits after its head`);
|
|
35
|
+
}
|
|
36
|
+
if (key.length > end &&
|
|
37
|
+
alphabet.digitValue(key.charCodeAt(key.length - 1)) === 0) {
|
|
38
|
+
return new FractionalKeyError(key, key.length - 1, "a fraction never ends in the zero digit");
|
|
39
|
+
}
|
|
40
|
+
if (key.length === end && isSmallestInteger_(key, alphabet)) {
|
|
41
|
+
return new FractionalKeyError(key, key.length, "the smallest integer part needs a fraction");
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/** Validates `key` and answers where its integer part ends. */
|
|
46
|
+
export function checkKey_(key, alphabet) {
|
|
47
|
+
const error = findKeyError_(key, alphabet);
|
|
48
|
+
if (error !== null) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
return integerPartLength_(alphabet.digitValue(key.charCodeAt(0)), alphabet);
|
|
52
|
+
}
|
|
53
|
+
/** Where a key already known valid ends its integer part. */
|
|
54
|
+
export function integerEnd_(key, alphabet) {
|
|
55
|
+
return integerPartLength_(alphabet.digitValue(key.charCodeAt(0)), alphabet);
|
|
56
|
+
}
|
|
57
|
+
export function zeroInteger_(alphabet) {
|
|
58
|
+
const { digits } = alphabet;
|
|
59
|
+
return digits[alphabet.base >> 1] + digits[0];
|
|
60
|
+
}
|
|
61
|
+
export function isSmallestInteger_(integer, alphabet) {
|
|
62
|
+
for (let index = 0; index < integer.length; index++) {
|
|
63
|
+
if (alphabet.digitValue(integer.charCodeAt(index)) !== 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
/** The next integer part, or `null` past the largest one. `O(length)`. */
|
|
70
|
+
export function incrementInteger_(integer, alphabet) {
|
|
71
|
+
const { base, digits } = alphabet;
|
|
72
|
+
let index = integer.length - 1;
|
|
73
|
+
while (index >= 1 &&
|
|
74
|
+
alphabet.digitValue(integer.charCodeAt(index)) === base - 1) {
|
|
75
|
+
index--;
|
|
76
|
+
}
|
|
77
|
+
if (index >= 1) {
|
|
78
|
+
const digit = alphabet.digitValue(integer.charCodeAt(index));
|
|
79
|
+
return (integer.slice(0, index) +
|
|
80
|
+
digits[digit + 1] +
|
|
81
|
+
digits[0].repeat(integer.length - 1 - index));
|
|
82
|
+
}
|
|
83
|
+
const head = alphabet.digitValue(integer.charCodeAt(0));
|
|
84
|
+
if (head === base - 1) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return (digits[head + 1] +
|
|
88
|
+
digits[0].repeat(integerPartLength_(head + 1, alphabet) - 1));
|
|
89
|
+
}
|
|
90
|
+
/** The previous integer part, or `null` below the smallest one. `O(length)`. */
|
|
91
|
+
export function decrementInteger_(integer, alphabet) {
|
|
92
|
+
const { base, digits } = alphabet;
|
|
93
|
+
let index = integer.length - 1;
|
|
94
|
+
while (index >= 1 && alphabet.digitValue(integer.charCodeAt(index)) === 0) {
|
|
95
|
+
index--;
|
|
96
|
+
}
|
|
97
|
+
if (index >= 1) {
|
|
98
|
+
const digit = alphabet.digitValue(integer.charCodeAt(index));
|
|
99
|
+
return (integer.slice(0, index) +
|
|
100
|
+
digits[digit - 1] +
|
|
101
|
+
digits[base - 1].repeat(integer.length - 1 - index));
|
|
102
|
+
}
|
|
103
|
+
const head = alphabet.digitValue(integer.charCodeAt(0));
|
|
104
|
+
if (head === 0) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return (digits[head - 1] +
|
|
108
|
+
digits[base - 1].repeat(integerPartLength_(head - 1, alphabet) - 1));
|
|
109
|
+
}
|
|
110
|
+
function digitAt_(fraction, index, alphabet) {
|
|
111
|
+
return index < fraction.length
|
|
112
|
+
? alphabet.digitValue(fraction.charCodeAt(index))
|
|
113
|
+
: 0;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Where `lower` and `upper` first differ, `lower` read with trailing zeros; `0`
|
|
117
|
+
* when `upper` is the open end `1`.
|
|
118
|
+
*/
|
|
119
|
+
function firstDifference_(lower, upper, alphabet) {
|
|
120
|
+
if (upper === null) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
let index = 0;
|
|
124
|
+
while (digitAt_(lower, index, alphabet) ===
|
|
125
|
+
alphabet.digitValue(upper.charCodeAt(index))) {
|
|
126
|
+
index++;
|
|
127
|
+
}
|
|
128
|
+
return index;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The fraction strictly between `lower` and `upper` (`null` for `1`) with the
|
|
132
|
+
* fewest digits, the middle one of those: the `n = 1` case of
|
|
133
|
+
* {@link fractionsBetween_}, without its arithmetic. `O(|lower| + |upper|)`.
|
|
134
|
+
*/
|
|
135
|
+
export function fractionBetween_(lower, upper, alphabet) {
|
|
136
|
+
const { base, digits } = alphabet;
|
|
137
|
+
let index = firstDifference_(lower, upper, alphabet);
|
|
138
|
+
let result = upper === null ? "" : upper.slice(0, index);
|
|
139
|
+
if (upper !== null) {
|
|
140
|
+
const low = digitAt_(lower, index, alphabet);
|
|
141
|
+
const high = alphabet.digitValue(upper.charCodeAt(index));
|
|
142
|
+
const gap = high - low + (upper.length > index + 1 ? 1 : 0);
|
|
143
|
+
if (gap >= 2) {
|
|
144
|
+
return result + digits[low + (gap >> 1)];
|
|
145
|
+
}
|
|
146
|
+
// `upper` ends right after `low + 1`: continue above `lower` towards 1.
|
|
147
|
+
result += digits[low];
|
|
148
|
+
index++;
|
|
149
|
+
}
|
|
150
|
+
for (;;) {
|
|
151
|
+
const low = digitAt_(lower, index, alphabet);
|
|
152
|
+
const gap = base - low;
|
|
153
|
+
if (gap >= 2) {
|
|
154
|
+
return result + digits[low + (gap >> 1)];
|
|
155
|
+
}
|
|
156
|
+
result += digits[low];
|
|
157
|
+
index++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* `count ≥ 1` fractions strictly between `lower` and `upper` (`null` for `1`),
|
|
162
|
+
* ascending: the points dividing the interval into `count + 1` equal parts,
|
|
163
|
+
* rounded down at the coarsest precision that keeps them distinct, so each has
|
|
164
|
+
* at most `max(|lower|, |upper|) + ⌈log_base(count + 1)⌉` digits.
|
|
165
|
+
*
|
|
166
|
+
* Only the window of digits from the first difference on is computed, with a
|
|
167
|
+
* `bigint` while finding the precision and a digit array while stepping. `O(w² +
|
|
168
|
+
* count · (w + p))`, for a window of `w` digits after a shared prefix of `p`.
|
|
169
|
+
*/
|
|
170
|
+
export function fractionsBetween_(lower, upper, count, alphabet) {
|
|
171
|
+
const { base, digits } = alphabet;
|
|
172
|
+
const bigBase = BigInt(base);
|
|
173
|
+
const parts = BigInt(count + 1);
|
|
174
|
+
const start = firstDifference_(lower, upper, alphabet);
|
|
175
|
+
const prefix = upper === null ? "" : upper.slice(0, start);
|
|
176
|
+
// The window [low, high) scaled by base^width; `1` is one unit at width 0.
|
|
177
|
+
let low = 0n;
|
|
178
|
+
let highFloor = upper === null ? 1n : 0n;
|
|
179
|
+
let gap = 0n;
|
|
180
|
+
let width = 0;
|
|
181
|
+
do {
|
|
182
|
+
const position = start + width;
|
|
183
|
+
low = low * bigBase + BigInt(digitAt_(lower, position, alphabet));
|
|
184
|
+
highFloor =
|
|
185
|
+
highFloor * bigBase +
|
|
186
|
+
BigInt(upper === null ? 0 : digitAt_(upper, position, alphabet));
|
|
187
|
+
width++;
|
|
188
|
+
const highCeiling = upper !== null && upper.length > position + 1
|
|
189
|
+
? highFloor + 1n
|
|
190
|
+
: highFloor;
|
|
191
|
+
gap = highCeiling - low;
|
|
192
|
+
} while (gap < parts);
|
|
193
|
+
const point = new Uint8Array(width);
|
|
194
|
+
const step = new Uint8Array(width);
|
|
195
|
+
let quotient = gap / parts;
|
|
196
|
+
for (let position = width - 1; position >= 0; position--) {
|
|
197
|
+
point[position] = digitAt_(lower, start + position, alphabet);
|
|
198
|
+
step[position] = Number(quotient % bigBase);
|
|
199
|
+
quotient /= bigBase;
|
|
200
|
+
}
|
|
201
|
+
// point_j = low + ⌊j · gap / parts⌋, stepped by ⌊gap / parts⌋ plus a carry
|
|
202
|
+
// from the remainder, Bresenham-style.
|
|
203
|
+
const remainder = Number(gap % parts);
|
|
204
|
+
const partCount = count + 1;
|
|
205
|
+
let accumulated = 0;
|
|
206
|
+
const fractions = new Array(count);
|
|
207
|
+
for (let index = 0; index < count; index++) {
|
|
208
|
+
accumulated += remainder;
|
|
209
|
+
let carry = 0;
|
|
210
|
+
if (accumulated >= partCount) {
|
|
211
|
+
accumulated -= partCount;
|
|
212
|
+
carry = 1;
|
|
213
|
+
}
|
|
214
|
+
for (let position = width - 1; position >= 0; position--) {
|
|
215
|
+
const sum = point[position] + step[position] + carry;
|
|
216
|
+
carry = sum >= base ? 1 : 0;
|
|
217
|
+
point[position] = sum - carry * base;
|
|
218
|
+
}
|
|
219
|
+
let last = width - 1;
|
|
220
|
+
while (point[last] === 0) {
|
|
221
|
+
last--;
|
|
222
|
+
}
|
|
223
|
+
let fraction = prefix;
|
|
224
|
+
for (let position = 0; position <= last; position++) {
|
|
225
|
+
fraction += digits[point[position]];
|
|
226
|
+
}
|
|
227
|
+
fractions[index] = fraction;
|
|
228
|
+
}
|
|
229
|
+
return fractions;
|
|
230
|
+
}
|
|
231
|
+
/** The key just above `key` (valid, its integer part ending at `end`). */
|
|
232
|
+
export function keyAfter_(key, end, alphabet) {
|
|
233
|
+
const integer = key.slice(0, end);
|
|
234
|
+
const next = incrementInteger_(integer, alphabet);
|
|
235
|
+
return next ?? integer + fractionBetween_(key.slice(end), null, alphabet);
|
|
236
|
+
}
|
|
237
|
+
/** The key just below `key` (valid, its integer part ending at `end`). */
|
|
238
|
+
export function keyBefore_(key, end, alphabet) {
|
|
239
|
+
const integer = key.slice(0, end);
|
|
240
|
+
if (key.length > end) {
|
|
241
|
+
return isSmallestInteger_(integer, alphabet)
|
|
242
|
+
? integer + fractionBetween_("", key.slice(end), alphabet)
|
|
243
|
+
: integer;
|
|
244
|
+
}
|
|
245
|
+
// Only the smallest integer has no predecessor, and it never stands alone.
|
|
246
|
+
const previous = decrementInteger_(integer, alphabet);
|
|
247
|
+
return isSmallestInteger_(previous, alphabet)
|
|
248
|
+
? previous + fractionBetween_("", null, alphabet)
|
|
249
|
+
: previous;
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=_fractional-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fractional-key.js","sourceRoot":"","sources":["../../src/ordered/_fractional-key.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AAEH,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB,CACjC,IAAY,EACZ,QAA+B;IAE/B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;IAEhC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,aAAa,CAC5B,GAAW,EACX,QAA+B;IAE/B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACt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,GAAG,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAElD,OAAO,IAAI,IAAI,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CACzB,GAAW,EACX,GAAW,EACX,QAA+B;IAE/B,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAElC,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtB,OAAO,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC;YAC3C,CAAC,CAAC,OAAO,GAAG,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;YAC1D,CAAC,CAAC,OAAO,CAAC;IACZ,CAAC;IACD,2EAA2E;IAC3E,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAE,CAAC;IAEvD,OAAO,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC5C,CAAC,CAAC,QAAQ,GAAG,gBAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC;QACjD,CAAC,CAAC,QAAQ,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link bisectRightNumbers} of every value: `out[i]` is how many elements of
|
|
3
|
+
* `items` are `≤ values[i]`, the index after the last of them. The searches run
|
|
4
|
+
* inside one loop, so no number crosses a call per value and nothing is
|
|
5
|
+
* allocated, wherever the call is made from.
|
|
6
|
+
*
|
|
7
|
+
* O(m log n) for m values and n items. `items` must be sorted ascending. A NaN
|
|
8
|
+
* value compares false with everything and gives 0, as
|
|
9
|
+
* {@link bisectRightNumbers} gives `low`; handle it before or after calling.
|
|
10
|
+
*
|
|
11
|
+
* @param out One index per value; its element type must hold `items.length` (an
|
|
12
|
+
* `Int32Array` holds up to 2³¹ − 1).
|
|
13
|
+
* @param items Numbers sorted ascending; a typed array reads without boxing.
|
|
14
|
+
* @param values The numbers to find insertion points for.
|
|
15
|
+
* @returns `out`.
|
|
16
|
+
* @throws {RangeError} When `out` and `values` differ in length.
|
|
17
|
+
* @see {@link bisectRightNumbers} for one value, or a window of `items`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bisectRightNumbersArray<T extends Int32Array | Uint32Array | Float64Array>(out: T, items: ArrayLike<number>, values: ArrayLike<number>): T;
|
|
20
|
+
//# sourceMappingURL=bisect-right-numbers-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bisect-right-numbers-array.d.ts","sourceRoot":"","sources":["../../src/ordered/bisect-right-numbers-array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACtC,CAAC,SAAS,UAAU,GAAG,WAAW,GAAG,YAAY,EAChD,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAwBhE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link bisectRightNumbers} of every value: `out[i]` is how many elements of
|
|
3
|
+
* `items` are `≤ values[i]`, the index after the last of them. The searches run
|
|
4
|
+
* inside one loop, so no number crosses a call per value and nothing is
|
|
5
|
+
* allocated, wherever the call is made from.
|
|
6
|
+
*
|
|
7
|
+
* O(m log n) for m values and n items. `items` must be sorted ascending. A NaN
|
|
8
|
+
* value compares false with everything and gives 0, as
|
|
9
|
+
* {@link bisectRightNumbers} gives `low`; handle it before or after calling.
|
|
10
|
+
*
|
|
11
|
+
* @param out One index per value; its element type must hold `items.length` (an
|
|
12
|
+
* `Int32Array` holds up to 2³¹ − 1).
|
|
13
|
+
* @param items Numbers sorted ascending; a typed array reads without boxing.
|
|
14
|
+
* @param values The numbers to find insertion points for.
|
|
15
|
+
* @returns `out`.
|
|
16
|
+
* @throws {RangeError} When `out` and `values` differ in length.
|
|
17
|
+
* @see {@link bisectRightNumbers} for one value, or a window of `items`.
|
|
18
|
+
*/
|
|
19
|
+
export function bisectRightNumbersArray(out, items, values) {
|
|
20
|
+
if (out.length !== values.length) {
|
|
21
|
+
throw new RangeError(`bisectRightNumbersArray: the output has ${out.length} elements and the values ${values.length}; they must agree.`);
|
|
22
|
+
}
|
|
23
|
+
const length = values.length;
|
|
24
|
+
const count = items.length;
|
|
25
|
+
for (let index = 0; index < length; index++) {
|
|
26
|
+
const value = values[index];
|
|
27
|
+
let start = 0;
|
|
28
|
+
let end = count;
|
|
29
|
+
while (start < end) {
|
|
30
|
+
const middle = start + Math.floor((end - start) / 2);
|
|
31
|
+
if (items[middle] <= value) {
|
|
32
|
+
start = middle + 1;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
end = middle;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
out[index] = start;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=bisect-right-numbers-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bisect-right-numbers-array.js","sourceRoot":"","sources":["../../src/ordered/bisect-right-numbers-array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,uBAAuB,CAErC,GAAM,EAAE,KAAwB,EAAE,MAAyB;IAC5D,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,MAAM,IAAI,UAAU,CACnB,2CAA2C,GAAG,CAAC,MAAM,4BAA4B,MAAM,CAAC,MAAM,oBAAoB,CAClH,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC3B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAE,CAAC;QAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,OAAO,KAAK,GAAG,GAAG,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACrD,IAAI,KAAK,CAAC,MAAM,CAAE,IAAI,KAAK,EAAE,CAAC;gBAC7B,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACP,GAAG,GAAG,MAAM,CAAC;YACd,CAAC;QACF,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the index after the last element of a sorted numeric array that is `≤
|
|
3
|
+
* value`, which is also how many elements are `≤ value`. It is
|
|
4
|
+
* {@link bisectRight} for numbers, with no comparator call per probe and no
|
|
5
|
+
* closure, so it allocates nothing.
|
|
6
|
+
*
|
|
7
|
+
* O(log n). `items` must be sorted ascending within `[low, high)`. A NaN
|
|
8
|
+
* `value` compares false with everything and returns `low`; handle it before
|
|
9
|
+
* calling.
|
|
10
|
+
*
|
|
11
|
+
* @param items Numbers sorted ascending; a typed array reads without boxing.
|
|
12
|
+
* @param value The number to find an insertion point for.
|
|
13
|
+
* @param low First index of the searched window.
|
|
14
|
+
* @param high End (exclusive) of the searched window.
|
|
15
|
+
* @returns The rightmost valid insertion index, in `[low, high]`.
|
|
16
|
+
* @see {@link bisectRight} for any item type.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bisectRightNumbers(items: ArrayLike<number>, value: number, low?: number, high?: number): number;
|
|
19
|
+
//# sourceMappingURL=bisect-right-numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bisect-right-numbers.d.ts","sourceRoot":"","sources":["../../src/ordered/bisect-right-numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,EACxB,KAAK,EAAE,MAAM,EACb,GAAG,SAAI,EACP,IAAI,SAAe,GACjB,MAAM,CAaR"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the index after the last element of a sorted numeric array that is `≤
|
|
3
|
+
* value`, which is also how many elements are `≤ value`. It is
|
|
4
|
+
* {@link bisectRight} for numbers, with no comparator call per probe and no
|
|
5
|
+
* closure, so it allocates nothing.
|
|
6
|
+
*
|
|
7
|
+
* O(log n). `items` must be sorted ascending within `[low, high)`. A NaN
|
|
8
|
+
* `value` compares false with everything and returns `low`; handle it before
|
|
9
|
+
* calling.
|
|
10
|
+
*
|
|
11
|
+
* @param items Numbers sorted ascending; a typed array reads without boxing.
|
|
12
|
+
* @param value The number to find an insertion point for.
|
|
13
|
+
* @param low First index of the searched window.
|
|
14
|
+
* @param high End (exclusive) of the searched window.
|
|
15
|
+
* @returns The rightmost valid insertion index, in `[low, high]`.
|
|
16
|
+
* @see {@link bisectRight} for any item type.
|
|
17
|
+
*/
|
|
18
|
+
export function bisectRightNumbers(items, value, low = 0, high = items.length) {
|
|
19
|
+
let start = low;
|
|
20
|
+
let end = high;
|
|
21
|
+
while (start < end) {
|
|
22
|
+
const middle = start + Math.floor((end - start) / 2);
|
|
23
|
+
if (items[middle] <= value) {
|
|
24
|
+
start = middle + 1;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
end = middle;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return start;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=bisect-right-numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bisect-right-numbers.js","sourceRoot":"","sources":["../../src/ordered/bisect-right-numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAwB,EACxB,KAAa,EACb,GAAG,GAAG,CAAC,EACP,IAAI,GAAG,KAAK,CAAC,MAAM;IAEnB,IAAI,KAAK,GAAG,GAAG,CAAC;IAChB,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,OAAO,KAAK,GAAG,GAAG,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,IAAI,KAAK,CAAC,MAAM,CAAE,IAAI,KAAK,EAAE,CAAC;YAC7B,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACP,GAAG,GAAG,MAAM,CAAC;QACd,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1 +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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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;KAC7D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ordered digits fractional keys are written in.
|
|
3
|
+
*
|
|
4
|
+
* Digits are ASCII graphic characters (`!` to `~`) in strictly increasing
|
|
5
|
+
* code-unit order, so a key's order is the same under JavaScript's `<`, UTF-8
|
|
6
|
+
* or Latin-1 byte order and a database's binary collation (`COLLATE "C"`,
|
|
7
|
+
* `BINARY`). A case-insensitive collation sorts base 62 differently: give such
|
|
8
|
+
* a store a single-case alphabet (`"0123456789abcdefghijklmnopqrstuvwxyz"`).
|
|
9
|
+
*
|
|
10
|
+
* The lower half of the digits (`⌊base / 2⌋` of them) are the heads of negative
|
|
11
|
+
* integer parts, the upper half those of non-negative ones; a larger alphabet
|
|
12
|
+
* gives shorter keys and more integer heads.
|
|
13
|
+
*/
|
|
14
|
+
export declare class FractionalKeyAlphabet {
|
|
15
|
+
/** The digits, smallest first. */
|
|
16
|
+
readonly digits: string;
|
|
17
|
+
/** How many digits there are, at least 2 and at most 94. */
|
|
18
|
+
readonly base: number;
|
|
19
|
+
private readonly values;
|
|
20
|
+
/**
|
|
21
|
+
* @param digits At least two ASCII graphic characters in strictly increasing
|
|
22
|
+
* code-unit order.
|
|
23
|
+
* @throws {RangeError} If `digits` is shorter than two, holds a character
|
|
24
|
+
* outside `!`–`~`, or is not strictly increasing.
|
|
25
|
+
*/
|
|
26
|
+
constructor(digits: string);
|
|
27
|
+
/**
|
|
28
|
+
* The value of the digit written as code unit `code`.
|
|
29
|
+
*
|
|
30
|
+
* Complexity: `O(1)`.
|
|
31
|
+
*
|
|
32
|
+
* @returns From `0` to `base - 1`, or `-1` if `code` is not a digit.
|
|
33
|
+
*/
|
|
34
|
+
digitValue(code: number): number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The default alphabet: `0`–`9`, `A`–`Z`, `a`–`z`, in byte order. Keys start at
|
|
38
|
+
* `"V0"` (the integer zero).
|
|
39
|
+
*/
|
|
40
|
+
export declare const BASE62_FRACTIONAL_KEY_ALPHABET: FractionalKeyAlphabet;
|
|
41
|
+
//# sourceMappingURL=fractional-key-alphabet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fractional-key-alphabet.d.ts","sourceRoot":"","sources":["../../src/ordered/fractional-key-alphabet.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IACjC,kCAAkC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IAEnC;;;;;OAKG;IACH,YAAY,MAAM,EAAE,MAAM,EA4BzB;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/B;CACD;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,qBAG3C,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isAsciiGraphic } from "@ac-kit/core";
|
|
2
|
+
const ASCII_CODES_ = 0x80;
|
|
3
|
+
/**
|
|
4
|
+
* The ordered digits fractional keys are written in.
|
|
5
|
+
*
|
|
6
|
+
* Digits are ASCII graphic characters (`!` to `~`) in strictly increasing
|
|
7
|
+
* code-unit order, so a key's order is the same under JavaScript's `<`, UTF-8
|
|
8
|
+
* or Latin-1 byte order and a database's binary collation (`COLLATE "C"`,
|
|
9
|
+
* `BINARY`). A case-insensitive collation sorts base 62 differently: give such
|
|
10
|
+
* a store a single-case alphabet (`"0123456789abcdefghijklmnopqrstuvwxyz"`).
|
|
11
|
+
*
|
|
12
|
+
* The lower half of the digits (`⌊base / 2⌋` of them) are the heads of negative
|
|
13
|
+
* integer parts, the upper half those of non-negative ones; a larger alphabet
|
|
14
|
+
* gives shorter keys and more integer heads.
|
|
15
|
+
*/
|
|
16
|
+
export class FractionalKeyAlphabet {
|
|
17
|
+
/** The digits, smallest first. */
|
|
18
|
+
digits;
|
|
19
|
+
/** How many digits there are, at least 2 and at most 94. */
|
|
20
|
+
base;
|
|
21
|
+
values;
|
|
22
|
+
/**
|
|
23
|
+
* @param digits At least two ASCII graphic characters in strictly increasing
|
|
24
|
+
* code-unit order.
|
|
25
|
+
* @throws {RangeError} If `digits` is shorter than two, holds a character
|
|
26
|
+
* outside `!`–`~`, or is not strictly increasing.
|
|
27
|
+
*/
|
|
28
|
+
constructor(digits) {
|
|
29
|
+
if (digits.length < 2) {
|
|
30
|
+
throw new RangeError(`A fractional key alphabet needs at least 2 digits, got ${digits.length}`);
|
|
31
|
+
}
|
|
32
|
+
const values = new Int8Array(ASCII_CODES_).fill(-1);
|
|
33
|
+
let previous = -1;
|
|
34
|
+
for (let index = 0; index < digits.length; index++) {
|
|
35
|
+
const code = digits.charCodeAt(index);
|
|
36
|
+
if (!isAsciiGraphic(code)) {
|
|
37
|
+
throw new RangeError(`Fractional key digit ${index} must be an ASCII graphic character, got U+${code.toString(16).toUpperCase().padStart(4, "0")}`);
|
|
38
|
+
}
|
|
39
|
+
if (code <= previous) {
|
|
40
|
+
throw new RangeError(`Fractional key digits must be in strictly increasing code-unit order, digit ${index} is not`);
|
|
41
|
+
}
|
|
42
|
+
values[code] = index;
|
|
43
|
+
previous = code;
|
|
44
|
+
}
|
|
45
|
+
this.digits = digits;
|
|
46
|
+
this.base = digits.length;
|
|
47
|
+
this.values = values;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The value of the digit written as code unit `code`.
|
|
51
|
+
*
|
|
52
|
+
* Complexity: `O(1)`.
|
|
53
|
+
*
|
|
54
|
+
* @returns From `0` to `base - 1`, or `-1` if `code` is not a digit.
|
|
55
|
+
*/
|
|
56
|
+
digitValue(code) {
|
|
57
|
+
return Number.isInteger(code) && code >= 0 && code < ASCII_CODES_
|
|
58
|
+
? this.values[code]
|
|
59
|
+
: -1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The default alphabet: `0`–`9`, `A`–`Z`, `a`–`z`, in byte order. Keys start at
|
|
64
|
+
* `"V0"` (the integer zero).
|
|
65
|
+
*/
|
|
66
|
+
export const BASE62_FRACTIONAL_KEY_ALPHABET = new FractionalKeyAlphabet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
|
67
|
+
//# sourceMappingURL=fractional-key-alphabet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fractional-key-alphabet.js","sourceRoot":"","sources":["../../src/ordered/fractional-key-alphabet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IACjC,kCAAkC;IACzB,MAAM,CAAS;IAExB,4DAA4D;IACnD,IAAI,CAAS;IAEL,MAAM,CAAY;IAEnC;;;;;OAKG;IACH,YAAY,MAAc;QACzB,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,UAAU,CACnB,0DAA0D,MAAM,CAAC,MAAM,EAAE,CACzE,CAAC;QACH,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC;QAElB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAEtC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,UAAU,CACnB,wBAAwB,KAAK,8CAA8C,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAC7H,CAAC;YACH,CAAC;YACD,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;gBACtB,MAAM,IAAI,UAAU,CACnB,+EAA+E,KAAK,SAAS,CAC7F,CAAC;YACH,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YACrB,QAAQ,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAY;QACtB,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,YAAY;YAChE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE;YACpB,CAAC,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAC1C,IAAI,qBAAqB,CACxB,gEAAgE,CAChE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown for a string that is not a fractional key under the alphabet in
|
|
3
|
+
* use.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FractionalKeyError extends SyntaxError {
|
|
6
|
+
/** The rejected string. */
|
|
7
|
+
readonly key: string;
|
|
8
|
+
/**
|
|
9
|
+
* The code-unit offset the check gave up at: the offending digit, or the
|
|
10
|
+
* key's length when the key stops too early.
|
|
11
|
+
*/
|
|
12
|
+
readonly index: number;
|
|
13
|
+
constructor(key: string, index: number, reason: string);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=fractional-key-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fractional-key-error.d.ts","sourceRoot":"","sources":["../../src/ordered/fractional-key-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;IAClD,2BAA2B;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,YAAY,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAOrD;CACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown for a string that is not a fractional key under the alphabet in
|
|
3
|
+
* use.
|
|
4
|
+
*/
|
|
5
|
+
export class FractionalKeyError extends SyntaxError {
|
|
6
|
+
/** The rejected string. */
|
|
7
|
+
key;
|
|
8
|
+
/**
|
|
9
|
+
* The code-unit offset the check gave up at: the offending digit, or the
|
|
10
|
+
* key's length when the key stops too early.
|
|
11
|
+
*/
|
|
12
|
+
index;
|
|
13
|
+
constructor(key, index, reason) {
|
|
14
|
+
super(`Invalid fractional key ${JSON.stringify(key)} at ${index}: ${reason}`);
|
|
15
|
+
this.name = "FractionalKeyError";
|
|
16
|
+
this.key = key;
|
|
17
|
+
this.index = index;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=fractional-key-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fractional-key-error.js","sourceRoot":"","sources":["../../src/ordered/fractional-key-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAClD,2BAA2B;IAClB,GAAG,CAAS;IAErB;;;OAGG;IACM,KAAK,CAAS;IAEvB,YAAY,GAAW,EAAE,KAAa,EAAE,MAAc;QACrD,KAAK,CACJ,0BAA0B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,MAAM,EAAE,CACtE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;CACD"}
|