@holoscript/std 2.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +197 -0
  2. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  3. package/dist/__tests__/EconomicTraits.test.d.ts.map +1 -0
  4. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +1 -0
  5. package/dist/__tests__/Sprint33.test.d.ts.map +1 -0
  6. package/dist/__tests__/Sprint56.test.d.ts.map +1 -0
  7. package/dist/__tests__/collections.test.d.ts.map +1 -0
  8. package/dist/__tests__/events.test.d.ts.map +1 -0
  9. package/dist/__tests__/materials.test.d.ts.map +1 -0
  10. package/dist/__tests__/math.test.d.ts.map +1 -0
  11. package/dist/__tests__/physics.test.d.ts.map +1 -0
  12. package/dist/__tests__/spatial.test.d.ts.map +1 -0
  13. package/dist/__tests__/string-decoupled.test.d.ts.map +1 -0
  14. package/dist/__tests__/string.test.d.ts.map +1 -0
  15. package/dist/__tests__/time.test.d.ts.map +1 -0
  16. package/dist/collections.d.ts.map +1 -1
  17. package/dist/events.d.ts.map +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +42 -9
  20. package/dist/materials.d.ts.map +1 -0
  21. package/dist/math.d.ts.map +1 -1
  22. package/dist/physics.d.ts.map +1 -0
  23. package/dist/spatial.d.ts.map +1 -0
  24. package/dist/string.d.ts.map +1 -1
  25. package/dist/time.d.ts.map +1 -1
  26. package/dist/traits/ARTraits.d.ts.map +1 -0
  27. package/dist/traits/EconomicPrimitives.d.ts.map +1 -0
  28. package/dist/traits/EconomicTraits.d.ts.map +1 -0
  29. package/dist/traits/IoTTraits.d.ts.map +1 -0
  30. package/dist/traits/SimulationLabPrimitives.d.ts.map +1 -0
  31. package/dist/traits/SimulationLabTraits.d.ts.map +1 -0
  32. package/dist/traits/VRRTraits.d.ts.map +1 -0
  33. package/dist/types.d.ts.map +1 -1
  34. package/package.json +17 -6
  35. package/src/__tests__/EconomicPrimitives.test.ts +690 -0
  36. package/src/__tests__/EconomicTraits.test.ts +425 -0
  37. package/src/__tests__/SimulationLabPrimitives.test.ts +415 -0
  38. package/src/__tests__/Sprint33.test.ts +1301 -0
  39. package/src/__tests__/Sprint56.test.ts +1070 -0
  40. package/src/__tests__/collections.test.ts +182 -0
  41. package/src/__tests__/events.test.ts +135 -0
  42. package/src/__tests__/materials.test.ts +84 -0
  43. package/src/__tests__/math.test.ts +246 -0
  44. package/src/__tests__/physics.test.ts +83 -0
  45. package/src/__tests__/spatial.test.ts +333 -0
  46. package/src/__tests__/string-decoupled.test.ts +16 -0
  47. package/src/__tests__/string.test.ts +164 -0
  48. package/src/__tests__/time.test.ts +110 -0
  49. package/src/collections.ts +8 -2
  50. package/src/events.ts +88 -0
  51. package/src/index.ts +161 -11
  52. package/src/materials.ts +109 -0
  53. package/src/math.ts +30 -14
  54. package/src/physics.ts +141 -0
  55. package/src/spatial.ts +320 -0
  56. package/src/string.basic.test.ts +14 -0
  57. package/src/string.test.ts +335 -0
  58. package/src/string.ts +19 -2
  59. package/src/time.ts +9 -10
  60. package/src/traits/ARTraits.ts +103 -0
  61. package/src/traits/EconomicPrimitives.ts +755 -0
  62. package/src/traits/EconomicTraits.ts +552 -0
  63. package/src/traits/IoTTraits.ts +102 -0
  64. package/src/traits/SimulationLabPrimitives.ts +650 -0
  65. package/src/traits/SimulationLabTraits.ts +191 -0
  66. package/src/traits/VRRTraits.ts +326 -0
  67. package/src/types.ts +47 -12
  68. package/vitest.config.ts +10 -0
  69. package/dist/collections.d.ts +0 -177
  70. package/dist/collections.js +0 -720
  71. package/dist/collections.js.map +0 -1
  72. package/dist/index.d.ts +0 -89
  73. package/dist/index.js.map +0 -1
  74. package/dist/math.d.ts +0 -162
  75. package/dist/math.js +0 -539
  76. package/dist/math.js.map +0 -1
  77. package/dist/string.d.ts +0 -208
  78. package/dist/string.js +0 -443
  79. package/dist/string.js.map +0 -1
  80. package/dist/time.d.ts +0 -215
  81. package/dist/time.js +0 -530
  82. package/dist/time.js.map +0 -1
  83. package/dist/types.d.ts +0 -193
  84. package/dist/types.js +0 -198
  85. package/dist/types.js.map +0 -1
@@ -1,720 +0,0 @@
1
- /**
2
- * @holoscript/std - Collections Module
3
- *
4
- * Provides List, Map, and Set implementations with functional operations
5
- * for use in HoloScript Plus programs.
6
- */
7
- /**
8
- * Immutable List with functional operations
9
- */
10
- export class List {
11
- items;
12
- constructor(items = []) {
13
- this.items = Array.from(items);
14
- }
15
- static of(...items) {
16
- return new List(items);
17
- }
18
- static from(iterable) {
19
- return new List(iterable);
20
- }
21
- static range(start, end, step = 1) {
22
- const items = [];
23
- for (let i = start; step > 0 ? i < end : i > end; i += step) {
24
- items.push(i);
25
- }
26
- return new List(items);
27
- }
28
- static repeat(value, count) {
29
- return new List(Array(count).fill(value));
30
- }
31
- get length() {
32
- return this.items.length;
33
- }
34
- get isEmpty() {
35
- return this.items.length === 0;
36
- }
37
- get(index) {
38
- return index < 0 ? this.items[this.items.length + index] : this.items[index];
39
- }
40
- first() {
41
- return this.items[0];
42
- }
43
- last() {
44
- return this.items[this.items.length - 1];
45
- }
46
- map(fn) {
47
- return new List(this.items.map(fn));
48
- }
49
- flatMap(fn) {
50
- const result = [];
51
- this.items.forEach((item, index) => {
52
- const mapped = fn(item, index);
53
- if (mapped instanceof List) {
54
- result.push(...mapped.toArray());
55
- }
56
- else {
57
- result.push(...mapped);
58
- }
59
- });
60
- return new List(result);
61
- }
62
- filter(predicate) {
63
- return new List(this.items.filter(predicate));
64
- }
65
- reject(predicate) {
66
- return this.filter((item, index) => !predicate(item, index));
67
- }
68
- reduce(fn, initial) {
69
- return this.items.reduce(fn, initial);
70
- }
71
- fold(initial, fn) {
72
- return this.items.reduce(fn, initial);
73
- }
74
- find(predicate) {
75
- return this.items.find(predicate);
76
- }
77
- findIndex(predicate) {
78
- return this.items.findIndex(predicate);
79
- }
80
- indexOf(item) {
81
- return this.items.indexOf(item);
82
- }
83
- includes(item) {
84
- return this.items.includes(item);
85
- }
86
- some(predicate) {
87
- return this.items.some(predicate);
88
- }
89
- every(predicate) {
90
- return this.items.every(predicate);
91
- }
92
- none(predicate) {
93
- return !this.some(predicate);
94
- }
95
- count(predicate) {
96
- return this.filter(predicate).length;
97
- }
98
- forEach(fn) {
99
- this.items.forEach(fn);
100
- }
101
- concat(...lists) {
102
- const arrays = lists.map((l) => (l instanceof List ? l.toArray() : l));
103
- return new List([...this.items, ...arrays.flat()]);
104
- }
105
- append(item) {
106
- return new List([...this.items, item]);
107
- }
108
- prepend(item) {
109
- return new List([item, ...this.items]);
110
- }
111
- insert(index, item) {
112
- const arr = [...this.items];
113
- arr.splice(index, 0, item);
114
- return new List(arr);
115
- }
116
- remove(index) {
117
- const arr = [...this.items];
118
- arr.splice(index, 1);
119
- return new List(arr);
120
- }
121
- update(index, item) {
122
- const arr = [...this.items];
123
- arr[index] = item;
124
- return new List(arr);
125
- }
126
- slice(start, end) {
127
- return new List(this.items.slice(start, end));
128
- }
129
- take(n) {
130
- return this.slice(0, n);
131
- }
132
- takeLast(n) {
133
- return this.slice(-n);
134
- }
135
- takeWhile(predicate) {
136
- const result = [];
137
- for (let i = 0; i < this.items.length; i++) {
138
- if (!predicate(this.items[i], i))
139
- break;
140
- result.push(this.items[i]);
141
- }
142
- return new List(result);
143
- }
144
- drop(n) {
145
- return this.slice(n);
146
- }
147
- dropLast(n) {
148
- return this.slice(0, -n);
149
- }
150
- dropWhile(predicate) {
151
- let startIndex = 0;
152
- for (let i = 0; i < this.items.length; i++) {
153
- if (!predicate(this.items[i], i))
154
- break;
155
- startIndex = i + 1;
156
- }
157
- return this.slice(startIndex);
158
- }
159
- reverse() {
160
- return new List([...this.items].reverse());
161
- }
162
- sort(compareFn) {
163
- return new List([...this.items].sort(compareFn));
164
- }
165
- sortBy(fn) {
166
- return this.sort((a, b) => {
167
- const va = fn(a);
168
- const vb = fn(b);
169
- if (va < vb)
170
- return -1;
171
- if (va > vb)
172
- return 1;
173
- return 0;
174
- });
175
- }
176
- shuffle() {
177
- const arr = [...this.items];
178
- for (let i = arr.length - 1; i > 0; i--) {
179
- const j = Math.floor(Math.random() * (i + 1));
180
- [arr[i], arr[j]] = [arr[j], arr[i]];
181
- }
182
- return new List(arr);
183
- }
184
- unique() {
185
- return new List([...new Set(this.items)]);
186
- }
187
- uniqueBy(fn) {
188
- const seen = new Set();
189
- const result = [];
190
- for (const item of this.items) {
191
- const key = fn(item);
192
- if (!seen.has(key)) {
193
- seen.add(key);
194
- result.push(item);
195
- }
196
- }
197
- return new List(result);
198
- }
199
- groupBy(fn) {
200
- const groups = new Map();
201
- for (const item of this.items) {
202
- const key = fn(item);
203
- const group = groups.get(key) || [];
204
- group.push(item);
205
- groups.set(key, group);
206
- }
207
- const result = new Map();
208
- for (const [key, items] of groups) {
209
- result.set(key, new List(items));
210
- }
211
- return new HoloMap(result);
212
- }
213
- partition(predicate) {
214
- const pass = [];
215
- const fail = [];
216
- this.items.forEach((item, index) => {
217
- if (predicate(item, index)) {
218
- pass.push(item);
219
- }
220
- else {
221
- fail.push(item);
222
- }
223
- });
224
- return [new List(pass), new List(fail)];
225
- }
226
- zip(other) {
227
- const length = Math.min(this.length, other.length);
228
- const result = [];
229
- for (let i = 0; i < length; i++) {
230
- result.push([this.items[i], other.get(i)]);
231
- }
232
- return new List(result);
233
- }
234
- zipWith(other, fn) {
235
- return this.zip(other).map(([a, b]) => fn(a, b));
236
- }
237
- flatten() {
238
- const result = [];
239
- for (const item of this.items) {
240
- if (item instanceof List) {
241
- result.push(...item.toArray());
242
- }
243
- else if (Array.isArray(item)) {
244
- result.push(...item);
245
- }
246
- }
247
- return new List(result);
248
- }
249
- sum() {
250
- return this.reduce((acc, n) => acc + n, 0);
251
- }
252
- min() {
253
- if (this.isEmpty)
254
- return undefined;
255
- return Math.min(...this.items);
256
- }
257
- max() {
258
- if (this.isEmpty)
259
- return undefined;
260
- return Math.max(...this.items);
261
- }
262
- average() {
263
- if (this.isEmpty)
264
- return undefined;
265
- return this.sum() / this.length;
266
- }
267
- join(separator = ',') {
268
- return this.items.join(separator);
269
- }
270
- toArray() {
271
- return [...this.items];
272
- }
273
- toSet() {
274
- return new HoloSet(this.items);
275
- }
276
- [Symbol.iterator]() {
277
- return this.items[Symbol.iterator]();
278
- }
279
- toString() {
280
- return `List(${this.items.join(', ')})`;
281
- }
282
- }
283
- /**
284
- * Immutable Map with functional operations
285
- */
286
- export class HoloMap {
287
- _map;
288
- constructor(entries) {
289
- this._map = entries instanceof Map ? entries : new Map(entries);
290
- }
291
- static of(...entries) {
292
- return new HoloMap(entries);
293
- }
294
- static from(entries) {
295
- return new HoloMap(entries);
296
- }
297
- static fromObject(obj) {
298
- return new HoloMap(Object.entries(obj));
299
- }
300
- get size() {
301
- return this._map.size;
302
- }
303
- get isEmpty() {
304
- return this._map.size === 0;
305
- }
306
- get(key) {
307
- return this._map.get(key);
308
- }
309
- getOrDefault(key, defaultValue) {
310
- return this._map.has(key) ? this._map.get(key) : defaultValue;
311
- }
312
- has(key) {
313
- return this._map.has(key);
314
- }
315
- set(key, value) {
316
- const newMap = new Map(this._map);
317
- newMap.set(key, value);
318
- return new HoloMap(newMap);
319
- }
320
- delete(key) {
321
- const newMap = new Map(this._map);
322
- newMap.delete(key);
323
- return new HoloMap(newMap);
324
- }
325
- update(key, fn) {
326
- return this.set(key, fn(this.get(key)));
327
- }
328
- merge(other) {
329
- const newMap = new Map(this._map);
330
- for (const [key, value] of other) {
331
- newMap.set(key, value);
332
- }
333
- return new HoloMap(newMap);
334
- }
335
- keys() {
336
- return new List(this._map.keys());
337
- }
338
- values() {
339
- return new List(this._map.values());
340
- }
341
- entries() {
342
- return new List(this._map.entries());
343
- }
344
- map(fn) {
345
- const entries = [];
346
- for (const [key, value] of this._map) {
347
- entries.push([key, fn(value, key)]);
348
- }
349
- return new HoloMap(entries);
350
- }
351
- mapKeys(fn) {
352
- const entries = [];
353
- for (const [key, value] of this._map) {
354
- entries.push([fn(key, value), value]);
355
- }
356
- return new HoloMap(entries);
357
- }
358
- filter(predicate) {
359
- const entries = [];
360
- for (const [key, value] of this._map) {
361
- if (predicate(value, key)) {
362
- entries.push([key, value]);
363
- }
364
- }
365
- return new HoloMap(entries);
366
- }
367
- reduce(fn, initial) {
368
- let acc = initial;
369
- for (const [key, value] of this._map) {
370
- acc = fn(acc, value, key);
371
- }
372
- return acc;
373
- }
374
- forEach(fn) {
375
- this._map.forEach(fn);
376
- }
377
- find(predicate) {
378
- for (const [key, value] of this._map) {
379
- if (predicate(value, key)) {
380
- return [key, value];
381
- }
382
- }
383
- return undefined;
384
- }
385
- some(predicate) {
386
- for (const [key, value] of this._map) {
387
- if (predicate(value, key))
388
- return true;
389
- }
390
- return false;
391
- }
392
- every(predicate) {
393
- for (const [key, value] of this._map) {
394
- if (!predicate(value, key))
395
- return false;
396
- }
397
- return true;
398
- }
399
- toObject() {
400
- const obj = {};
401
- for (const [key, value] of this._map) {
402
- obj[key] = value;
403
- }
404
- return obj;
405
- }
406
- toNativeMap() {
407
- return new Map(this._map);
408
- }
409
- [Symbol.iterator]() {
410
- return this._map[Symbol.iterator]();
411
- }
412
- toString() {
413
- const entries = [...this._map].map(([k, v]) => `${k}: ${v}`).join(', ');
414
- return `HoloMap { ${entries} }`;
415
- }
416
- }
417
- /**
418
- * Immutable Set with functional operations
419
- */
420
- export class HoloSet {
421
- set;
422
- constructor(items) {
423
- this.set = new Set(items);
424
- }
425
- static of(...items) {
426
- return new HoloSet(items);
427
- }
428
- static from(iterable) {
429
- return new HoloSet(iterable);
430
- }
431
- get size() {
432
- return this.set.size;
433
- }
434
- get isEmpty() {
435
- return this.set.size === 0;
436
- }
437
- has(item) {
438
- return this.set.has(item);
439
- }
440
- add(item) {
441
- const newSet = new Set(this.set);
442
- newSet.add(item);
443
- return new HoloSet(newSet);
444
- }
445
- delete(item) {
446
- const newSet = new Set(this.set);
447
- newSet.delete(item);
448
- return new HoloSet(newSet);
449
- }
450
- addAll(items) {
451
- const newSet = new Set(this.set);
452
- for (const item of items) {
453
- newSet.add(item);
454
- }
455
- return new HoloSet(newSet);
456
- }
457
- union(other) {
458
- return this.addAll(other);
459
- }
460
- intersection(other) {
461
- const result = new Set();
462
- for (const item of this.set) {
463
- if (other.has(item)) {
464
- result.add(item);
465
- }
466
- }
467
- return new HoloSet(result);
468
- }
469
- difference(other) {
470
- const result = new Set();
471
- for (const item of this.set) {
472
- if (!other.has(item)) {
473
- result.add(item);
474
- }
475
- }
476
- return new HoloSet(result);
477
- }
478
- symmetricDifference(other) {
479
- return this.difference(other).union(other.difference(this));
480
- }
481
- isSubsetOf(other) {
482
- for (const item of this.set) {
483
- if (!other.has(item))
484
- return false;
485
- }
486
- return true;
487
- }
488
- isSupersetOf(other) {
489
- return other.isSubsetOf(this);
490
- }
491
- isDisjointFrom(other) {
492
- return this.intersection(other).isEmpty;
493
- }
494
- map(fn) {
495
- const result = new Set();
496
- for (const item of this.set) {
497
- result.add(fn(item));
498
- }
499
- return new HoloSet(result);
500
- }
501
- filter(predicate) {
502
- const result = new Set();
503
- for (const item of this.set) {
504
- if (predicate(item)) {
505
- result.add(item);
506
- }
507
- }
508
- return new HoloSet(result);
509
- }
510
- reduce(fn, initial) {
511
- let acc = initial;
512
- for (const item of this.set) {
513
- acc = fn(acc, item);
514
- }
515
- return acc;
516
- }
517
- forEach(fn) {
518
- this.set.forEach(fn);
519
- }
520
- find(predicate) {
521
- for (const item of this.set) {
522
- if (predicate(item))
523
- return item;
524
- }
525
- return undefined;
526
- }
527
- some(predicate) {
528
- for (const item of this.set) {
529
- if (predicate(item))
530
- return true;
531
- }
532
- return false;
533
- }
534
- every(predicate) {
535
- for (const item of this.set) {
536
- if (!predicate(item))
537
- return false;
538
- }
539
- return true;
540
- }
541
- toArray() {
542
- return [...this.set];
543
- }
544
- toList() {
545
- return new List(this.set);
546
- }
547
- toNativeSet() {
548
- return new Set(this.set);
549
- }
550
- [Symbol.iterator]() {
551
- return this.set[Symbol.iterator]();
552
- }
553
- toString() {
554
- return `HoloSet { ${[...this.set].join(', ')} }`;
555
- }
556
- }
557
- /**
558
- * Spatial grid for efficient spatial queries (useful for game worlds)
559
- */
560
- export class SpatialGrid {
561
- cellSize;
562
- cells = new Map();
563
- constructor(cellSize) {
564
- this.cellSize = cellSize;
565
- }
566
- getCellKey(x, y, z) {
567
- const cx = Math.floor(x / this.cellSize);
568
- const cy = Math.floor(y / this.cellSize);
569
- const cz = Math.floor(z / this.cellSize);
570
- return `${cx},${cy},${cz}`;
571
- }
572
- insert(position, item) {
573
- const key = this.getCellKey(position.x, position.y, position.z);
574
- if (!this.cells.has(key)) {
575
- this.cells.set(key, []);
576
- }
577
- this.cells.get(key).push(item);
578
- }
579
- remove(position, item) {
580
- const key = this.getCellKey(position.x, position.y, position.z);
581
- const cell = this.cells.get(key);
582
- if (!cell)
583
- return false;
584
- const index = cell.indexOf(item);
585
- if (index === -1)
586
- return false;
587
- cell.splice(index, 1);
588
- if (cell.length === 0) {
589
- this.cells.delete(key);
590
- }
591
- return true;
592
- }
593
- query(center, radius) {
594
- const results = [];
595
- const cellRadius = Math.ceil(radius / this.cellSize);
596
- const cx = Math.floor(center.x / this.cellSize);
597
- const cy = Math.floor(center.y / this.cellSize);
598
- const cz = Math.floor(center.z / this.cellSize);
599
- for (let x = cx - cellRadius; x <= cx + cellRadius; x++) {
600
- for (let y = cy - cellRadius; y <= cy + cellRadius; y++) {
601
- for (let z = cz - cellRadius; z <= cz + cellRadius; z++) {
602
- const cell = this.cells.get(`${x},${y},${z}`);
603
- if (cell) {
604
- results.push(...cell);
605
- }
606
- }
607
- }
608
- }
609
- return results;
610
- }
611
- queryBox(min, max) {
612
- const results = [];
613
- const minCx = Math.floor(min.x / this.cellSize);
614
- const minCy = Math.floor(min.y / this.cellSize);
615
- const minCz = Math.floor(min.z / this.cellSize);
616
- const maxCx = Math.floor(max.x / this.cellSize);
617
- const maxCy = Math.floor(max.y / this.cellSize);
618
- const maxCz = Math.floor(max.z / this.cellSize);
619
- for (let x = minCx; x <= maxCx; x++) {
620
- for (let y = minCy; y <= maxCy; y++) {
621
- for (let z = minCz; z <= maxCz; z++) {
622
- const cell = this.cells.get(`${x},${y},${z}`);
623
- if (cell) {
624
- results.push(...cell);
625
- }
626
- }
627
- }
628
- }
629
- return results;
630
- }
631
- clear() {
632
- this.cells.clear();
633
- }
634
- get cellCount() {
635
- return this.cells.size;
636
- }
637
- get itemCount() {
638
- let count = 0;
639
- for (const cell of this.cells.values()) {
640
- count += cell.length;
641
- }
642
- return count;
643
- }
644
- }
645
- /**
646
- * Priority queue (min-heap by default)
647
- */
648
- export class PriorityQueue {
649
- compareFn;
650
- heap = [];
651
- constructor(compareFn = (a, b) => a - b) {
652
- this.compareFn = compareFn;
653
- }
654
- static minHeap() {
655
- return new PriorityQueue((a, b) => a - b);
656
- }
657
- static maxHeap() {
658
- return new PriorityQueue((a, b) => b - a);
659
- }
660
- get size() {
661
- return this.heap.length;
662
- }
663
- get isEmpty() {
664
- return this.heap.length === 0;
665
- }
666
- enqueue(item, priority) {
667
- this.heap.push({ item, priority });
668
- this.bubbleUp(this.heap.length - 1);
669
- }
670
- dequeue() {
671
- if (this.isEmpty)
672
- return undefined;
673
- const result = this.heap[0].item;
674
- const last = this.heap.pop();
675
- if (this.heap.length > 0) {
676
- this.heap[0] = last;
677
- this.bubbleDown(0);
678
- }
679
- return result;
680
- }
681
- peek() {
682
- return this.heap[0]?.item;
683
- }
684
- peekPriority() {
685
- return this.heap[0]?.priority;
686
- }
687
- clear() {
688
- this.heap = [];
689
- }
690
- bubbleUp(index) {
691
- while (index > 0) {
692
- const parentIndex = Math.floor((index - 1) / 2);
693
- if (this.compareFn(this.heap[index].priority, this.heap[parentIndex].priority) >= 0)
694
- break;
695
- [this.heap[index], this.heap[parentIndex]] = [this.heap[parentIndex], this.heap[index]];
696
- index = parentIndex;
697
- }
698
- }
699
- bubbleDown(index) {
700
- while (true) {
701
- const leftChild = 2 * index + 1;
702
- const rightChild = 2 * index + 2;
703
- let smallest = index;
704
- if (leftChild < this.heap.length && this.compareFn(this.heap[leftChild].priority, this.heap[smallest].priority) < 0) {
705
- smallest = leftChild;
706
- }
707
- if (rightChild < this.heap.length && this.compareFn(this.heap[rightChild].priority, this.heap[smallest].priority) < 0) {
708
- smallest = rightChild;
709
- }
710
- if (smallest === index)
711
- break;
712
- [this.heap[index], this.heap[smallest]] = [this.heap[smallest], this.heap[index]];
713
- index = smallest;
714
- }
715
- }
716
- }
717
- // Convenience aliases
718
- export { HoloMap as Map };
719
- export { HoloSet as Set };
720
- //# sourceMappingURL=collections.js.map