@procedures/collections 0.12.1 → 0.12.2

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/index.js CHANGED
@@ -68,6 +68,8 @@ export * from "./interfaces/set.js";
68
68
  export * from "./storage/index.js";
69
69
  // The overlay: a logical document through a stack of layers, and the stacks from rules
70
70
  export * from "./overlay/index.js";
71
+ // The order of a list as data: a rank between two neighbors, and the index of a drop
72
+ export * from "./order/index.js";
71
73
  // ============================================================================
72
74
  // Implementations
73
75
  // ============================================================================
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AAEpC,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,cAAc,oBAAoB,CAAC;AAEnC,uFAAuF;AACvF,cAAc,oBAAoB,CAAC;AAcnC,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,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,EACT,MAAM,EACN,GAAG,EACH,SAAS,EACT,KAAK,EACL,MAAM,EACN,SAAS,EACT,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,mBAAmB,EACnB,GAAG,EACH,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,GAAG,EACH,GAAG,EACH,GAAG,EACH,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,IAAI,SAAS,EAClB,IAAI,GACL,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,OAAO,EACP,MAAM,IAAI,aAAa,EACvB,OAAO,IAAI,cAAc,EACzB,KAAK,IAAI,YAAY,EACrB,KAAK,IAAI,YAAY,EACrB,UAAU,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,aAAa,EACb,eAAe,EACf,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,SAAS,EACT,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,KAAK,EACL,IAAI,EACJ,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,mBAAmB;AACnB,OAAO,EACL,SAAS,EACT,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,GACR,MAAM,sBAAsB,CAAC;AAE9B,UAAU;AACV,OAAO,EACL,IAAI,EACJ,IAAI,EAEJ,EAAE,EACF,GAAG,EAEH,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,SAAS,EACT,MAAM,GACP,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The order of a list as data (Graph's split, wave 2, W1). Each item keeps a string key, and the list
3
+ * sorts by it. An item that moves between two others gets a key between theirs, so a move writes one
4
+ * item and no other.
5
+ */
6
+ export { KEY_DIGITS, keyBetween, keysBetween, keysForDrop, compareKeys, isValidKey, dropIndex, type KeyCheckOptions, type KeyedItem, type Point } from "./rank.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/order/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The order of a list as data (Graph's split, wave 2, W1). Each item keeps a string key, and the list
3
+ * sorts by it. An item that moves between two others gets a key between theirs, so a move writes one
4
+ * item and no other.
5
+ */
6
+ export { KEY_DIGITS, keyBetween, keysBetween, keysForDrop, compareKeys, isValidKey, dropIndex } from "./rank.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/order/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAoD,MAAM,WAAW,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The keys of an ordered list (Graph's split, wave 2, W1): fractional indexing with base-62 keys. A
3
+ * key is a string. Each item of the list keeps one, and the list sorts by it. An item that moves
4
+ * between two others gets a key between theirs, so a move writes one item and no other.
5
+ *
6
+ * - A key has an integer part and a fraction part. The first character of the integer part gives its
7
+ * length. An insertion at an end changes the integer part, so the keys stay short. An insertion
8
+ * between two keys uses the fraction part, which can grow without a limit: the keys never run out,
9
+ * and the list needs no rebalance.
10
+ * - Compare two keys by the code units of the strings (`a < b`), never with `localeCompare`.
11
+ * - Two writers that move items into the same gap at the same time can get the same key. Sort by the
12
+ * key, then by the id of the item, so each reader sees one order.
13
+ *
14
+ * The algorithm is the one of the `fractional-indexing` package of Rocicorp (CC0), after the article
15
+ * "Implementing Fractional Indexing" of David Greenspan.
16
+ */
17
+ /** The digits of a key, in ascending order of their code units. */
18
+ export declare const KEY_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
19
+ /**
20
+ * This function gives a key strictly between two keys. Without `prev`, the key comes before `next`.
21
+ * Without `next`, it comes after `prev`. Without both, it gives the first key of a list ("a0").
22
+ *
23
+ * @throws RangeError when a key is not valid, or when `prev` is not before `next`
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * keyBetween(undefined, undefined); // "a0"
28
+ * keyBetween("a0", undefined); // "a1", after a0
29
+ * keyBetween("a0", "a1"); // "a0V"
30
+ * ```
31
+ */
32
+ export declare function keyBetween(prev: string | null | undefined, next: string | null | undefined): string;
33
+ /**
34
+ * This function gives `count` keys in ascending order, strictly between two keys, for example to put
35
+ * several items at one place, or to give keys to the items of a list for the first time.
36
+ *
37
+ * @throws RangeError as `keyBetween`, or when `count` is not an integer of 0 or more
38
+ */
39
+ export declare function keysBetween(prev: string | null | undefined, next: string | null | undefined, count: number): string[];
40
+ /** The options of `isValidKey`. */
41
+ export interface KeyCheckOptions {
42
+ /** The longest key that the check accepts. The default is 1024 characters. */
43
+ readonly maxLength?: number;
44
+ }
45
+ /**
46
+ * This function tells if a value is a valid key, for example a key that a client writes. A key that
47
+ * is longer than `maxLength` is not valid.
48
+ */
49
+ export declare function isValidKey(key: unknown, options?: KeyCheckOptions): key is string;
50
+ /** An item of an ordered list: its id and its key. */
51
+ export interface KeyedItem {
52
+ readonly id: string;
53
+ readonly key: string;
54
+ }
55
+ /**
56
+ * This function gives the writes of a move: the new key of the item that moves, and new keys for the
57
+ * neighbors that need them. Give the other items of the list in order (by key, then by id), without
58
+ * the item that moves, and the index of the drop from 0 to their number (`dropIndex`).
59
+ *
60
+ * Two writers can give two items one key. A drop between two such items has no key between them, so
61
+ * the helper first gives new keys to the items after the drop that have the key of the item before
62
+ * it. Each write is `{ id, key }`. The writes of the neighbors come first, and the write of the item
63
+ * that moves comes last.
64
+ *
65
+ * @throws RangeError when the index is outside the list, when the list holds the item that moves, or
66
+ * when a key is not valid
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const index = dropIndex(pointer, others.map(centerOf));
71
+ * for (const { id, key } of keysForDrop(others, index, dragged.id)) await save(id, { rank: key });
72
+ * ```
73
+ */
74
+ export declare function keysForDrop(items: readonly KeyedItem[], index: number, movingId: string): Array<{
75
+ id: string;
76
+ key: string;
77
+ }>;
78
+ /** The order of two keys: the code units of the strings, as the keys need (never `localeCompare`). */
79
+ export declare function compareKeys(a: string, b: string): number;
80
+ /** A point, for example the center of an item on the screen. */
81
+ export interface Point {
82
+ readonly x: number;
83
+ readonly y: number;
84
+ }
85
+ /**
86
+ * This function gives the index at which a point goes among the items of a list on the screen, in
87
+ * reading order: the rows from top to bottom, and each row from left to right. It is the index of the
88
+ * first item whose center comes after the point, from 0 to the number of items. A center within
89
+ * `rowTolerance` of the point on the vertical axis is in the row of the point.
90
+ *
91
+ * Give the centers in reading order, the same order as the keys, and without the item that moves.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const index = dropIndex(pointer, others.map(centerOf));
96
+ * const key = keyBetween(keys[index - 1], keys[index]);
97
+ * ```
98
+ */
99
+ export declare function dropIndex(point: Point, centers: readonly Point[], rowTolerance?: number): number;
100
+ //# sourceMappingURL=rank.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rank.d.ts","sourceRoot":"","sources":["../../src/order/rank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mEAAmE;AACnE,eAAO,MAAM,UAAU,mEAAmE,CAAC;AAuF3F;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,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 2, W1): fractional indexing with base-62 keys. A
3
+ * key is a string. Each item of the list keeps one, and the list sorts by it. An item that moves
4
+ * between two others gets a key between theirs, so a move writes one item and no other.
5
+ *
6
+ * - A key has an integer part and a fraction part. The first character of the integer part gives its
7
+ * length. An insertion at an end changes the integer part, so the keys stay short. An insertion
8
+ * between two keys uses the fraction part, which can grow without a limit: the keys never run out,
9
+ * and the list needs no rebalance.
10
+ * - Compare two keys by the code units of the strings (`a < b`), never with `localeCompare`.
11
+ * - Two writers that move items into the same gap at the same time can get the same key. Sort by the
12
+ * key, then by the id of the item, so each reader sees one order.
13
+ *
14
+ * The algorithm is the one of the `fractional-indexing` package of Rocicorp (CC0), after the article
15
+ * "Implementing Fractional Indexing" of David Greenspan.
16
+ */
17
+ /** The digits of a key, in ascending order of their code units. */
18
+ export const KEY_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
19
+ const ZERO = KEY_DIGITS[0];
20
+ const LAST = KEY_DIGITS[KEY_DIGITS.length - 1];
21
+ /** The smallest integer part. No key comes before it. */
22
+ const SMALLEST_INTEGER = `A${ZERO.repeat(26)}`;
23
+ function invalid(message) {
24
+ return new RangeError(message);
25
+ }
26
+ /** The length of the integer part that starts with a head character: a to z give 2 to 27, Z to A give 2 to 27. */
27
+ function integerLength(head) {
28
+ if (head >= "a" && head <= "z")
29
+ return head.charCodeAt(0) - "a".charCodeAt(0) + 2;
30
+ if (head >= "A" && head <= "Z")
31
+ return "Z".charCodeAt(0) - head.charCodeAt(0) + 2;
32
+ throw invalid(`A key cannot start with "${head}"`);
33
+ }
34
+ function integerPart(key) {
35
+ const length = integerLength(key[0] ?? "");
36
+ if (length > key.length)
37
+ throw invalid(`The key "${key}" is too short for its integer part`);
38
+ return key.slice(0, length);
39
+ }
40
+ function validateKey(key) {
41
+ if (typeof key !== "string" || key === "")
42
+ throw invalid("A key is a string that is not empty");
43
+ for (const c of key)
44
+ if (!KEY_DIGITS.includes(c))
45
+ throw invalid(`The key "${key}" has a character that is no digit of a key`);
46
+ if (key === SMALLEST_INTEGER)
47
+ throw invalid(`The key "${key}" is reserved`);
48
+ const fraction = key.slice(integerPart(key).length);
49
+ if (fraction.endsWith(ZERO))
50
+ throw invalid(`The fraction part of the key "${key}" ends with ${ZERO}`);
51
+ }
52
+ /** A fraction strictly between two fractions. `b` null is the end. Neither one ends with the zero digit. */
53
+ function midpoint(a, b) {
54
+ if (b !== null) {
55
+ let n = 0;
56
+ while ((a[n] ?? ZERO) === b[n])
57
+ n++;
58
+ if (n > 0)
59
+ return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
60
+ }
61
+ const digitA = a ? KEY_DIGITS.indexOf(a[0]) : 0;
62
+ const digitB = b !== null ? KEY_DIGITS.indexOf(b[0]) : KEY_DIGITS.length;
63
+ if (digitB - digitA > 1)
64
+ return KEY_DIGITS[Math.round((digitA + digitB) / 2)];
65
+ // The first digits are next to each other
66
+ if (b !== null && b.length > 1)
67
+ return b.slice(0, 1);
68
+ return KEY_DIGITS[digitA] + midpoint(a.slice(1), null);
69
+ }
70
+ function incrementInteger(x) {
71
+ const [head, ...digits] = x.split("");
72
+ let carry = true;
73
+ for (let i = digits.length - 1; carry && i >= 0; i--) {
74
+ const d = KEY_DIGITS.indexOf(digits[i]) + 1;
75
+ if (d === KEY_DIGITS.length)
76
+ digits[i] = ZERO;
77
+ else {
78
+ digits[i] = KEY_DIGITS[d];
79
+ carry = false;
80
+ }
81
+ }
82
+ if (!carry)
83
+ return head + digits.join("");
84
+ if (head === "Z")
85
+ return `a${ZERO}`;
86
+ if (head === "z")
87
+ return null;
88
+ const next = String.fromCharCode(head.charCodeAt(0) + 1);
89
+ if (next > "a")
90
+ digits.push(ZERO);
91
+ else
92
+ digits.pop();
93
+ return next + digits.join("");
94
+ }
95
+ function decrementInteger(x) {
96
+ const [head, ...digits] = x.split("");
97
+ let borrow = true;
98
+ for (let i = digits.length - 1; borrow && i >= 0; i--) {
99
+ const d = KEY_DIGITS.indexOf(digits[i]) - 1;
100
+ if (d === -1)
101
+ digits[i] = LAST;
102
+ else {
103
+ digits[i] = KEY_DIGITS[d];
104
+ borrow = false;
105
+ }
106
+ }
107
+ if (!borrow)
108
+ return head + digits.join("");
109
+ if (head === "a")
110
+ return `Z${LAST}`;
111
+ if (head === "A")
112
+ return null;
113
+ const next = String.fromCharCode(head.charCodeAt(0) - 1);
114
+ if (next < "Z")
115
+ digits.push(LAST);
116
+ else
117
+ digits.pop();
118
+ return next + digits.join("");
119
+ }
120
+ /**
121
+ * This function gives a key strictly between two keys. Without `prev`, the key comes before `next`.
122
+ * Without `next`, it comes after `prev`. Without both, it gives the first key of a list ("a0").
123
+ *
124
+ * @throws RangeError when a key is not valid, or when `prev` is not before `next`
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * keyBetween(undefined, undefined); // "a0"
129
+ * keyBetween("a0", undefined); // "a1", after a0
130
+ * keyBetween("a0", "a1"); // "a0V"
131
+ * ```
132
+ */
133
+ export function keyBetween(prev, next) {
134
+ const a = prev ?? null;
135
+ const b = next ?? null;
136
+ if (a !== null)
137
+ validateKey(a);
138
+ if (b !== null)
139
+ validateKey(b);
140
+ if (a !== null && b !== null && a >= b)
141
+ throw invalid(`The key "${a}" is not before the key "${b}"`);
142
+ if (a === null) {
143
+ if (b === null)
144
+ return `a${ZERO}`;
145
+ const ib = integerPart(b);
146
+ const fb = b.slice(ib.length);
147
+ if (ib === SMALLEST_INTEGER)
148
+ return ib + midpoint("", fb);
149
+ if (ib < b)
150
+ return ib;
151
+ const decremented = decrementInteger(ib);
152
+ if (decremented === null)
153
+ throw invalid("No key comes before this one");
154
+ return decremented;
155
+ }
156
+ const ia = integerPart(a);
157
+ const fa = a.slice(ia.length);
158
+ if (b === null) {
159
+ const incremented = incrementInteger(ia);
160
+ return incremented === null ? ia + midpoint(fa, null) : incremented;
161
+ }
162
+ const ib = integerPart(b);
163
+ const fb = b.slice(ib.length);
164
+ if (ia === ib)
165
+ return ia + midpoint(fa, fb);
166
+ const incremented = incrementInteger(ia);
167
+ if (incremented === null)
168
+ throw invalid("No key comes after this one");
169
+ if (incremented < b)
170
+ return incremented;
171
+ return ia + midpoint(fa, null);
172
+ }
173
+ /**
174
+ * This function gives `count` keys in ascending order, strictly between two keys, for example to put
175
+ * several items at one place, or to give keys to the items of a list for the first time.
176
+ *
177
+ * @throws RangeError as `keyBetween`, or when `count` is not an integer of 0 or more
178
+ */
179
+ export function keysBetween(prev, next, count) {
180
+ if (!Number.isInteger(count) || count < 0)
181
+ throw invalid(`A count of keys is an integer of 0 or more, not ${count}`);
182
+ const a = prev ?? null;
183
+ const b = next ?? null;
184
+ if (count === 0)
185
+ return [];
186
+ if (count === 1)
187
+ return [keyBetween(a, b)];
188
+ if (b === null) {
189
+ const keys = [keyBetween(a, null)];
190
+ for (let i = 1; i < count; i++)
191
+ keys.push(keyBetween(keys[i - 1], null));
192
+ return keys;
193
+ }
194
+ if (a === null) {
195
+ const keys = [keyBetween(null, b)];
196
+ for (let i = 1; i < count; i++)
197
+ keys.push(keyBetween(null, keys[i - 1]));
198
+ return keys.reverse();
199
+ }
200
+ const half = Math.floor(count / 2);
201
+ const middle = keyBetween(a, b);
202
+ return [...keysBetween(a, middle, half), middle, ...keysBetween(middle, b, count - half - 1)];
203
+ }
204
+ /**
205
+ * This function tells if a value is a valid key, for example a key that a client writes. A key that
206
+ * is longer than `maxLength` is not valid.
207
+ */
208
+ export function isValidKey(key, options = {}) {
209
+ if (typeof key !== "string" || key.length > (options.maxLength ?? 1024))
210
+ return false;
211
+ try {
212
+ validateKey(key);
213
+ return true;
214
+ }
215
+ catch {
216
+ return false;
217
+ }
218
+ }
219
+ /**
220
+ * This function gives the writes of a move: the new key of the item that moves, and new keys for the
221
+ * neighbors that need them. Give the other items of the list in order (by key, then by id), without
222
+ * the item that moves, and the index of the drop from 0 to their number (`dropIndex`).
223
+ *
224
+ * Two writers can give two items one key. A drop between two such items has no key between them, so
225
+ * the helper first gives new keys to the items after the drop that have the key of the item before
226
+ * it. Each write is `{ id, key }`. The writes of the neighbors come first, and the write of the item
227
+ * that moves comes last.
228
+ *
229
+ * @throws RangeError when the index is outside the list, when the list holds the item that moves, or
230
+ * when a key is not valid
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * const index = dropIndex(pointer, others.map(centerOf));
235
+ * for (const { id, key } of keysForDrop(others, index, dragged.id)) await save(id, { rank: key });
236
+ * ```
237
+ */
238
+ export function keysForDrop(items, index, movingId) {
239
+ if (!Number.isInteger(index) || index < 0 || index > items.length)
240
+ throw invalid(`The index ${index} is outside the list of ${items.length} items`);
241
+ if (items.some((item) => item.id === movingId))
242
+ throw invalid(`The list holds the item that moves (${movingId})`);
243
+ const prev = items[index - 1]?.key ?? null;
244
+ // The items from the index on that do not come after the item before the drop need new keys
245
+ let end = index;
246
+ while (end < items.length && prev !== null && items[end].key <= prev)
247
+ end++;
248
+ const writes = [];
249
+ if (end > index) {
250
+ const keys = keysBetween(prev, items[end]?.key ?? null, end - index);
251
+ for (let i = index; i < end; i++)
252
+ writes.push({ id: items[i].id, key: keys[i - index] });
253
+ }
254
+ const next = writes.length > 0 ? writes[0].key : (items[index]?.key ?? null);
255
+ writes.push({ id: movingId, key: keyBetween(prev, next) });
256
+ return writes;
257
+ }
258
+ /** The order of two keys: the code units of the strings, as the keys need (never `localeCompare`). */
259
+ export function compareKeys(a, b) {
260
+ return a < b ? -1 : a > b ? 1 : 0;
261
+ }
262
+ /**
263
+ * This function gives the index at which a point goes among the items of a list on the screen, in
264
+ * reading order: the rows from top to bottom, and each row from left to right. It is the index of the
265
+ * first item whose center comes after the point, from 0 to the number of items. A center within
266
+ * `rowTolerance` of the point on the vertical axis is in the row of the point.
267
+ *
268
+ * Give the centers in reading order, the same order as the keys, and without the item that moves.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const index = dropIndex(pointer, others.map(centerOf));
273
+ * const key = keyBetween(keys[index - 1], keys[index]);
274
+ * ```
275
+ */
276
+ export function dropIndex(point, centers, rowTolerance = 24) {
277
+ for (let i = 0; i < centers.length; i++) {
278
+ const c = centers[i];
279
+ if (point.y < c.y - rowTolerance)
280
+ return i;
281
+ if (Math.abs(point.y - c.y) <= rowTolerance && point.x < c.x)
282
+ return i;
283
+ }
284
+ return centers.length;
285
+ }
286
+ //# sourceMappingURL=rank.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rank.js","sourceRoot":"","sources":["../../src/order/rank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,UAAU,GAAG,gEAAgE,CAAC;AAE3F,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;AAC5B,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;AAChD,yDAAyD;AACzD,MAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AAE/C,SAAS,OAAO,CAAC,OAAe;IAC9B,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,kHAAkH;AAClH,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAClF,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAClF,MAAM,OAAO,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC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G,EAAE;IAClF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QACtB,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY;YAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@procedures/collections",
4
- "version": "0.12.1",
4
+ "version": "0.12.2",
5
5
  "description": "Collections for TypeScript: ArrayList, LinkedList, ArrayDeque, HashMap, LinkedHashMap, TreeMap (red-black), PriorityQueue, LRU and TTL maps, async queues, channels and collectors, tested with fast-check.",
6
6
  "keywords": [
7
7
  "collections",
@@ -59,7 +59,7 @@
59
59
  "provenance": true
60
60
  },
61
61
  "dependencies": {
62
- "@procedures/client": "0.12.1"
62
+ "@procedures/client": "0.12.2"
63
63
  },
64
64
  "devDependencies": {
65
65
  "typescript": "^7.0.2",
package/src/index.ts CHANGED
@@ -75,6 +75,9 @@ export * from "./storage/index.js";
75
75
  // The overlay: a logical document through a stack of layers, and the stacks from rules
76
76
  export * from "./overlay/index.js";
77
77
 
78
+ // The order of a list as data: a rank between two neighbors, and the index of a drop
79
+ export * from "./order/index.js";
80
+
78
81
  // Export queue interfaces with disambiguation for PriorityQueue
79
82
  export type {
80
83
  ReadonlyQueue,
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The order of a list as data (Graph's split, wave 2, W1). Each item keeps a string key, and the list
3
+ * sorts by it. An item that moves between two others gets a key between theirs, so a move writes one
4
+ * item and no other.
5
+ */
6
+ export { KEY_DIGITS, keyBetween, keysBetween, keysForDrop, compareKeys, isValidKey, dropIndex, type KeyCheckOptions, type KeyedItem, type Point } from "./rank.js";