@fluidframework/core-utils 2.0.0-rc.5.0.1 → 2.1.0-274160

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-base.esm.legacy.json"
4
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YACnB,SAAS,CAAC,EAAE,SACX,SAAS,CAAC,EAAE,eACP,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KAI/D,OAUF,CAAC"}
1
+ {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YACnB,SAAS,CAAC,EAAE,SACX,SAAS,CAAC,EAAE,eACP,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KAI/D,OAYF,CAAC"}
package/dist/compare.js CHANGED
@@ -22,6 +22,8 @@ const compareArrays = (left, right, comparator = (leftItem, rightItem) => Object
22
22
  // 30% penalty vs. baseline for exported function [node 14 x64].
23
23
  return (left === right || // Trivial acceptance: 'left' and 'right' are the same instance
24
24
  (left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
25
+ // non null asserting the right array because we know the lengths are the same
26
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25
27
  left.every((leftItem, index) => comparator(leftItem, right[index], index))));
26
28
  };
27
29
  exports.compareArrays = compareArrays;
@@ -1 +1 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,aAAa,iBAiBxB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @alpha\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t): boolean => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index], index)))\n\t);\n};\n"]}
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,8EAA8E;YAC9E,oEAAoE;YACpE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAC7E,CAAC;AACH,CAAC,CAAC;AAnBW,QAAA,aAAa,iBAmBxB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @alpha\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t): boolean => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\t// non null asserting the right array because we know the lengths are the same\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index]!, index)))\n\t);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B;;OAEG;IACH,GAAG,EAAE,CAAC,CAAC;IAEP;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,MAAM,CAW5C,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,IAAI,CAAC,CAAC;IAOQ,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAN5C,OAAO,CAAC,CAAC,CAAiB;IAE1B;;;OAGG;gBACuB,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAI5C;;;;OAIG;IACI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS;IAIvC;;;;OAIG;IACI,GAAG,IAAI,CAAC,GAAG,SAAS;IAY3B;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAQ9B;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,C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CAAC,CAAC,GAAG,IAAI;IAcvC;;;;OAIG;IACI,KAAK,IAAI,MAAM;IAItB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,IAAI;CAWZ"}
package/dist/heap.js CHANGED
@@ -92,6 +92,8 @@ class Heap {
92
92
  this.L.splice(-1);
93
93
  // Update the swapped node assuming we didn't remove the end of the list
94
94
  if (position !== this.L.length) {
95
+ // Non null asserting here since its the removal node's previous position
96
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
95
97
  this.update(this.L[position]);
96
98
  }
97
99
  }
@@ -113,7 +115,8 @@ class Heap {
113
115
  }
114
116
  }
115
117
  isGreaterThanParent(k) {
116
- // eslint-disable-next-line no-bitwise
118
+ // TODO: Document why this non-null assert is safe
119
+ // eslint-disable-next-line no-bitwise, @typescript-eslint/no-non-null-assertion
117
120
  return k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;
118
121
  }
119
122
  fixdown(pos) {
@@ -122,9 +125,13 @@ class Heap {
122
125
  while (k << 1 <= this.count()) {
123
126
  // eslint-disable-next-line no-bitwise
124
127
  let j = k << 1;
128
+ // TODO: Document why this non-null assert is safe
129
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
130
  if (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {
126
131
  j++;
127
132
  }
133
+ // TODO: Document why this non-null assert is safe
134
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
128
135
  if (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {
129
136
  break;
130
137
  }
@@ -133,11 +140,15 @@ class Heap {
133
140
  }
134
141
  }
135
142
  swap(k, j) {
136
- const tmp = this.L[k];
137
- this.L[k] = this.L[j];
138
- this.L[k].position = k;
139
- this.L[j] = tmp;
140
- this.L[j].position = j;
143
+ // Non null asserting here since array is always filled and indices are within range
144
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
145
+ const resultNodeJ = this.L[k];
146
+ // Non null asserting here since this affects perf if we assert
147
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
148
+ const resultNodeK = (this.L[k] = this.L[j]);
149
+ resultNodeK.position = k;
150
+ this.L[j] = resultNodeJ;
151
+ resultNodeJ.position = j;
141
152
  }
142
153
  }
143
154
  exports.Heap = Heap;
package/dist/heap.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBH;;;GAGG;AACU,QAAA,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAWF;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAA0B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QAC3C,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,GAAG;QACT,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChB,oEAAoE;QACpE,OAAO,CAAE,CAAC,KAAK,CAAC;IAC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,CAAC,CAAC,CAAC;YAChB,CAAC,GAAG,CAAC,CAAC;QACP,CAAC;IACF,CAAC;IAEO,IAAI,CAAC,CAAS,EAAE,CAAS;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AAhID,oBAgIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @internal\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @internal\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @internal\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @internal\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tpublic constructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> | undefined {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T | undefined {\n\t\tif (this.L.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\tthis.update(this.L[position]);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\tconst tmp = this.L[k];\n\t\tthis.L[k] = this.L[j];\n\t\tthis.L[k].position = k;\n\t\tthis.L[j] = tmp;\n\t\tthis.L[j].position = j;\n\t}\n}\n"]}
1
+ {"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBH;;;GAGG;AACU,QAAA,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAWF;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAA0B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QAC3C,IAAI,CAAC,CAAC,GAA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and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @internal\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @internal\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @internal\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @internal\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tpublic constructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> | undefined {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T | undefined {\n\t\tif (this.L.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\t// Non null asserting here since its the removal node's previous position\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.update(this.L[position]!);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// TODO: Document why this non-null assert is safe\n\t\t// eslint-disable-next-line no-bitwise, @typescript-eslint/no-non-null-assertion\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1]!.value, this.L[k]!.value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\t// TODO: Document why this non-null assert is safe\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j]!.value, this.L[j + 1]!.value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\t// TODO: Document why this non-null assert is safe\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (this.comp.compare(this.L[k]!.value, this.L[j]!.value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\t// Non null asserting here since array is always filled and indices are within range\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resultNodeJ = this.L[k]!;\n\t\t// Non null asserting here since this affects perf if we assert\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resultNodeK = (this.L[k] = this.L[j]!);\n\t\tresultNodeK.position = k;\n\t\tthis.L[j] = resultNodeJ;\n\t\tresultNodeJ.position = j;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YACnB,SAAS,CAAC,EAAE,SACX,SAAS,CAAC,EAAE,eACP,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KAI/D,OAUF,CAAC"}
1
+ {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YACnB,SAAS,CAAC,EAAE,SACX,SAAS,CAAC,EAAE,eACP,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KAI/D,OAYF,CAAC"}
package/lib/compare.js CHANGED
@@ -19,6 +19,8 @@ export const compareArrays = (left, right, comparator = (leftItem, rightItem) =>
19
19
  // 30% penalty vs. baseline for exported function [node 14 x64].
20
20
  return (left === right || // Trivial acceptance: 'left' and 'right' are the same instance
21
21
  (left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
22
+ // non null asserting the right array because we know the lengths are the same
23
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
24
  left.every((leftItem, index) => comparator(leftItem, right[index], index))));
23
25
  };
24
26
  //# sourceMappingURL=compare.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @alpha\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t): boolean => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index], index)))\n\t);\n};\n"]}
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,8EAA8E;YAC9E,oEAAoE;YACpE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAC7E,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @alpha\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t): boolean => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\t// non null asserting the right array because we know the lengths are the same\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index]!, index)))\n\t);\n};\n"]}
package/lib/heap.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B;;OAEG;IACH,GAAG,EAAE,CAAC,CAAC;IAEP;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,MAAM,CAW5C,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAA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AI,EAAE,SAAS,CAAC,CAAC,CAAC;IAN5C,OAAO,CAAC,CAAC,CAAiB;IAE1B;;;OAGG;gBACuB,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAI5C;;;;OAIG;IACI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS;IAIvC;;;;OAIG;IACI,GAAG,IAAI,CAAC,GAAG,SAAS;IAY3B;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAQ9B;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IASvC;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAcvC;;;;OAIG;IACI,KAAK,IAAI,MAAM;IAItB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,IAAI;CAWZ"}
package/lib/heap.js CHANGED
@@ -89,6 +89,8 @@ export class Heap {
89
89
  this.L.splice(-1);
90
90
  // Update the swapped node assuming we didn't remove the end of the list
91
91
  if (position !== this.L.length) {
92
+ // Non null asserting here since its the removal node's previous position
93
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
94
  this.update(this.L[position]);
93
95
  }
94
96
  }
@@ -110,7 +112,8 @@ export class Heap {
110
112
  }
111
113
  }
112
114
  isGreaterThanParent(k) {
113
- // eslint-disable-next-line no-bitwise
115
+ // TODO: Document why this non-null assert is safe
116
+ // eslint-disable-next-line no-bitwise, @typescript-eslint/no-non-null-assertion
114
117
  return k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;
115
118
  }
116
119
  fixdown(pos) {
@@ -119,9 +122,13 @@ export class Heap {
119
122
  while (k << 1 <= this.count()) {
120
123
  // eslint-disable-next-line no-bitwise
121
124
  let j = k << 1;
125
+ // TODO: Document why this non-null assert is safe
126
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122
127
  if (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {
123
128
  j++;
124
129
  }
130
+ // TODO: Document why this non-null assert is safe
131
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
132
  if (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {
126
133
  break;
127
134
  }
@@ -130,11 +137,15 @@ export class Heap {
130
137
  }
131
138
  }
132
139
  swap(k, j) {
133
- const tmp = this.L[k];
134
- this.L[k] = this.L[j];
135
- this.L[k].position = k;
136
- this.L[j] = tmp;
137
- this.L[j].position = j;
140
+ // Non null asserting here since array is always filled and indices are within range
141
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
142
+ const resultNodeJ = this.L[k];
143
+ // Non null asserting here since this affects perf if we assert
144
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
145
+ const resultNodeK = (this.L[k] = this.L[j]);
146
+ resultNodeK.position = k;
147
+ this.L[j] = resultNodeJ;
148
+ resultNodeJ.position = j;
138
149
  }
139
150
  }
140
151
  //# sourceMappingURL=heap.js.map
package/lib/heap.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAWF;;;GAGG;AACH,MAAM,OAAO,IAAI;IAGhB;;;OAGG;IACH,YAA0B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QAC3C,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC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AG,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrF,CAAC,EAAE,CAAC;YACL,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9D,MAAM;YACP,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChB,CAAC,GAAG,CAAC,CAAC;QACP,CAAC;IACF,CAAC;IAEO,IAAI,CAAC,CAAS,EAAE,CAAS;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @internal\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @internal\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @internal\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @internal\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tpublic constructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> | undefined {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T | undefined {\n\t\tif (this.L.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\tthis.update(this.L[position]);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\tconst tmp = this.L[k];\n\t\tthis.L[k] = this.L[j];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,IAAI,CAAC,CAAS,EAAE,CAAS;QAChC,oFAAoF;QACpF,oEAAoE;QACpE,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;QAC/B,+DAA+D;QAC/D,oEAAoE;QACpE,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;QAC7C,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;QACxB,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC1B,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @internal\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @internal\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @internal\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @internal\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tpublic constructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> | undefined {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T | undefined {\n\t\tif (this.L.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\t// Non null asserting here since its the removal node's previous position\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.update(this.L[position]!);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// TODO: Document why this non-null assert is safe\n\t\t// eslint-disable-next-line no-bitwise, @typescript-eslint/no-non-null-assertion\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1]!.value, this.L[k]!.value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\t// TODO: Document why this non-null assert is safe\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j]!.value, this.L[j + 1]!.value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\t// TODO: Document why this non-null assert is safe\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (this.comp.compare(this.L[k]!.value, this.L[j]!.value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\t// Non null asserting here since array is always filled and indices are within range\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resultNodeJ = this.L[k]!;\n\t\t// Non null asserting here since this affects perf if we assert\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resultNodeK = (this.L[k] = this.L[j]!);\n\t\tresultNodeK.position = k;\n\t\tthis.L[j] = resultNodeJ;\n\t\tresultNodeJ.position = j;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/core-utils",
3
- "version": "2.0.0-rc.5.0.1",
3
+ "version": "2.1.0-274160",
4
4
  "description": "Not intended for use outside the Fluid client repo.",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,12 +69,12 @@
69
69
  "devDependencies": {
70
70
  "@arethetypeswrong/cli": "^0.15.2",
71
71
  "@biomejs/biome": "^1.7.3",
72
- "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
72
+ "@fluid-internal/mocha-test-setup": "2.1.0-274160",
73
73
  "@fluid-tools/benchmark": "^0.47.0",
74
74
  "@fluid-tools/build-cli": "^0.39.0",
75
75
  "@fluidframework/build-common": "^2.0.3",
76
76
  "@fluidframework/build-tools": "^0.39.0",
77
- "@fluidframework/core-utils-previous": "npm:@fluidframework/core-utils@2.0.0-rc.4.0.0",
77
+ "@fluidframework/core-utils-previous": "npm:@fluidframework/core-utils@2.0.0-rc.5.0.0",
78
78
  "@fluidframework/eslint-config-fluid": "^5.3.0",
79
79
  "@microsoft/api-extractor": "^7.45.1",
80
80
  "@types/mocha": "^9.1.1",
@@ -107,7 +107,9 @@
107
107
  "build": "fluid-build . --task build",
108
108
  "build:commonjs": "fluid-build . --task commonjs",
109
109
  "build:compile": "fluid-build . --task compile",
110
- "build:docs": "api-extractor run --local",
110
+ "build:docs": "concurrently \"npm:build:docs:*\"",
111
+ "build:docs:current": "api-extractor run --local",
112
+ "build:docs:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
111
113
  "build:esnext": "tsc --project ./tsconfig.json",
112
114
  "build:test": "npm run build:test:esm && npm run build:test:cjs",
113
115
  "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
@@ -122,7 +124,9 @@
122
124
  "check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
123
125
  "check:format": "npm run check:biome",
124
126
  "check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
125
- "ci:build:docs": "api-extractor run",
127
+ "ci:build:docs": "concurrently \"npm:ci:build:docs:*\"",
128
+ "ci:build:docs:current": "api-extractor run",
129
+ "ci:build:docs:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
126
130
  "clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
127
131
  "eslint": "eslint --format stylish src",
128
132
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
@@ -139,7 +143,7 @@
139
143
  "test:mocha:esm": "mocha --recursive \"lib/test/**/*.spec.*js\" --exit",
140
144
  "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
141
145
  "tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
142
- "typetests:gen": "flub generate typetests --dir . -v --publicFallback",
146
+ "typetests:gen": "flub generate typetests --dir . -v",
143
147
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
144
148
  }
145
149
  }
package/src/compare.ts CHANGED
@@ -28,6 +28,8 @@ export const compareArrays = <T>(
28
28
  return (
29
29
  left === right || // Trivial acceptance: 'left' and 'right' are the same instance
30
30
  (left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
31
- left.every((leftItem, index) => comparator(leftItem, right[index], index)))
31
+ // non null asserting the right array because we know the lengths are the same
32
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
+ left.every((leftItem, index) => comparator(leftItem, right[index]!, index)))
32
34
  );
33
35
  };
package/src/heap.ts CHANGED
@@ -127,7 +127,9 @@ export class Heap<T> {
127
127
 
128
128
  // Update the swapped node assuming we didn't remove the end of the list
129
129
  if (position !== this.L.length) {
130
- this.update(this.L[position]);
130
+ // Non null asserting here since its the removal node's previous position
131
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
132
+ this.update(this.L[position]!);
131
133
  }
132
134
  }
133
135
 
@@ -151,8 +153,9 @@ export class Heap<T> {
151
153
  }
152
154
 
153
155
  private isGreaterThanParent(k: number): boolean {
154
- // eslint-disable-next-line no-bitwise
155
- return k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;
156
+ // TODO: Document why this non-null assert is safe
157
+ // eslint-disable-next-line no-bitwise, @typescript-eslint/no-non-null-assertion
158
+ return k > 1 && this.comp.compare(this.L[k >> 1]!.value, this.L[k]!.value) > 0;
156
159
  }
157
160
 
158
161
  private fixdown(pos: number): void {
@@ -161,10 +164,14 @@ export class Heap<T> {
161
164
  while (k << 1 <= this.count()) {
162
165
  // eslint-disable-next-line no-bitwise
163
166
  let j = k << 1;
164
- if (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {
167
+ // TODO: Document why this non-null assert is safe
168
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
169
+ if (j < this.count() && this.comp.compare(this.L[j]!.value, this.L[j + 1]!.value) > 0) {
165
170
  j++;
166
171
  }
167
- if (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {
172
+ // TODO: Document why this non-null assert is safe
173
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
174
+ if (this.comp.compare(this.L[k]!.value, this.L[j]!.value) <= 0) {
168
175
  break;
169
176
  }
170
177
  this.swap(k, j);
@@ -173,10 +180,14 @@ export class Heap<T> {
173
180
  }
174
181
 
175
182
  private swap(k: number, j: number): void {
176
- const tmp = this.L[k];
177
- this.L[k] = this.L[j];
178
- this.L[k].position = k;
179
- this.L[j] = tmp;
180
- this.L[j].position = j;
183
+ // Non null asserting here since array is always filled and indices are within range
184
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
185
+ const resultNodeJ = this.L[k]!;
186
+ // Non null asserting here since this affects perf if we assert
187
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
188
+ const resultNodeK = (this.L[k] = this.L[j]!);
189
+ resultNodeK.position = k;
190
+ this.L[j] = resultNodeJ;
191
+ resultNodeJ.position = j;
181
192
  }
182
193
  }
package/tsconfig.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "compilerOptions": {
6
6
  "rootDir": "./src",
7
7
  "outDir": "./lib",
8
- "noUncheckedIndexedAccess": false,
9
8
  "exactOptionalPropertyTypes": false,
10
9
  },
11
10
  }