sorted-collections 1.0.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/LICENSE +21 -0
- package/README.md +258 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +431 -0
- package/dist/index.d.ts +431 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A standard JS/TS comparator: negative if `a` sorts before `b`, positive if
|
|
3
|
+
* after, zero if equal.
|
|
4
|
+
*/
|
|
5
|
+
type Comparator<T> = (a: T, b: T) => number;
|
|
6
|
+
interface SortedOptions<T> {
|
|
7
|
+
comparator?: Comparator<T>;
|
|
8
|
+
}
|
|
9
|
+
interface SortedOptionsRequired<T> {
|
|
10
|
+
comparator: Comparator<T>;
|
|
11
|
+
}
|
|
12
|
+
/** Types with a natural order (`<`/`>`) usable without an explicit comparator. */
|
|
13
|
+
type NaturallyOrderable = number | string;
|
|
14
|
+
/**
|
|
15
|
+
* Rest-tuple used in constructors so TypeScript enforces a comparator at
|
|
16
|
+
* compile time for any `T` that isn't naturally orderable, while keeping it
|
|
17
|
+
* optional for `number`/`string`.
|
|
18
|
+
*/
|
|
19
|
+
type ComparatorArg<T> = T extends NaturallyOrderable ? [options?: SortedOptions<T>] : [options: SortedOptionsRequired<T>];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A list that keeps its elements in sorted order as they're inserted.
|
|
23
|
+
*
|
|
24
|
+
* A thin public wrapper around the internal {@link BucketEngine} — see there
|
|
25
|
+
* for the actual "list of lists" (sqrt-decomposition) implementation and its
|
|
26
|
+
* complexity notes.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const scores = new SortedList<number>([42, 7, 99]);
|
|
31
|
+
* scores.add(15);
|
|
32
|
+
* [...scores]; // [7, 15, 42, 99]
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare class SortedList<T> implements Iterable<T> {
|
|
36
|
+
private readonly engine;
|
|
37
|
+
/**
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* new SortedList<number>(); // empty
|
|
41
|
+
* new SortedList<number>([3, 1, 2]); // [1, 2, 3]
|
|
42
|
+
* new SortedList<Person>([...], { comparator: (a, b) => a.age - b.age });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
constructor(iterable?: Iterable<T>, ...options: ComparatorArg<T>);
|
|
46
|
+
/** Safe to call from subclasses/clone: both `ComparatorArg<T>` branches accept `{ comparator }`. */
|
|
47
|
+
protected comparatorArg(): ComparatorArg<T>;
|
|
48
|
+
/**
|
|
49
|
+
* O(√n) amortized.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const scores = new SortedList<number>();
|
|
54
|
+
* scores.add(42);
|
|
55
|
+
* scores.add(7);
|
|
56
|
+
* [...scores]; // [7, 42]
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
add(value: T): void;
|
|
60
|
+
/**
|
|
61
|
+
* Bulk-inserts every value from `iterable`, one {@link add} at a time.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const scores = new SortedList<number>([3, 1]);
|
|
66
|
+
* scores.update([2, 5, 4]);
|
|
67
|
+
* [...scores]; // [1, 2, 3, 4, 5]
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
update(iterable: Iterable<T>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Removes the first occurrence of `value`. Returns `false` if it wasn't present.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const scores = new SortedList<number>([1, 2, 2, 3]);
|
|
77
|
+
* scores.remove(2); // true — removes one occurrence
|
|
78
|
+
* scores.remove(99); // false — not present
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
remove(value: T): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Like {@link remove}, but never throws (or returns anything) if `value` isn't present.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const scores = new SortedList<number>([1, 2, 3]);
|
|
88
|
+
* scores.discard(99); // no-op, no error
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
discard(value: T): void;
|
|
92
|
+
/**
|
|
93
|
+
* Removes and returns the element at `index` (default: the last element).
|
|
94
|
+
* Negative indices count from the end, same as {@link at}.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const scores = new SortedList<number>([10, 20, 30]);
|
|
99
|
+
* scores.pop(); // 30 — last element
|
|
100
|
+
* scores.pop(0); // 10 — first element
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
pop(index?: number): T;
|
|
104
|
+
/**
|
|
105
|
+
* O(√n): walks bucket lengths to find the element at `index` (negative indices count from the end).
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const scores = new SortedList<number>([10, 20, 30]);
|
|
110
|
+
* scores.at(0); // 10
|
|
111
|
+
* scores.at(-1); // 30 — same as Array.prototype.at
|
|
112
|
+
* scores.at(99); // undefined — out of range
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
at(index: number): T | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The index of the first occurrence of `value`, or `-1` if absent.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* new SortedList<number>([1, 2, 2, 3]).indexOf(2); // 1
|
|
122
|
+
* new SortedList<number>([1, 2, 3]).indexOf(99); // -1
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
indexOf(value: T): number;
|
|
126
|
+
/**
|
|
127
|
+
* O(log n): binary search for the bucket, then binary search within it.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const scores = new SortedList<number>([1, 2, 3]);
|
|
132
|
+
* scores.has(2); // true
|
|
133
|
+
* scores.has(99); // false
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
has(value: T): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* The leftmost index where `value` could be inserted while keeping the list sorted.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* new SortedList<number>([1, 2, 2, 2, 3]).bisectLeft(2); // 1
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
bisectLeft(value: T): number;
|
|
146
|
+
/**
|
|
147
|
+
* The rightmost index where `value` could be inserted while keeping the list sorted.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* new SortedList<number>([1, 2, 2, 2, 3]).bisectRight(2); // 4
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
bisectRight(value: T): number;
|
|
155
|
+
/**
|
|
156
|
+
* O(log n) to locate both bounds by value + O(k) to iterate the k results.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const scores = new SortedList<number>([1, 2, 3, 4, 5]);
|
|
161
|
+
* [...scores.irange(2, 4)]; // [2, 3, 4] — inclusive by default
|
|
162
|
+
* [...scores.irange(2, 4, { inclusive: [false, true] })]; // [3, 4]
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
irange(min?: T, max?: T, options?: {
|
|
166
|
+
inclusive?: [boolean, boolean];
|
|
167
|
+
}): IterableIterator<T>;
|
|
168
|
+
/**
|
|
169
|
+
* O(√n) to locate both positional bounds + O(k) to iterate the k results.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const scores = new SortedList<number>([10, 20, 30, 40, 50]);
|
|
174
|
+
* [...scores.islice(1, 4)]; // [20, 30, 40] — like Array.prototype.slice
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
islice(start?: number, end?: number): IterableIterator<T>;
|
|
178
|
+
/**
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* new SortedList<number>([1, 2, 3]).length; // 3
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
get length(): number;
|
|
185
|
+
/**
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const scores = new SortedList<number>([1, 2, 3]);
|
|
189
|
+
* scores.clear();
|
|
190
|
+
* scores.length; // 0
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
clear(): void;
|
|
194
|
+
/**
|
|
195
|
+
* An independent copy — mutating the clone never affects the original.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const original = new SortedList<number>([1, 2, 3]);
|
|
200
|
+
* const copy = original.clone();
|
|
201
|
+
* copy.add(4);
|
|
202
|
+
* original.length; // 3
|
|
203
|
+
* copy.length; // 4
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
clone(): SortedList<T>;
|
|
207
|
+
/**
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* const scores = new SortedList<number>([3, 1, 2]);
|
|
211
|
+
* for (const value of scores) console.log(value); // 1, 2, 3
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Like {@link SortedList}, but rejects duplicates (compared via the
|
|
219
|
+
* comparator, not reference identity). Adds set-theory operations.
|
|
220
|
+
*
|
|
221
|
+
* Reuses `SortedList`'s bucket structure entirely: the only behavioral
|
|
222
|
+
* difference is that `add` is a no-op for values already present.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const tags = new SortedSet<string>(['b', 'a', 'c', 'a']);
|
|
227
|
+
* [...tags]; // ['a', 'b', 'c'] — the duplicate 'a' was dropped
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
declare class SortedSet<T> extends SortedList<T> {
|
|
231
|
+
/**
|
|
232
|
+
* O(log n) `has` check + O(√n) amortized insert if the value is new.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const tags = new SortedSet<string>(['a']);
|
|
237
|
+
* tags.add('a'); // no-op, already present
|
|
238
|
+
* tags.length; // 1
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
add(value: T): void;
|
|
242
|
+
/**
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* const original = new SortedSet<number>([1, 2, 3]);
|
|
246
|
+
* const copy = original.clone();
|
|
247
|
+
* copy.add(4);
|
|
248
|
+
* original.length; // 3
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
clone(): SortedSet<T>;
|
|
252
|
+
/**
|
|
253
|
+
* O(m log n + m) for a set of size m being merged in.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* const a = new SortedSet<number>([1, 2, 3]);
|
|
258
|
+
* const b = new SortedSet<number>([3, 4]);
|
|
259
|
+
* [...a.union(b)]; // [1, 2, 3, 4]
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
union(other: SortedSet<T>): SortedSet<T>;
|
|
263
|
+
/**
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const a = new SortedSet<number>([1, 2, 3]);
|
|
267
|
+
* const b = new SortedSet<number>([2, 3, 4]);
|
|
268
|
+
* [...a.intersection(b)]; // [2, 3]
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
intersection(other: SortedSet<T>): SortedSet<T>;
|
|
272
|
+
/**
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* const a = new SortedSet<number>([1, 2, 3]);
|
|
276
|
+
* const b = new SortedSet<number>([2, 3]);
|
|
277
|
+
* [...a.difference(b)]; // [1] — in a, not in b
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
difference(other: SortedSet<T>): SortedSet<T>;
|
|
281
|
+
/**
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* new SortedSet<number>([2, 3]).isSubsetOf(new SortedSet<number>([1, 2, 3, 4])); // true
|
|
285
|
+
* new SortedSet<number>([1, 5]).isSubsetOf(new SortedSet<number>([1, 2, 3])); // false
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
isSubsetOf(other: SortedSet<T>): boolean;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* A dictionary ordered by key.
|
|
293
|
+
*
|
|
294
|
+
* Uses the internal {@link BucketEngine} directly (on `[K, V]` tuples, with a
|
|
295
|
+
* comparator that only looks at the key) rather than composing over
|
|
296
|
+
* `SortedList`'s public API. Two reasons: `set` needs the engine's O(log n)
|
|
297
|
+
* in-place replace-or-insert (`SortedList#bisectLeft` + `#at` would pay for a
|
|
298
|
+
* positional index it doesn't need), and `get`/`has`/`delete` use the `*By`
|
|
299
|
+
* lookup methods with a closure over the bare key — that compares the key
|
|
300
|
+
* only once per candidate (not twice, since the search side needs no
|
|
301
|
+
* `entry[0]` unwrapping) and avoids allocating a throwaway `[key, undefined]`
|
|
302
|
+
* search tuple per call.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* const byPrice = new SortedMap<number, string>([[101.5, 'order-1'], [99.75, 'order-2']]);
|
|
307
|
+
* [...byPrice.keys()]; // [99.75, 101.5]
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare class SortedMap<K, V> implements Iterable<[K, V]> {
|
|
311
|
+
private readonly engine;
|
|
312
|
+
private readonly keyComparator;
|
|
313
|
+
/**
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* new SortedMap<number, string>(); // empty
|
|
317
|
+
* new SortedMap<number, string>([[2, 'b'], [1, 'a']]); // ordered by key: 1, 2
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
constructor(entries?: Iterable<[K, V]>, ...options: ComparatorArg<K>);
|
|
321
|
+
/**
|
|
322
|
+
* O(log n) to locate + O(1) to replace in place, or O(√n) amortized to insert.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* const byPrice = new SortedMap<number, string>();
|
|
327
|
+
* byPrice.set(101.5, 'order-1');
|
|
328
|
+
* byPrice.set(101.5, 'order-1-updated'); // overwrites, doesn't grow size
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
set(key: K, value: V): void;
|
|
332
|
+
/**
|
|
333
|
+
* O(log n): binary search for the bucket, then binary search within it.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* const byPrice = new SortedMap<number, string>([[101.5, 'order-1']]);
|
|
338
|
+
* byPrice.get(101.5); // 'order-1'
|
|
339
|
+
* byPrice.get(1); // undefined
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
get(key: K): V | undefined;
|
|
343
|
+
/**
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const byPrice = new SortedMap<number, string>([[101.5, 'order-1']]);
|
|
347
|
+
* byPrice.delete(101.5); // true
|
|
348
|
+
* byPrice.delete(101.5); // false — already gone
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
delete(key: K): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* new SortedMap<number, string>([[1, 'a']]).has(1); // true
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
has(key: K): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* A snapshot `SortedSet` of the current keys — not a live view.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* const byPrice = new SortedMap<number, string>([[2, 'b'], [1, 'a']]);
|
|
365
|
+
* [...byPrice.keys()]; // [1, 2]
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
keys(): SortedSet<K>;
|
|
369
|
+
private keysGenerator;
|
|
370
|
+
/**
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* [...new SortedMap<number, string>([[2, 'b'], [1, 'a']]).values()]; // ['a', 'b']
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
values(): IterableIterator<V>;
|
|
377
|
+
/**
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* [...new SortedMap<number, string>([[2, 'b'], [1, 'a']]).entries()]; // [[1, 'a'], [2, 'b']]
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
entries(): IterableIterator<[K, V]>;
|
|
384
|
+
/**
|
|
385
|
+
* Iterates `[key, value]` pairs with keys in `[minKey, maxKey]`.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const byPrice = new SortedMap<number, string>([[95, 'a'], [100, 'b'], [105, 'c']]);
|
|
390
|
+
* [...byPrice.irange(95, 100)]; // [[95, 'a'], [100, 'b']]
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
irange(minKey?: K, maxKey?: K): IterableIterator<[K, V]>;
|
|
394
|
+
/**
|
|
395
|
+
* O(√n). Entry at ordinal position `index` in key order.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* const byPrice = new SortedMap<number, string>([[2, 'b'], [1, 'a']]);
|
|
400
|
+
* byPrice.at(0); // [1, 'a']
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
at(index: number): [K, V] | undefined;
|
|
404
|
+
/**
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* new SortedMap<number, string>([[1, 'a'], [2, 'b']]).size; // 2
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
get size(): number;
|
|
411
|
+
/**
|
|
412
|
+
* @example
|
|
413
|
+
* ```ts
|
|
414
|
+
* const byPrice = new SortedMap<number, string>([[1, 'a']]);
|
|
415
|
+
* byPrice.clear();
|
|
416
|
+
* byPrice.size; // 0
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
clear(): void;
|
|
420
|
+
/**
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* for (const [key, value] of new SortedMap([[2, 'b'], [1, 'a']])) {
|
|
424
|
+
* console.log(key, value); // 1 'a', then 2 'b'
|
|
425
|
+
* }
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export { type Comparator, type NaturallyOrderable, SortedList, SortedMap, type SortedOptions, type SortedOptionsRequired, SortedSet };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function m(i,t,e,r){let n=0,o=i;for(;n<o;){let s=n+o>>>1,a=e(t(s));(r==="left"?a>=0:a>0)?o=s:n=s+1;}return n}var h=class h{constructor(t){this.buckets=[];this.count=0;this.comparator=t;}targetBucketSize(){return Math.max(h.MIN_BUCKET_SIZE,Math.ceil(Math.sqrt(this.count)))}maybeSplit(t){let e=this.buckets[t],r=this.targetBucketSize();if(e.length>r*2){let n=e.length>>>1,o=e.splice(n);this.buckets.splice(t+1,0,o);}}maybeMerge(t){let e=this.buckets[t];if(e.length===0){this.buckets.splice(t,1);return}if(this.buckets.length<=1)return;let r=this.targetBucketSize();if(e.length<r/2){let n=t>0?t-1:t+1,[o,s]=t<n?[t,n]:[n,t],a=this.buckets[o].concat(this.buckets[s]);this.buckets.splice(o,2,a),this.maybeSplit(o);}}locateBy(t,e){let r=m(this.buckets.length,a=>{let d=this.buckets[a];return d[d.length-1]},t,e),n=Math.min(r,this.buckets.length-1),o=this.buckets[n],s=m(o.length,a=>o[a],t,e);return {bucketIndex:n,localIndex:s}}locate(t,e){return this.locateBy(r=>this.comparator(r,t),e)}locatePosition(t){if(t<0||t>=this.count)return;let e=t;for(let r=0;r<this.buckets.length;r++){let n=this.buckets[r];if(e<n.length)return {bucketIndex:r,localIndex:e};e-=n.length;}throw new Error("BucketEngine: internal invariant violated (count out of sync with buckets)")}globalIndex(t,e){let r=e;for(let n=0;n<t;n++)r+=this.buckets[n].length;return r}resolveIndex(t){return t<0?this.count+t:t}*iterateRange(t,e){for(let r=t.bucketIndex;r<this.buckets.length;r++){if(e&&r>e.bucketIndex)return;let n=this.buckets[r],o=r===t.bucketIndex?t.localIndex:0,s=e&&r===e.bucketIndex?e.localIndex:n.length;for(let a=o;a<s;a++)yield n[a];}}add(t){if(this.buckets.length===0){this.buckets.push([t]),this.count+=1;return}let{bucketIndex:e,localIndex:r}=this.locate(t,"right");this.buckets[e].splice(r,0,t),this.count+=1,this.maybeSplit(e);}set(t){if(this.buckets.length===0){this.buckets.push([t]),this.count+=1;return}let{bucketIndex:e,localIndex:r}=this.locate(t,"left"),n=this.buckets[e];if(r<n.length&&this.comparator(n[r],t)===0){n[r]=t;return}n.splice(r,0,t),this.count+=1,this.maybeSplit(e);}remove(t){return this.removeBy(e=>this.comparator(e,t))}removeBy(t){if(this.buckets.length===0)return false;let{bucketIndex:e,localIndex:r}=this.locateBy(t,"left"),n=this.buckets[e];return r>=n.length||t(n[r])!==0?false:(n.splice(r,1),this.count-=1,this.maybeMerge(e),true)}discard(t){this.remove(t);}pop(t){if(this.count===0)throw new RangeError("SortedList#pop: list is empty");let e=t===void 0?this.count-1:this.resolveIndex(t),r=this.locatePosition(e);if(!r)throw new RangeError(`SortedList#pop: index ${t} is out of range`);let n=this.buckets[r.bucketIndex],[o]=n.splice(r.localIndex,1);return this.count-=1,this.maybeMerge(r.bucketIndex),o}at(t){let e=this.locatePosition(this.resolveIndex(t));if(e)return this.buckets[e.bucketIndex][e.localIndex]}indexOf(t){if(this.buckets.length===0)return -1;let{bucketIndex:e,localIndex:r}=this.locate(t,"left"),n=this.buckets[e];return r>=n.length||this.comparator(n[r],t)!==0?-1:this.globalIndex(e,r)}has(t){return this.hasBy(e=>this.comparator(e,t))}hasBy(t){return this.findBy(t)!==void 0}findBy(t){if(this.buckets.length===0)return;let{bucketIndex:e,localIndex:r}=this.locateBy(t,"left"),n=this.buckets[e];return r<n.length&&t(n[r])===0?n[r]:void 0}bisectLeft(t){if(this.buckets.length===0)return 0;let{bucketIndex:e,localIndex:r}=this.locate(t,"left");return this.globalIndex(e,r)}bisectRight(t){if(this.buckets.length===0)return 0;let{bucketIndex:e,localIndex:r}=this.locate(t,"right");return this.globalIndex(e,r)}irange(t,e,r){if(this.buckets.length===0)return this.iterateRange({bucketIndex:0,localIndex:0});let[n,o]=r?.inclusive??[true,true],s=t===void 0?{bucketIndex:0,localIndex:0}:this.locate(t,n?"left":"right"),a=e===void 0?void 0:this.locate(e,o?"right":"left");return this.iterateRange(s,a)}islice(t,e){let r=Math.max(0,t===void 0?0:this.resolveIndex(t)),n=Math.min(this.count,e===void 0?this.count:this.resolveIndex(e));if(r>=n||this.count===0)return this.iterateRange({bucketIndex:0,localIndex:0},{bucketIndex:0,localIndex:0});let o=this.locatePosition(r),s=this.locatePosition(n-1);return this.iterateRange(o,{bucketIndex:s.bucketIndex,localIndex:s.localIndex+1})}get length(){return this.count}clear(){this.buckets=[],this.count=0;}[Symbol.iterator](){return this.iterateRange({bucketIndex:0,localIndex:0})}};h.MIN_BUCKET_SIZE=32;var c=h;function f(i,t){if(typeof i=="number"&&typeof t=="number")return i-t;let e=String(i),r=String(t);return e<r?-1:e>r?1:0}var u=class i{constructor(t,...e){let n=e[0]?.comparator??f;this.engine=new c(n),t&&this.update(t);}comparatorArg(){return [{comparator:this.engine.comparator}]}add(t){this.engine.add(t);}update(t){for(let e of t)this.add(e);}remove(t){return this.engine.remove(t)}discard(t){this.engine.discard(t);}pop(t){return this.engine.pop(t)}at(t){return this.engine.at(t)}indexOf(t){return this.engine.indexOf(t)}has(t){return this.engine.has(t)}bisectLeft(t){return this.engine.bisectLeft(t)}bisectRight(t){return this.engine.bisectRight(t)}irange(t,e,r){return this.engine.irange(t,e,r)}islice(t,e){return this.engine.islice(t,e)}get length(){return this.engine.length}clear(){this.engine.clear();}clone(){return new i(this,...this.comparatorArg())}[Symbol.iterator](){return this.engine[Symbol.iterator]()}};var l=class i extends u{add(t){this.has(t)||super.add(t);}clone(){return new i(this,...this.comparatorArg())}union(t){let e=this.clone();for(let r of t)e.add(r);return e}intersection(t){let e=new i([],...this.comparatorArg());for(let r of this)t.has(r)&&e.add(r);return e}difference(t){let e=new i([],...this.comparatorArg());for(let r of this)t.has(r)||e.add(r);return e}isSubsetOf(t){for(let e of this)if(!t.has(e))return false;return true}};function p(i,t){if(typeof i=="number"&&typeof t=="number")return i-t;let e=String(i),r=String(t);return e<r?-1:e>r?1:0}function g(i){return [{comparator:i}]}var b=class{constructor(t,...e){let r=e[0];this.keyComparator=r?.comparator??p;let n=(o,s)=>this.keyComparator(o[0],s[0]);if(this.engine=new c(n),t)for(let[o,s]of t)this.set(o,s);}set(t,e){this.engine.set([t,e]);}get(t){return this.engine.findBy(e=>this.keyComparator(e[0],t))?.[1]}delete(t){return this.engine.removeBy(e=>this.keyComparator(e[0],t))}has(t){return this.engine.hasBy(e=>this.keyComparator(e[0],t))}keys(){return new l(this.keysGenerator(),...g(this.keyComparator))}*keysGenerator(){for(let[t]of this.engine)yield t;}*values(){for(let[,t]of this.engine)yield t;}entries(){return this.engine[Symbol.iterator]()}irange(t,e){let r=t===void 0?void 0:[t,void 0],n=e===void 0?void 0:[e,void 0];return this.engine.irange(r,n)}at(t){return this.engine.at(t)}get size(){return this.engine.length}clear(){this.engine.clear();}[Symbol.iterator](){return this.engine[Symbol.iterator]()}};export{u as SortedList,b as SortedMap,l as SortedSet};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/bucket-engine.ts","../src/sorted-list.ts","../src/sorted-set.ts","../src/sorted-map.ts"],"names":["bisectByCompare","length","getCandidate","compare","bias","lo","hi","mid","cmp","_BucketEngine","comparator","bucketIndex","bucket","target","right","neighborIndex","a","b","merged","i","clampedBucketIndex","localIndex","value","candidate","index","remaining","total","start","end","from","to","resolved","location","min","max","options","minInclusive","maxInclusive","resolvedStart","resolvedEnd","startLoc","endLoc","BucketEngine","defaultComparator","left","SortedList","_SortedList","iterable","SortedSet","_SortedSet","other","result","defaultKeyComparator","comparatorArgs","SortedMap","entries","opts","entryComparator","key","entry","minKey","maxKey"],"mappings":"AAWA,SAASA,CAAAA,CACPC,EACAC,CAAAA,CACAC,CAAAA,CACAC,EACQ,CACR,IAAIC,CAAAA,CAAK,CAAA,CACLC,CAAAA,CAAKL,CAAAA,CACT,KAAOI,CAAAA,CAAKC,CAAAA,EAAI,CACd,IAAMC,CAAAA,CAAOF,EAAKC,CAAAA,GAAQ,CAAA,CACpBE,CAAAA,CAAML,CAAAA,CAAQD,CAAAA,CAAaK,CAAG,CAAC,CAAA,CAAA,CACtBH,CAAAA,GAAS,OAASI,CAAAA,EAAO,CAAA,CAAIA,EAAM,CAAA,EAEhDF,CAAAA,CAAKC,CAAAA,CAELF,CAAAA,CAAKE,CAAAA,CAAM,EAEf,CACA,OAAOF,CACT,CAwBO,IAAMI,CAAAA,CAAN,MAAMA,CAAuC,CAOlD,WAAA,CAAYC,CAAAA,CAA2B,CAJvC,IAAA,CAAQ,OAAA,CAAiB,EAAC,CAC1B,IAAA,CAAQ,MAAQ,CAAA,CAId,IAAA,CAAK,WAAaA,EACpB,CAEQ,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,CACnB,OAAO,IAAIV,CAAAA,CAAa,KAAK,aAAA,EAAc,CAAG,GAAGK,CAAAA,CAAe,IAAA,CAAK,aAAa,CAAC,CACrF,CAEA,CAAS,aAAA,EAA8B,CACrC,OAAW,CAACK,CAAG,CAAA,GAAK,IAAA,CAAK,MAAA,CACvB,MAAMA,EAEV,CAQA,CAAC,QAA8B,CAC7B,IAAA,GAAW,EAAGpC,CAAK,CAAA,GAAK,IAAA,CAAK,MAAA,CAC3B,MAAMA,EAEV,CAQA,OAAA,EAAoC,CAClC,OAAO,IAAA,CAAK,OAAO,MAAA,CAAO,QAAQ,CAAA,EACpC,CAWA,MAAA,CAAOsC,EAAYC,CAAAA,CAAsC,CACvD,IAAM5B,CAAAA,CAAM2B,CAAAA,GAAW,MAAA,CAAY,OAAa,CAACA,CAAAA,CAAQ,MAAyB,CAAA,CAC5E1B,CAAAA,CAAM2B,CAAAA,GAAW,OAAY,MAAA,CAAa,CAACA,EAAQ,MAAyB,CAAA,CAClF,OAAO,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO5B,CAAAA,CAAKC,CAAG,CACpC,CAWA,EAAA,CAAGV,CAAAA,CAAmC,CACpC,OAAO,IAAA,CAAK,OAAO,EAAA,CAAGA,CAAK,CAC7B,CAQA,IAAI,IAAA,EAAe,CACjB,OAAO,IAAA,CAAK,OAAO,MACrB,CAUA,OAAc,CACZ,IAAA,CAAK,MAAA,CAAO,KAAA,GACd,CAUA,CAAC,MAAA,CAAO,QAAQ,CAAA,EAA8B,CAC5C,OAAO,IAAA,CAAK,OAAO,MAAA,CAAO,QAAQ,CAAA,EACpC,CACF","file":"index.js","sourcesContent":["import type { Comparator } from '../types.js';\n\ntype Bias = 'left' | 'right';\n\n/**\n * Generic binary search over `length` candidates. `compare(candidate)` must\n * return the same sign a comparator would for `comparator(candidate, target)`\n * — i.e. negative if the candidate sorts before the (implicit) target.\n * Taking a closure instead of `(target, comparator)` lets callers search by\n * a bare key without constructing a throwaway full element to compare against.\n */\nfunction bisectByCompare<T>(\n length: number,\n getCandidate: (index: number) => T,\n compare: (candidate: T) => number,\n bias: Bias,\n): number {\n let lo = 0;\n let hi = length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n const cmp = compare(getCandidate(mid));\n const goLeft = bias === 'left' ? cmp >= 0 : cmp > 0;\n if (goLeft) {\n hi = mid;\n } else {\n lo = mid + 1;\n }\n }\n return lo;\n}\n\ninterface BucketLocation {\n bucketIndex: number;\n localIndex: number;\n}\n\n/**\n * Internal \"list of lists\" (sqrt-decomposition) engine shared by `SortedList`\n * and `SortedMap` — not part of the public API.\n *\n * Buckets of roughly √n sorted elements each, the same technique used by\n * Python's `sortedcontainers`. Locating a bucket by value is a binary search\n * over bucket boundaries (O(log buckets)); locating by position walks bucket\n * lengths (O(buckets)). With bucket count kept close to √n, that's O(log n)\n * and O(√n) respectively.\n *\n * `SortedMap` uses the `*By` methods directly (with a closure that compares\n * a stored `[K, V]` entry against a bare key) instead of `SortedList`'s\n * public wrapper: going through `bisectLeft` + `at` would pay for a\n * positional index (O(√n)) it doesn't need, and comparing via a search value\n * would need a throwaway `[key, undefined]` tuple and double key-unwrapping\n * per comparison instead of one.\n */\nexport class BucketEngine<T> implements Iterable<T> {\n private static readonly MIN_BUCKET_SIZE = 32;\n\n private buckets: T[][] = [];\n private count = 0;\n readonly comparator: Comparator<T>;\n\n constructor(comparator: Comparator<T>) {\n this.comparator = comparator;\n }\n\n private targetBucketSize(): number {\n return Math.max(BucketEngine.MIN_BUCKET_SIZE, Math.ceil(Math.sqrt(this.count)));\n }\n\n private maybeSplit(bucketIndex: number): void {\n const bucket = this.buckets[bucketIndex]!;\n const target = this.targetBucketSize();\n if (bucket.length > target * 2) {\n const mid = bucket.length >>> 1;\n const right = bucket.splice(mid);\n this.buckets.splice(bucketIndex + 1, 0, right);\n }\n }\n\n private maybeMerge(bucketIndex: number): void {\n const bucket = this.buckets[bucketIndex]!;\n if (bucket.length === 0) {\n this.buckets.splice(bucketIndex, 1);\n return;\n }\n if (this.buckets.length <= 1) {\n return;\n }\n const target = this.targetBucketSize();\n if (bucket.length < target / 2) {\n const neighborIndex = bucketIndex > 0 ? bucketIndex - 1 : bucketIndex + 1;\n const [a, b] =\n bucketIndex < neighborIndex ? [bucketIndex, neighborIndex] : [neighborIndex, bucketIndex];\n const merged = this.buckets[a]!.concat(this.buckets[b]!);\n this.buckets.splice(a, 2, merged);\n this.maybeSplit(a);\n }\n }\n\n /** Lookup by an arbitrary comparison closure: which (bucket, local index) does it point to? O(log n). Callers must ensure buckets is non-empty. */\n private locateBy(compare: (candidate: T) => number, bias: Bias): BucketLocation {\n const bucketIndex = bisectByCompare(\n this.buckets.length,\n (i) => {\n const bucket = this.buckets[i]!;\n return bucket[bucket.length - 1]!;\n },\n compare,\n bias,\n );\n const clampedBucketIndex = Math.min(bucketIndex, this.buckets.length - 1);\n const bucket = this.buckets[clampedBucketIndex]!;\n const localIndex = bisectByCompare(bucket.length, (i) => bucket[i]!, compare, bias);\n return { bucketIndex: clampedBucketIndex, localIndex };\n }\n\n /** Value-based lookup: which (bucket, local index) does `value` belong at? O(log n). Callers must ensure buckets is non-empty. */\n private locate(value: T, bias: Bias): BucketLocation {\n return this.locateBy((candidate) => this.comparator(candidate, value), bias);\n }\n\n /** Position-based lookup: which (bucket, local index) is global index `index` at? O(√n). */\n private locatePosition(index: number): BucketLocation | undefined {\n if (index < 0 || index >= this.count) {\n return undefined;\n }\n let remaining = index;\n for (let i = 0; i < this.buckets.length; i++) {\n const bucket = this.buckets[i]!;\n if (remaining < bucket.length) {\n return { bucketIndex: i, localIndex: remaining };\n }\n remaining -= bucket.length;\n }\n /* v8 ignore next -- unreachable unless `count` desyncs from `buckets`, which would be an internal bug */\n throw new Error('BucketEngine: internal invariant violated (count out of sync with buckets)');\n }\n\n /** Inverse of {@link locatePosition}: sums preceding bucket lengths. O(√n). */\n private globalIndex(bucketIndex: number, localIndex: number): number {\n let total = localIndex;\n for (let i = 0; i < bucketIndex; i++) {\n total += this.buckets[i]!.length;\n }\n return total;\n }\n\n private resolveIndex(index: number): number {\n return index < 0 ? this.count + index : index;\n }\n\n private *iterateRange(start: BucketLocation, end?: BucketLocation): Generator<T> {\n for (let bucketIndex = start.bucketIndex; bucketIndex < this.buckets.length; bucketIndex++) {\n if (end && bucketIndex > end.bucketIndex) {\n return;\n }\n const bucket = this.buckets[bucketIndex]!;\n const from = bucketIndex === start.bucketIndex ? start.localIndex : 0;\n const to = end && bucketIndex === end.bucketIndex ? end.localIndex : bucket.length;\n for (let i = from; i < to; i++) {\n yield bucket[i]!;\n }\n }\n }\n\n /** O(√n) amortized: locates the target bucket and splices the value in, splitting oversized buckets. */\n add(value: T): void {\n if (this.buckets.length === 0) {\n this.buckets.push([value]);\n this.count += 1;\n return;\n }\n const { bucketIndex, localIndex } = this.locate(value, 'right');\n this.buckets[bucketIndex]!.splice(localIndex, 0, value);\n this.count += 1;\n this.maybeSplit(bucketIndex);\n }\n\n /**\n * Replaces the stored element equal to `value` (by comparator) in place, or\n * inserts it if absent. O(log n) to locate; O(1) to replace in place, or\n * O(√n) amortized to insert. This is what backs `SortedMap#set` — cheaper\n * than a separate find-then-remove-then-add round trip.\n */\n set(value: T): void {\n if (this.buckets.length === 0) {\n this.buckets.push([value]);\n this.count += 1;\n return;\n }\n const { bucketIndex, localIndex } = this.locate(value, 'left');\n const bucket = this.buckets[bucketIndex]!;\n if (localIndex < bucket.length && this.comparator(bucket[localIndex]!, value) === 0) {\n bucket[localIndex] = value;\n return;\n }\n bucket.splice(localIndex, 0, value);\n this.count += 1;\n this.maybeSplit(bucketIndex);\n }\n\n remove(value: T): boolean {\n return this.removeBy((candidate) => this.comparator(candidate, value));\n }\n\n /** Same O(log n) path as {@link remove}, via an arbitrary comparison closure instead of a full value. */\n removeBy(compare: (candidate: T) => number): boolean {\n if (this.buckets.length === 0) {\n return false;\n }\n const { bucketIndex, localIndex } = this.locateBy(compare, 'left');\n const bucket = this.buckets[bucketIndex]!;\n if (localIndex >= bucket.length || compare(bucket[localIndex]!) !== 0) {\n return false;\n }\n bucket.splice(localIndex, 1);\n this.count -= 1;\n this.maybeMerge(bucketIndex);\n return true;\n }\n\n discard(value: T): void {\n this.remove(value);\n }\n\n pop(index?: number): T {\n if (this.count === 0) {\n throw new RangeError('SortedList#pop: list is empty');\n }\n const resolved = index === undefined ? this.count - 1 : this.resolveIndex(index);\n const location = this.locatePosition(resolved);\n if (!location) {\n throw new RangeError(`SortedList#pop: index ${index} is out of range`);\n }\n const bucket = this.buckets[location.bucketIndex]!;\n const [value] = bucket.splice(location.localIndex, 1);\n this.count -= 1;\n this.maybeMerge(location.bucketIndex);\n return value as T;\n }\n\n /** O(√n): walks bucket lengths to find the element at `index` (negative indices count from the end). */\n at(index: number): T | undefined {\n const location = this.locatePosition(this.resolveIndex(index));\n if (!location) {\n return undefined;\n }\n return this.buckets[location.bucketIndex]![location.localIndex];\n }\n\n indexOf(value: T): number {\n if (this.buckets.length === 0) {\n return -1;\n }\n const { bucketIndex, localIndex } = this.locate(value, 'left');\n const bucket = this.buckets[bucketIndex]!;\n if (localIndex >= bucket.length || this.comparator(bucket[localIndex]!, value) !== 0) {\n return -1;\n }\n return this.globalIndex(bucketIndex, localIndex);\n }\n\n /** O(log n): binary search for the bucket, then binary search within it. */\n has(value: T): boolean {\n return this.hasBy((candidate) => this.comparator(candidate, value));\n }\n\n /** Same O(log n) path as {@link has}, via an arbitrary comparison closure instead of a full value. */\n hasBy(compare: (candidate: T) => number): boolean {\n return this.findBy(compare) !== undefined;\n }\n\n /** Same O(log n) path as {@link has}, but returns the actual stored element instead of a boolean. */\n findBy(compare: (candidate: T) => number): T | undefined {\n if (this.buckets.length === 0) {\n return undefined;\n }\n const { bucketIndex, localIndex } = this.locateBy(compare, 'left');\n const bucket = this.buckets[bucketIndex]!;\n return localIndex < bucket.length && compare(bucket[localIndex]!) === 0\n ? bucket[localIndex]\n : undefined;\n }\n\n bisectLeft(value: T): number {\n if (this.buckets.length === 0) {\n return 0;\n }\n const { bucketIndex, localIndex } = this.locate(value, 'left');\n return this.globalIndex(bucketIndex, localIndex);\n }\n\n bisectRight(value: T): number {\n if (this.buckets.length === 0) {\n return 0;\n }\n const { bucketIndex, localIndex } = this.locate(value, 'right');\n return this.globalIndex(bucketIndex, localIndex);\n }\n\n /** O(log n) to locate both bounds by value + O(k) to iterate the k results. */\n irange(min?: T, max?: T, options?: { inclusive?: [boolean, boolean] }): IterableIterator<T> {\n if (this.buckets.length === 0) {\n return this.iterateRange({ bucketIndex: 0, localIndex: 0 });\n }\n const [minInclusive, maxInclusive] = options?.inclusive ?? [true, true];\n const start =\n min === undefined\n ? { bucketIndex: 0, localIndex: 0 }\n : this.locate(min, minInclusive ? 'left' : 'right');\n const end = max === undefined ? undefined : this.locate(max, maxInclusive ? 'right' : 'left');\n return this.iterateRange(start, end);\n }\n\n /**\n * O(√n) to locate both positional bounds + O(k) to iterate the k results.\n * (Slightly worse than the O(log n) originally targeted for this method —\n * positional lookup fundamentally needs a bucket-length walk without a\n * Fenwick index. Confirmed empirically via `npm run bench`.)\n */\n islice(start?: number, end?: number): IterableIterator<T> {\n const resolvedStart = Math.max(0, start === undefined ? 0 : this.resolveIndex(start));\n const resolvedEnd = Math.min(\n this.count,\n end === undefined ? this.count : this.resolveIndex(end),\n );\n if (resolvedStart >= resolvedEnd || this.count === 0) {\n return this.iterateRange(\n { bucketIndex: 0, localIndex: 0 },\n { bucketIndex: 0, localIndex: 0 },\n );\n }\n const startLoc = this.locatePosition(resolvedStart)!;\n const endLoc = this.locatePosition(resolvedEnd - 1)!;\n return this.iterateRange(startLoc, {\n bucketIndex: endLoc.bucketIndex,\n localIndex: endLoc.localIndex + 1,\n });\n }\n\n get length(): number {\n return this.count;\n }\n\n clear(): void {\n this.buckets = [];\n this.count = 0;\n }\n\n [Symbol.iterator](): IterableIterator<T> {\n return this.iterateRange({ bucketIndex: 0, localIndex: 0 });\n }\n}\n","import { BucketEngine } from './internal/bucket-engine.js';\nimport type { Comparator, ComparatorArg, SortedOptions } from './types.js';\n\nfunction defaultComparator<T>(a: T, b: T): number {\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n const left = String(a);\n const right = String(b);\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n\n/**\n * A list that keeps its elements in sorted order as they're inserted.\n *\n * A thin public wrapper around the internal {@link BucketEngine} — see there\n * for the actual \"list of lists\" (sqrt-decomposition) implementation and its\n * complexity notes.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([42, 7, 99]);\n * scores.add(15);\n * [...scores]; // [7, 15, 42, 99]\n * ```\n */\nexport class SortedList<T> implements Iterable<T> {\n private readonly engine: BucketEngine<T>;\n\n /**\n * @example\n * ```ts\n * new SortedList<number>(); // empty\n * new SortedList<number>([3, 1, 2]); // [1, 2, 3]\n * new SortedList<Person>([...], { comparator: (a, b) => a.age - b.age });\n * ```\n */\n constructor(iterable?: Iterable<T>, ...options: ComparatorArg<T>) {\n const opts = options[0] as SortedOptions<T> | undefined;\n const comparator = opts?.comparator ?? (defaultComparator as Comparator<T>);\n this.engine = new BucketEngine<T>(comparator);\n // Goes through `this.update` -> `this.add` (not the engine's) so that a\n // SortedSet's overridden, deduping `add` applies during construction too.\n if (iterable) {\n this.update(iterable);\n }\n }\n\n /** Safe to call from subclasses/clone: both `ComparatorArg<T>` branches accept `{ comparator }`. */\n protected comparatorArg(): ComparatorArg<T> {\n return [{ comparator: this.engine.comparator }] as unknown as ComparatorArg<T>;\n }\n\n /**\n * O(√n) amortized.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>();\n * scores.add(42);\n * scores.add(7);\n * [...scores]; // [7, 42]\n * ```\n */\n add(value: T): void {\n this.engine.add(value);\n }\n\n /**\n * Bulk-inserts every value from `iterable`, one {@link add} at a time.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([3, 1]);\n * scores.update([2, 5, 4]);\n * [...scores]; // [1, 2, 3, 4, 5]\n * ```\n */\n update(iterable: Iterable<T>): void {\n for (const value of iterable) {\n this.add(value);\n }\n }\n\n /**\n * Removes the first occurrence of `value`. Returns `false` if it wasn't present.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([1, 2, 2, 3]);\n * scores.remove(2); // true — removes one occurrence\n * scores.remove(99); // false — not present\n * ```\n */\n remove(value: T): boolean {\n return this.engine.remove(value);\n }\n\n /**\n * Like {@link remove}, but never throws (or returns anything) if `value` isn't present.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([1, 2, 3]);\n * scores.discard(99); // no-op, no error\n * ```\n */\n discard(value: T): void {\n this.engine.discard(value);\n }\n\n /**\n * Removes and returns the element at `index` (default: the last element).\n * Negative indices count from the end, same as {@link at}.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([10, 20, 30]);\n * scores.pop(); // 30 — last element\n * scores.pop(0); // 10 — first element\n * ```\n */\n pop(index?: number): T {\n return this.engine.pop(index);\n }\n\n /**\n * O(√n): walks bucket lengths to find the element at `index` (negative indices count from the end).\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([10, 20, 30]);\n * scores.at(0); // 10\n * scores.at(-1); // 30 — same as Array.prototype.at\n * scores.at(99); // undefined — out of range\n * ```\n */\n at(index: number): T | undefined {\n return this.engine.at(index);\n }\n\n /**\n * The index of the first occurrence of `value`, or `-1` if absent.\n *\n * @example\n * ```ts\n * new SortedList<number>([1, 2, 2, 3]).indexOf(2); // 1\n * new SortedList<number>([1, 2, 3]).indexOf(99); // -1\n * ```\n */\n indexOf(value: T): number {\n return this.engine.indexOf(value);\n }\n\n /**\n * O(log n): binary search for the bucket, then binary search within it.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([1, 2, 3]);\n * scores.has(2); // true\n * scores.has(99); // false\n * ```\n */\n has(value: T): boolean {\n return this.engine.has(value);\n }\n\n /**\n * The leftmost index where `value` could be inserted while keeping the list sorted.\n *\n * @example\n * ```ts\n * new SortedList<number>([1, 2, 2, 2, 3]).bisectLeft(2); // 1\n * ```\n */\n bisectLeft(value: T): number {\n return this.engine.bisectLeft(value);\n }\n\n /**\n * The rightmost index where `value` could be inserted while keeping the list sorted.\n *\n * @example\n * ```ts\n * new SortedList<number>([1, 2, 2, 2, 3]).bisectRight(2); // 4\n * ```\n */\n bisectRight(value: T): number {\n return this.engine.bisectRight(value);\n }\n\n /**\n * O(log n) to locate both bounds by value + O(k) to iterate the k results.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([1, 2, 3, 4, 5]);\n * [...scores.irange(2, 4)]; // [2, 3, 4] — inclusive by default\n * [...scores.irange(2, 4, { inclusive: [false, true] })]; // [3, 4]\n * ```\n */\n irange(min?: T, max?: T, options?: { inclusive?: [boolean, boolean] }): IterableIterator<T> {\n return this.engine.irange(min, max, options);\n }\n\n /**\n * O(√n) to locate both positional bounds + O(k) to iterate the k results.\n *\n * @example\n * ```ts\n * const scores = new SortedList<number>([10, 20, 30, 40, 50]);\n * [...scores.islice(1, 4)]; // [20, 30, 40] — like Array.prototype.slice\n * ```\n */\n islice(start?: number, end?: number): IterableIterator<T> {\n return this.engine.islice(start, end);\n }\n\n /**\n * @example\n * ```ts\n * new SortedList<number>([1, 2, 3]).length; // 3\n * ```\n */\n get length(): number {\n return this.engine.length;\n }\n\n /**\n * @example\n * ```ts\n * const scores = new SortedList<number>([1, 2, 3]);\n * scores.clear();\n * scores.length; // 0\n * ```\n */\n clear(): void {\n this.engine.clear();\n }\n\n /**\n * An independent copy — mutating the clone never affects the original.\n *\n * @example\n * ```ts\n * const original = new SortedList<number>([1, 2, 3]);\n * const copy = original.clone();\n * copy.add(4);\n * original.length; // 3\n * copy.length; // 4\n * ```\n */\n clone(): SortedList<T> {\n return new SortedList<T>(this, ...this.comparatorArg());\n }\n\n /**\n * @example\n * ```ts\n * const scores = new SortedList<number>([3, 1, 2]);\n * for (const value of scores) console.log(value); // 1, 2, 3\n * ```\n */\n [Symbol.iterator](): IterableIterator<T> {\n return this.engine[Symbol.iterator]();\n }\n}\n","import { SortedList } from './sorted-list.js';\n\n/**\n * Like {@link SortedList}, but rejects duplicates (compared via the\n * comparator, not reference identity). Adds set-theory operations.\n *\n * Reuses `SortedList`'s bucket structure entirely: the only behavioral\n * difference is that `add` is a no-op for values already present.\n *\n * @example\n * ```ts\n * const tags = new SortedSet<string>(['b', 'a', 'c', 'a']);\n * [...tags]; // ['a', 'b', 'c'] — the duplicate 'a' was dropped\n * ```\n */\nexport class SortedSet<T> extends SortedList<T> {\n /**\n * O(log n) `has` check + O(√n) amortized insert if the value is new.\n *\n * @example\n * ```ts\n * const tags = new SortedSet<string>(['a']);\n * tags.add('a'); // no-op, already present\n * tags.length; // 1\n * ```\n */\n override add(value: T): void {\n if (!this.has(value)) {\n super.add(value);\n }\n }\n\n /**\n * @example\n * ```ts\n * const original = new SortedSet<number>([1, 2, 3]);\n * const copy = original.clone();\n * copy.add(4);\n * original.length; // 3\n * ```\n */\n override clone(): SortedSet<T> {\n return new SortedSet<T>(this, ...this.comparatorArg());\n }\n\n /**\n * O(m log n + m) for a set of size m being merged in.\n *\n * @example\n * ```ts\n * const a = new SortedSet<number>([1, 2, 3]);\n * const b = new SortedSet<number>([3, 4]);\n * [...a.union(b)]; // [1, 2, 3, 4]\n * ```\n */\n union(other: SortedSet<T>): SortedSet<T> {\n const result = this.clone();\n for (const value of other) {\n result.add(value);\n }\n return result;\n }\n\n /**\n * @example\n * ```ts\n * const a = new SortedSet<number>([1, 2, 3]);\n * const b = new SortedSet<number>([2, 3, 4]);\n * [...a.intersection(b)]; // [2, 3]\n * ```\n */\n intersection(other: SortedSet<T>): SortedSet<T> {\n const result = new SortedSet<T>([], ...this.comparatorArg());\n for (const value of this) {\n if (other.has(value)) {\n result.add(value);\n }\n }\n return result;\n }\n\n /**\n * @example\n * ```ts\n * const a = new SortedSet<number>([1, 2, 3]);\n * const b = new SortedSet<number>([2, 3]);\n * [...a.difference(b)]; // [1] — in a, not in b\n * ```\n */\n difference(other: SortedSet<T>): SortedSet<T> {\n const result = new SortedSet<T>([], ...this.comparatorArg());\n for (const value of this) {\n if (!other.has(value)) {\n result.add(value);\n }\n }\n return result;\n }\n\n /**\n * @example\n * ```ts\n * new SortedSet<number>([2, 3]).isSubsetOf(new SortedSet<number>([1, 2, 3, 4])); // true\n * new SortedSet<number>([1, 5]).isSubsetOf(new SortedSet<number>([1, 2, 3])); // false\n * ```\n */\n isSubsetOf(other: SortedSet<T>): boolean {\n for (const value of this) {\n if (!other.has(value)) {\n return false;\n }\n }\n return true;\n }\n}\n","import { BucketEngine } from './internal/bucket-engine.js';\nimport { SortedSet } from './sorted-set.js';\nimport type { Comparator, ComparatorArg, SortedOptions } from './types.js';\n\nfunction defaultKeyComparator<K>(a: K, b: K): number {\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n const left = String(a);\n const right = String(b);\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n\nfunction comparatorArgs<T>(comparator: Comparator<T>): ComparatorArg<T> {\n return [{ comparator }] as unknown as ComparatorArg<T>;\n}\n\n/**\n * A dictionary ordered by key.\n *\n * Uses the internal {@link BucketEngine} directly (on `[K, V]` tuples, with a\n * comparator that only looks at the key) rather than composing over\n * `SortedList`'s public API. Two reasons: `set` needs the engine's O(log n)\n * in-place replace-or-insert (`SortedList#bisectLeft` + `#at` would pay for a\n * positional index it doesn't need), and `get`/`has`/`delete` use the `*By`\n * lookup methods with a closure over the bare key — that compares the key\n * only once per candidate (not twice, since the search side needs no\n * `entry[0]` unwrapping) and avoids allocating a throwaway `[key, undefined]`\n * search tuple per call.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[101.5, 'order-1'], [99.75, 'order-2']]);\n * [...byPrice.keys()]; // [99.75, 101.5]\n * ```\n */\nexport class SortedMap<K, V> implements Iterable<[K, V]> {\n private readonly engine: BucketEngine<[K, V]>;\n private readonly keyComparator: Comparator<K>;\n\n /**\n * @example\n * ```ts\n * new SortedMap<number, string>(); // empty\n * new SortedMap<number, string>([[2, 'b'], [1, 'a']]); // ordered by key: 1, 2\n * ```\n */\n constructor(entries?: Iterable<[K, V]>, ...options: ComparatorArg<K>) {\n const opts = options[0] as SortedOptions<K> | undefined;\n this.keyComparator = opts?.comparator ?? (defaultKeyComparator as Comparator<K>);\n const entryComparator: Comparator<[K, V]> = (a, b) => this.keyComparator(a[0], b[0]);\n this.engine = new BucketEngine<[K, V]>(entryComparator);\n if (entries) {\n for (const [key, value] of entries) {\n this.set(key, value);\n }\n }\n }\n\n /**\n * O(log n) to locate + O(1) to replace in place, or O(√n) amortized to insert.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>();\n * byPrice.set(101.5, 'order-1');\n * byPrice.set(101.5, 'order-1-updated'); // overwrites, doesn't grow size\n * ```\n */\n set(key: K, value: V): void {\n this.engine.set([key, value]);\n }\n\n /**\n * O(log n): binary search for the bucket, then binary search within it.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[101.5, 'order-1']]);\n * byPrice.get(101.5); // 'order-1'\n * byPrice.get(1); // undefined\n * ```\n */\n get(key: K): V | undefined {\n return this.engine.findBy((entry) => this.keyComparator(entry[0], key))?.[1];\n }\n\n /**\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[101.5, 'order-1']]);\n * byPrice.delete(101.5); // true\n * byPrice.delete(101.5); // false — already gone\n * ```\n */\n delete(key: K): boolean {\n return this.engine.removeBy((entry) => this.keyComparator(entry[0], key));\n }\n\n /**\n * @example\n * ```ts\n * new SortedMap<number, string>([[1, 'a']]).has(1); // true\n * ```\n */\n has(key: K): boolean {\n return this.engine.hasBy((entry) => this.keyComparator(entry[0], key));\n }\n\n /**\n * A snapshot `SortedSet` of the current keys — not a live view.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[2, 'b'], [1, 'a']]);\n * [...byPrice.keys()]; // [1, 2]\n * ```\n */\n keys(): SortedSet<K> {\n return new SortedSet<K>(this.keysGenerator(), ...comparatorArgs(this.keyComparator));\n }\n\n private *keysGenerator(): Generator<K> {\n for (const [key] of this.engine) {\n yield key;\n }\n }\n\n /**\n * @example\n * ```ts\n * [...new SortedMap<number, string>([[2, 'b'], [1, 'a']]).values()]; // ['a', 'b']\n * ```\n */\n *values(): IterableIterator<V> {\n for (const [, value] of this.engine) {\n yield value;\n }\n }\n\n /**\n * @example\n * ```ts\n * [...new SortedMap<number, string>([[2, 'b'], [1, 'a']]).entries()]; // [[1, 'a'], [2, 'b']]\n * ```\n */\n entries(): IterableIterator<[K, V]> {\n return this.engine[Symbol.iterator]();\n }\n\n /**\n * Iterates `[key, value]` pairs with keys in `[minKey, maxKey]`.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[95, 'a'], [100, 'b'], [105, 'c']]);\n * [...byPrice.irange(95, 100)]; // [[95, 'a'], [100, 'b']]\n * ```\n */\n irange(minKey?: K, maxKey?: K): IterableIterator<[K, V]> {\n const min = minKey === undefined ? undefined : ([minKey, undefined as unknown as V] as [K, V]);\n const max = maxKey === undefined ? undefined : ([maxKey, undefined as unknown as V] as [K, V]);\n return this.engine.irange(min, max);\n }\n\n /**\n * O(√n). Entry at ordinal position `index` in key order.\n *\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[2, 'b'], [1, 'a']]);\n * byPrice.at(0); // [1, 'a']\n * ```\n */\n at(index: number): [K, V] | undefined {\n return this.engine.at(index);\n }\n\n /**\n * @example\n * ```ts\n * new SortedMap<number, string>([[1, 'a'], [2, 'b']]).size; // 2\n * ```\n */\n get size(): number {\n return this.engine.length;\n }\n\n /**\n * @example\n * ```ts\n * const byPrice = new SortedMap<number, string>([[1, 'a']]);\n * byPrice.clear();\n * byPrice.size; // 0\n * ```\n */\n clear(): void {\n this.engine.clear();\n }\n\n /**\n * @example\n * ```ts\n * for (const [key, value] of new SortedMap([[2, 'b'], [1, 'a']])) {\n * console.log(key, value); // 1 'a', then 2 'b'\n * }\n * ```\n */\n [Symbol.iterator](): IterableIterator<[K, V]> {\n return this.engine[Symbol.iterator]();\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sorted-collections",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "SortedList, SortedSet and SortedMap for JavaScript/TypeScript — zero runtime dependencies, inspired by Python's sortedcontainers.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sorted",
|
|
7
|
+
"sorted-list",
|
|
8
|
+
"sorted-set",
|
|
9
|
+
"sorted-map",
|
|
10
|
+
"data-structures",
|
|
11
|
+
"sortedcontainers",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://johansneirap.github.io/sorted-collections/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/johansneirap/sorted-collections/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/johansneirap/sorted-collections.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Johans Neira",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"module": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"dev": "tsup --watch",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest",
|
|
48
|
+
"test:coverage": "vitest run --coverage",
|
|
49
|
+
"bench": "tsx benchmarks/run.ts",
|
|
50
|
+
"lint": "biome check .",
|
|
51
|
+
"lint:fix": "biome check --write .",
|
|
52
|
+
"format": "biome format --write .",
|
|
53
|
+
"format:check": "biome format .",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"changeset": "changeset",
|
|
56
|
+
"docs:api": "typedoc",
|
|
57
|
+
"docs:dev": "npm run docs:api && vitepress dev docs-site",
|
|
58
|
+
"docs:build": "npm run docs:api && vitepress build docs-site",
|
|
59
|
+
"docs:preview": "vitepress preview docs-site",
|
|
60
|
+
"prepublishOnly": "npm run format:check && npm run lint && npm run typecheck && npm run test && npm run build"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@biomejs/biome": "^2.5.3",
|
|
64
|
+
"@changesets/cli": "^2.31.0",
|
|
65
|
+
"@types/node": "^26.1.1",
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
67
|
+
"fast-check": "^4.9.0",
|
|
68
|
+
"sorted-containers": "^0.4.0",
|
|
69
|
+
"sortedkit": "^0.1.0",
|
|
70
|
+
"tinybench": "^6.0.2",
|
|
71
|
+
"tsup": "^8.5.1",
|
|
72
|
+
"tsx": "^4.23.0",
|
|
73
|
+
"typedoc": "^0.28.20",
|
|
74
|
+
"typedoc-plugin-markdown": "^4.12.0",
|
|
75
|
+
"typedoc-vitepress-theme": "^1.1.3",
|
|
76
|
+
"typescript": "^6.0.3",
|
|
77
|
+
"vitepress": "^1.6.4",
|
|
78
|
+
"vitest": "^4.1.10",
|
|
79
|
+
"vue": "^3.5.39"
|
|
80
|
+
},
|
|
81
|
+
"packageManager": "npm@11.8.0"
|
|
82
|
+
}
|