qstd 0.3.84 → 0.3.85
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/dist/shared/lexorank/domain.d.ts +71 -0
- package/dist/shared/lexorank/domain.d.ts.map +1 -0
- package/dist/shared/lexorank/fns.d.ts +25 -0
- package/dist/shared/lexorank/fns.d.ts.map +1 -0
- package/dist/shared/lexorank/index.d.ts +17 -0
- package/dist/shared/lexorank/index.d.ts.map +1 -0
- package/dist/shared/lexorank/literals.d.ts +20 -0
- package/dist/shared/lexorank/literals.d.ts.map +1 -0
- package/dist/shared/lexorank/types.d.ts +5 -0
- package/dist/shared/lexorank/types.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as _t from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a new sort key between two adjacent items.
|
|
4
|
+
*
|
|
5
|
+
* Given the order strings of the previous and next items, produces a
|
|
6
|
+
* string that sorts lexicographically between them. Pass empty strings
|
|
7
|
+
* for boundaries (insert at start or end).
|
|
8
|
+
*
|
|
9
|
+
* Algorithm uses lowercase a-z (char codes 96-123) as the alphabet:
|
|
10
|
+
* - 96 = boundary before 'a'
|
|
11
|
+
* - 123 = boundary after 'z'
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* createOrderStr("b", "d") // "c"
|
|
15
|
+
* createOrderStr("", "b") // "a" (or similar, insert at start)
|
|
16
|
+
* createOrderStr("n", "") // "t" (or similar, insert at end)
|
|
17
|
+
* createOrderStr("az", "b") // "an" (midpoint between "az" and "b")
|
|
18
|
+
*/
|
|
19
|
+
export declare const createOrderStr: (prev?: string, next?: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Generate evenly-spaced order keys for a list of a given size.
|
|
22
|
+
*
|
|
23
|
+
* Used for initial list creation and periodic rebalancing. Produces
|
|
24
|
+
* `num` strings that are roughly evenly distributed across the a-z
|
|
25
|
+
* alphabet space, minimizing future string growth.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* createRebalancedOrderList(3) // ["i", "r", "z"] (roughly evenly spaced)
|
|
29
|
+
* createRebalancedOrderList(5) // ["e", "j", "o", "t", "y"]
|
|
30
|
+
*/
|
|
31
|
+
export declare const createRebalancedOrderList: (num: number) => string[];
|
|
32
|
+
/**
|
|
33
|
+
* Check if the order strings in a list need rebalancing.
|
|
34
|
+
*
|
|
35
|
+
* Returns true when the longest order string exceeds half the list size.
|
|
36
|
+
* This indicates too many consecutive edge insertions have caused string
|
|
37
|
+
* growth. Rebalancing is rare in normal usage patterns.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* checkBalance([{ order: "b" }, { order: "n" }]) // false (1 < 1)
|
|
41
|
+
* checkBalance([{ order: "aaaaax" }, { order: "b" }]) // true (6 > 1)
|
|
42
|
+
*/
|
|
43
|
+
export declare const checkBalance: <T extends _t.Ordered>(xs: T[]) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Rebalance a list by recomputing evenly-spaced order keys for every item.
|
|
46
|
+
*
|
|
47
|
+
* Eliminates long order strings caused by repeated edge insertions.
|
|
48
|
+
* Returns new items with fresh `order` values. Does not mutate input.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const items = [
|
|
52
|
+
* { id: "a", order: "aaaaax" },
|
|
53
|
+
* { id: "b", order: "b" },
|
|
54
|
+
* { id: "c", order: "n" },
|
|
55
|
+
* ];
|
|
56
|
+
* rebalance(items);
|
|
57
|
+
* // [{ id: "a", order: "i" }, { id: "b", order: "r" }, { id: "c", order: "z" }]
|
|
58
|
+
*/
|
|
59
|
+
export declare const rebalance: <T extends _t.Ordered>(xs: T[]) => (T & {
|
|
60
|
+
order: string;
|
|
61
|
+
})[];
|
|
62
|
+
/**
|
|
63
|
+
* Sort items by their lexicographic order strings.
|
|
64
|
+
*
|
|
65
|
+
* Returns a new sorted array (immutable). Items without an order
|
|
66
|
+
* field sort to the beginning.
|
|
67
|
+
*/
|
|
68
|
+
export declare const sortByOrder: <T extends {
|
|
69
|
+
order?: string;
|
|
70
|
+
}>(xs: T[]) => T[];
|
|
71
|
+
//# sourceMappingURL=domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/domain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAI9B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,GAAI,aAAS,EAAE,aAAS,WA0ClD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,aAiCpD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,YAMzD,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE;;IAGtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,CAAC,EAAE,QACI,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip trailing 'a' characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* During order list generation, intermediate strings can end with runs
|
|
5
|
+
* of 'a's that add length without information. Stripping them produces
|
|
6
|
+
* shorter, cleaner keys that still sort correctly.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* stripTrailingAs("naaa") // "n"
|
|
10
|
+
* stripTrailingAs("abc") // "abc"
|
|
11
|
+
* stripTrailingAs("a") // ""
|
|
12
|
+
*/
|
|
13
|
+
export declare const stripTrailingAs: (str: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate a partial alphabet for evenly distributing keys.
|
|
16
|
+
*
|
|
17
|
+
* Uses a bit-packed lookup table to select well-distributed
|
|
18
|
+
* characters from the a-z range based on the desired count.
|
|
19
|
+
* For counts >= 13, the table mirrors to cover the full range.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* partialAlphabet(3) // ["d", "n", "x"] (roughly evenly spaced)
|
|
23
|
+
*/
|
|
24
|
+
export declare const partialAlphabet: (num: number) => string[];
|
|
25
|
+
//# sourceMappingURL=fns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fns.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/fns.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,WAI1C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,aAW1C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LexoRank Ordering
|
|
3
|
+
*
|
|
4
|
+
* Lexicographic string-based ordering for collection items.
|
|
5
|
+
* Enables O(1) reorder operations: moving an item between two others
|
|
6
|
+
* generates a new order string between their existing orders.
|
|
7
|
+
*
|
|
8
|
+
* Key functions:
|
|
9
|
+
* - `createOrderStr(prev, next)` - Generate key between two adjacent items
|
|
10
|
+
* - `createRebalancedOrderList(num)` - Generate evenly-spaced keys for a list
|
|
11
|
+
* - `checkBalance(xs)` - Detect when rebalancing is needed
|
|
12
|
+
* - `rebalance(xs)` - Recompute all orders
|
|
13
|
+
* - `sortByOrder(xs)` - Sort items by lexicographic order
|
|
14
|
+
*/
|
|
15
|
+
export type * from "./types";
|
|
16
|
+
export * from "./domain";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,mBAAmB,SAAS,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Char code for the lower bound sentinel (one below 'a') */
|
|
2
|
+
export declare const LOWER_BOUND = 96;
|
|
3
|
+
/** Char code for the upper bound sentinel (one above 'z') */
|
|
4
|
+
export declare const UPPER_BOUND = 123;
|
|
5
|
+
/** Char code for 'a' — first character in the usable alphabet */
|
|
6
|
+
export declare const CHAR_A = 97;
|
|
7
|
+
/** Char code for 'z' — last character in the usable alphabet */
|
|
8
|
+
export declare const CHAR_Z = 122;
|
|
9
|
+
/** Size of the a-z alphabet */
|
|
10
|
+
export declare const ALPHABET_SIZE = 26;
|
|
11
|
+
/**
|
|
12
|
+
* Bit-packed lookup table for selecting well-distributed characters
|
|
13
|
+
* from the a-z range when generating evenly-spaced order keys.
|
|
14
|
+
*
|
|
15
|
+
* Each entry encodes which of the 25 non-'a' characters to include
|
|
16
|
+
* when distributing `n` keys across the alphabet. For n >= 13, the
|
|
17
|
+
* table is mirrored using a 25-bit mask (2^25 - 1 = 33554431).
|
|
18
|
+
*/
|
|
19
|
+
export declare const DISTRIBUTION_TABLE: readonly [0, 4096, 65792, 528416, 1081872, 2167048, 2376776, 4756004, 4794660, 5411476, 9775442, 11097386, 11184810, 22369621];
|
|
20
|
+
//# sourceMappingURL=literals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literals.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/literals.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,6DAA6D;AAC7D,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,iEAAiE;AACjE,eAAO,MAAM,MAAM,KAAK,CAAC;AAEzB,gEAAgE;AAChE,eAAO,MAAM,MAAM,MAAM,CAAC;AAE1B,+BAA+B;AAC/B,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,gIAGrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;CACf"}
|