@memlab/core 1.1.6 → 1.1.10

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 (120) hide show
  1. package/dist/__tests__/parser/HeapParser.test.d.ts +1 -1
  2. package/dist/__tests__/parser/HeapParser.test.js +3 -3
  3. package/dist/__tests__/parser/NodeHeap.test.d.ts +1 -1
  4. package/dist/__tests__/parser/NodeHeap.test.js +6 -6
  5. package/dist/__tests__/parser/StringNode.test.d.ts +1 -1
  6. package/dist/__tests__/parser/StringNode.test.js +2 -2
  7. package/dist/__tests__/parser/traverse/HeapNodeTraverse.test.d.ts +1 -1
  8. package/dist/__tests__/parser/traverse/HeapNodeTraverse.test.js +3 -3
  9. package/dist/__tests__/utils/utils.test.d.ts +1 -1
  10. package/dist/__tests__/utils/utils.test.js +1 -1
  11. package/dist/index.d.ts +4 -2
  12. package/dist/index.js +6 -3
  13. package/dist/lib/BaseOption.d.ts +1 -1
  14. package/dist/lib/BaseOption.js +1 -1
  15. package/dist/lib/BrowserInfo.d.ts +1 -1
  16. package/dist/lib/BrowserInfo.js +1 -1
  17. package/dist/lib/Config.d.ts +8 -2
  18. package/dist/lib/Config.js +23 -12
  19. package/dist/lib/Console.d.ts +1 -1
  20. package/dist/lib/Console.js +1 -1
  21. package/dist/lib/Constant.d.ts +1 -1
  22. package/dist/lib/Constant.js +1 -1
  23. package/dist/lib/FileManager.d.ts +1 -1
  24. package/dist/lib/FileManager.js +5 -3
  25. package/dist/lib/HeapAnalyzer.d.ts +9 -1
  26. package/dist/lib/HeapAnalyzer.js +51 -9
  27. package/dist/lib/HeapParser.d.ts +2 -2
  28. package/dist/lib/HeapParser.js +2 -2
  29. package/dist/lib/InternalValueSetter.d.ts +1 -1
  30. package/dist/lib/InternalValueSetter.js +1 -1
  31. package/dist/lib/NodeHeap.d.ts +35 -12
  32. package/dist/lib/NodeHeap.js +55 -24
  33. package/dist/lib/PackageInfoLoader.js +1 -1
  34. package/dist/lib/ProcessManager.d.ts +1 -1
  35. package/dist/lib/ProcessManager.js +1 -1
  36. package/dist/lib/Serializer.d.ts +1 -1
  37. package/dist/lib/Serializer.js +1 -1
  38. package/dist/lib/StringLoader.d.ts +2 -2
  39. package/dist/lib/StringLoader.js +2 -2
  40. package/dist/lib/Types.d.ts +51 -33
  41. package/dist/lib/Types.js +1 -1
  42. package/dist/lib/Utils.d.ts +3 -1
  43. package/dist/lib/Utils.js +71 -33
  44. package/dist/lib/heap-data/HeapEdge.d.ts +2 -2
  45. package/dist/lib/heap-data/HeapEdge.js +2 -2
  46. package/dist/lib/heap-data/HeapLocation.d.ts +2 -2
  47. package/dist/lib/heap-data/HeapLocation.js +2 -2
  48. package/dist/lib/heap-data/HeapNode.d.ts +3 -2
  49. package/dist/lib/heap-data/HeapNode.js +6 -2
  50. package/dist/lib/heap-data/HeapSnapshot.d.ts +3 -2
  51. package/dist/lib/heap-data/HeapSnapshot.js +6 -33
  52. package/dist/lib/heap-data/HeapStringNode.d.ts +2 -2
  53. package/dist/lib/heap-data/HeapStringNode.js +4 -2
  54. package/dist/lib/heap-data/HeapUtils.d.ts +2 -2
  55. package/dist/lib/heap-data/HeapUtils.js +2 -2
  56. package/dist/lib/heap-data/MemLabTagStore.d.ts +23 -0
  57. package/dist/lib/heap-data/MemLabTagStore.js +110 -0
  58. package/dist/lib/leak-filters/BaseLeakFilter.rule.d.ts +1 -1
  59. package/dist/lib/leak-filters/BaseLeakFilter.rule.js +1 -1
  60. package/dist/lib/leak-filters/LeakFilterRuleList.d.ts +1 -1
  61. package/dist/lib/leak-filters/LeakFilterRuleList.js +1 -1
  62. package/dist/lib/leak-filters/LeakObjectFilter.d.ts +1 -1
  63. package/dist/lib/leak-filters/LeakObjectFilter.js +1 -1
  64. package/dist/lib/leak-filters/rules/FilterByExternalFilter.rule.d.ts +1 -1
  65. package/dist/lib/leak-filters/rules/FilterByExternalFilter.rule.js +1 -1
  66. package/dist/lib/leak-filters/rules/FilterDetachedDOMElement.rule.d.ts +1 -1
  67. package/dist/lib/leak-filters/rules/FilterDetachedDOMElement.rule.js +1 -1
  68. package/dist/lib/leak-filters/rules/FilterHermesNode.rule.d.ts +1 -1
  69. package/dist/lib/leak-filters/rules/FilterHermesNode.rule.js +1 -1
  70. package/dist/lib/leak-filters/rules/FilterOverSizedNodeAsLeak.rule.d.ts +1 -1
  71. package/dist/lib/leak-filters/rules/FilterOverSizedNodeAsLeak.rule.js +1 -1
  72. package/dist/lib/leak-filters/rules/FilterStackTraceFrame.rule.d.ts +1 -1
  73. package/dist/lib/leak-filters/rules/FilterStackTraceFrame.rule.js +1 -1
  74. package/dist/lib/leak-filters/rules/FilterTrivialNode.rule.d.ts +1 -1
  75. package/dist/lib/leak-filters/rules/FilterTrivialNode.rule.js +1 -1
  76. package/dist/lib/leak-filters/rules/FilterUnmountedFiberNode.rule.d.ts +1 -1
  77. package/dist/lib/leak-filters/rules/FilterUnmountedFiberNode.rule.js +1 -1
  78. package/dist/logger/LeakClusterLogger.d.ts +1 -1
  79. package/dist/logger/LeakClusterLogger.js +1 -1
  80. package/dist/logger/LeakTraceDetailsLogger.d.ts +1 -1
  81. package/dist/logger/LeakTraceDetailsLogger.js +1 -1
  82. package/dist/modes/BaseMode.d.ts +1 -1
  83. package/dist/modes/BaseMode.js +1 -1
  84. package/dist/modes/InteractionTestMode.d.ts +1 -1
  85. package/dist/modes/InteractionTestMode.js +1 -1
  86. package/dist/modes/MeasureMode.d.ts +1 -1
  87. package/dist/modes/MeasureMode.js +1 -1
  88. package/dist/modes/RunningModes.d.ts +1 -1
  89. package/dist/modes/RunningModes.js +1 -1
  90. package/dist/paths/TraceFinder.d.ts +1 -1
  91. package/dist/paths/TraceFinder.js +58 -40
  92. package/dist/trace-cluster/ClusterUtils.d.ts +1 -1
  93. package/dist/trace-cluster/ClusterUtils.js +1 -1
  94. package/dist/trace-cluster/ClusterUtilsHelper.d.ts +1 -1
  95. package/dist/trace-cluster/ClusterUtilsHelper.js +1 -1
  96. package/dist/trace-cluster/ClusteringHeuristics.d.ts +1 -1
  97. package/dist/trace-cluster/ClusteringHeuristics.js +1 -1
  98. package/dist/trace-cluster/EvalutationMetric.d.ts +1 -1
  99. package/dist/trace-cluster/EvalutationMetric.js +1 -1
  100. package/dist/trace-cluster/SequentialClustering.d.ts +17 -0
  101. package/dist/trace-cluster/SequentialClustering.js +47 -0
  102. package/dist/trace-cluster/TraceBucket.d.ts +2 -1
  103. package/dist/trace-cluster/TraceBucket.js +11 -3
  104. package/dist/trace-cluster/TraceElement.d.ts +3 -1
  105. package/dist/trace-cluster/TraceElement.js +7 -1
  106. package/dist/trace-cluster/strategies/MLTraceSimilarityStrategy.d.ts +1 -1
  107. package/dist/trace-cluster/strategies/MLTraceSimilarityStrategy.js +2 -2
  108. package/dist/trace-cluster/strategies/TraceAsClusterStrategy.d.ts +1 -1
  109. package/dist/trace-cluster/strategies/TraceAsClusterStrategy.js +1 -1
  110. package/dist/trace-cluster/strategies/TraceSimilarityStrategy.d.ts +1 -1
  111. package/dist/trace-cluster/strategies/TraceSimilarityStrategy.js +1 -1
  112. package/dist/trace-cluster/strategies/machine-learning/DistanceMatrix.d.ts +1 -1
  113. package/dist/trace-cluster/strategies/machine-learning/DistanceMatrix.js +1 -1
  114. package/dist/trace-cluster/strategies/machine-learning/HAC.d.ts +2 -2
  115. package/dist/trace-cluster/strategies/machine-learning/HAC.js +5 -7
  116. package/dist/trace-cluster/strategies/machine-learning/Ngram.d.ts +1 -1
  117. package/dist/trace-cluster/strategies/machine-learning/Ngram.js +1 -1
  118. package/dist/trace-cluster/strategies/machine-learning/TfidfVectorizer.d.ts +1 -1
  119. package/dist/trace-cluster/strategies/machine-learning/TfidfVectorizer.js +7 -3
  120. package/package.json +1 -1
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  declare type ClusteredLeakTraces = Record<string, string>;
11
11
  declare const _default: {
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  ////////////////////////
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall ws_labs
9
+ */
10
+ import type { LeakTrace } from '../lib/Types';
11
+ export default class SequentialClustering {
12
+ private existingRepresentativeTraces;
13
+ private traceSimilarity;
14
+ constructor();
15
+ cluster(newLeakTraces: LeakTrace[]): LeakTrace[][];
16
+ }
17
+ //# sourceMappingURL=SequentialClustering.d.ts.map
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @format
9
+ * @oncall ws_labs
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ClusterUtils_1 = __importDefault(require("./ClusterUtils"));
16
+ const TraceSimilarityStrategy_1 = __importDefault(require("./strategies/TraceSimilarityStrategy"));
17
+ const MLTraceSimilarityStrategy_1 = __importDefault(require("./strategies/MLTraceSimilarityStrategy"));
18
+ const Config_1 = __importDefault(require("../lib/Config"));
19
+ class SequentialClustering {
20
+ constructor() {
21
+ this.existingRepresentativeTraces = [];
22
+ this.traceSimilarity = Config_1.default.isMLClustering
23
+ ? new MLTraceSimilarityStrategy_1.default()
24
+ : new TraceSimilarityStrategy_1.default();
25
+ }
26
+ cluster(newLeakTraces) {
27
+ const { allClusters: clusters } = this.traceSimilarity.diffTraces(newLeakTraces, []);
28
+ const representativeTracesToAdd = [];
29
+ // Second round of clustering and relabeling
30
+ outer: for (let i = 0; i < clusters.length; i++) {
31
+ const newRepTrace = clusters[i][0];
32
+ for (const exRepTrace of this.existingRepresentativeTraces) {
33
+ if (ClusterUtils_1.default.isSimilarTrace(exRepTrace, newRepTrace)) {
34
+ clusters[i].unshift(exRepTrace);
35
+ continue outer;
36
+ }
37
+ }
38
+ representativeTracesToAdd.push(newRepTrace);
39
+ }
40
+ this.existingRepresentativeTraces = [
41
+ ...this.existingRepresentativeTraces,
42
+ ...representativeTracesToAdd,
43
+ ];
44
+ return clusters;
45
+ }
46
+ }
47
+ exports.default = SequentialClustering;
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  import type { IHeapNode, IHeapSnapshot, LeakTrace, LeakTracePathItem, Optional, TraceCluster, TraceClusterDiff, IClusterStrategy } from '../lib/Types';
11
11
  import type { NormalizedTraceElement } from './TraceElement';
@@ -25,6 +25,7 @@ export default class NormalizedTrace {
25
25
  private static diffTraces;
26
26
  static diffClusters(newClusters: TraceCluster[], existingClusters: TraceCluster[]): TraceClusterDiff;
27
27
  static clusterLeakTraces(leakTraces: LeakTrace[]): Record<string, string>;
28
+ static clusteredLeakTracesToRecord(allClusters: LeakTrace[][]): Record<string, string>;
28
29
  static filterClusters(clusters: TraceCluster[]): TraceCluster[];
29
30
  static clusterPaths(paths: LeakTracePathItem[], snapshot: IHeapSnapshot, aggregateDominatorMetrics: AggregateNodeCb, option?: {
30
31
  strategy?: IClusterStrategy;
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -163,6 +163,9 @@ class NormalizedTrace {
163
163
  ? new MLTraceSimilarityStrategy_1.default()
164
164
  : undefined,
165
165
  });
166
+ return NormalizedTrace.clusteredLeakTracesToRecord(allClusters);
167
+ }
168
+ static clusteredLeakTracesToRecord(allClusters) {
166
169
  const lastNodeFromTrace = (trace) => trace[trace.length - 1];
167
170
  const labaledLeakTraces = allClusters.reduce((acc, bucket) => {
168
171
  const lastNodeFromFirstTrace = lastNodeFromTrace(bucket[0]);
@@ -208,12 +211,18 @@ class NormalizedTrace {
208
211
  const { allClusters } = NormalizedTrace.diffTraces(traces, [], option);
209
212
  // construct TraceCluster from clustering result
210
213
  let clusters = allClusters.map((traces) => {
214
+ const representativeTrace = traces[0];
211
215
  const cluster = {
212
- path: traceToPathMap.get(traces[0]),
216
+ path: traceToPathMap.get(representativeTrace),
213
217
  count: traces.length,
214
218
  snapshot,
215
219
  retainedSize: 0,
216
220
  };
221
+ // add representative object id if there is one
222
+ const lastNode = representativeTrace[representativeTrace.length - 1];
223
+ if ('id' in lastNode) {
224
+ cluster.id = lastNode.id;
225
+ }
217
226
  traces.forEach((trace) => {
218
227
  NormalizedTrace.addLeakedNodeToCluster(cluster, traceToPathMap.get(trace));
219
228
  });
@@ -222,7 +231,6 @@ class NormalizedTrace {
222
231
  });
223
232
  clusters = NormalizedTrace.filterClusters(clusters);
224
233
  clusters.sort((c1, c2) => { var _a, _b; return ((_a = c2.retainedSize) !== null && _a !== void 0 ? _a : 0) - ((_b = c1.retainedSize) !== null && _b !== void 0 ? _b : 0); });
225
- Console_1.default.midLevel(`MemLab found ${clusters.length} leak(s)`);
226
234
  return clusters;
227
235
  }
228
236
  static generateUnClassifiedClusters(paths, snapshot, aggregateDominatorMetrics) {
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  import type { EdgeIterationCallback, IHeapEdge, IHeapLocation, IHeapNode, IHeapSnapshot, IHeapStringNode, Nullable } from '../lib/Types';
11
11
  export declare class NodeRecord implements IHeapNode {
@@ -37,6 +37,8 @@ export declare class NodeRecord implements IHeapNode {
37
37
  findAnyReference(): Nullable<IHeapEdge>;
38
38
  findAnyReferrer(): Nullable<IHeapEdge>;
39
39
  findReferrers(): IHeapEdge[];
40
+ set hasPathEdge(f: boolean);
41
+ get hasPathEdge(): boolean;
40
42
  set pathEdge(r: IHeapEdge);
41
43
  get pathEdge(): IHeapEdge;
42
44
  set dominatorNode(r: IHeapNode);
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -79,6 +79,12 @@ class NodeRecord {
79
79
  findReferrers() {
80
80
  throw new Error('NodeRecord.findReferrers is not implemented');
81
81
  }
82
+ set hasPathEdge(f) {
83
+ throw new Error('NodeRecord.hasPathEdge cannot be assigned');
84
+ }
85
+ get hasPathEdge() {
86
+ throw new Error('NodeRecord.hasPathEdge cannot be read');
87
+ }
82
88
  set pathEdge(r) {
83
89
  throw new Error('NodeRecord.pathEdge cannot be assigned');
84
90
  }
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  import type { IClusterStrategy, LeakTrace, TraceDiff } from '../../lib/Types';
11
11
  export default class MLTraceSimilarityStrategy implements IClusterStrategy {
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -32,7 +32,7 @@ class MLTraceSimilarityStrategy {
32
32
  if (!map.has(repTrace)) {
33
33
  map.set(repTrace, [repTrace]);
34
34
  }
35
- // to please lint
35
+ // to please linter
36
36
  (_a = map.get(repTrace)) === null || _a === void 0 ? void 0 : _a.push(trace);
37
37
  }
38
38
  return {
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  import type { IClusterStrategy, LeakTrace, TraceDiff } from '../../lib/Types';
11
11
  export default class TraceAsClusterStrategy implements IClusterStrategy {
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  import type { IClusterStrategy, LeakTrace, TraceDiff } from '../../lib/Types';
11
11
  export default class TraceSimilarityStrategy implements IClusterStrategy {
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  export declare const distance: (tfidfs: Record<string, number>[]) => Float32Array;
11
11
  //# sourceMappingURL=DistanceMatrix.d.ts.map
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.distance = void 0;
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  /**
11
11
  *
@@ -13,5 +13,5 @@
13
13
  * @param {*} D condenced distance matrix
14
14
  * @returns labels - list of doc ids as clusters
15
15
  */
16
- export declare const cluster: (nDocs: number, condensedDistanceMatrix: Float32Array, maxDistanceThreshold: number) => number[];
16
+ export declare const cluster: (nDocs: number, condensedDistanceMatrix: Float32Array, maxDistanceThreshold: number) => number[] | Uint32Array;
17
17
  //# sourceMappingURL=HAC.d.ts.map
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.cluster = void 0;
@@ -18,13 +18,13 @@ const condensedIndex = (n, i, j) => {
18
18
  // (n - 1) + (n - 2) + ... + (n - i) + (j - i) - 1
19
19
  return n * i - (i * (i + 1)) / 2 + (j - i - 1);
20
20
  };
21
- const getRootLabel = (array, idx) => {
21
+ function getRootLabel(array, idx) {
22
22
  let rootIdx = idx;
23
23
  while (array[rootIdx] !== rootIdx) {
24
24
  rootIdx = array[rootIdx];
25
25
  }
26
26
  return rootIdx;
27
- };
27
+ }
28
28
  /**
29
29
  *
30
30
  * @param {*} nDocs number of docs
@@ -42,9 +42,7 @@ const cluster = (nDocs, condensedDistanceMatrix, maxDistanceThreshold) => {
42
42
  let traceBIdx = -1;
43
43
  let currentMin = Number.MAX_SAFE_INTEGER;
44
44
  let distanceBetweenTraces;
45
- const labels = Array(nDocs)
46
- .fill(0)
47
- .map((_, idx) => idx);
45
+ const labels = new Uint32Array(nDocs).map((_, idx) => idx);
48
46
  for (let k = 0; k < nDocs - 1; k++) {
49
47
  traceBIdx = -1;
50
48
  if (chainLength === 0) {
@@ -77,7 +75,7 @@ const cluster = (nDocs, condensedDistanceMatrix, maxDistanceThreshold) => {
77
75
  traceBIdx = i;
78
76
  }
79
77
  }
80
- // to make sure we found a two mutual traces whose distance is smallest.
78
+ // make sure that traceA and traceB are closest to each other
81
79
  if (chainLength > 1 &&
82
80
  traceBIdx !== -1 &&
83
81
  traceBIdx === clusterChain[chainLength - 2]) {
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  export declare function nGram(n: number, terms: string[]): string[];
11
11
  //# sourceMappingURL=Ngram.d.ts.map
@@ -5,8 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.nGram = void 0;
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+ws_labs
8
7
  * @format
8
+ * @oncall ws_labs
9
9
  */
10
10
  interface TfidfVectorizerProps {
11
11
  rawDocuments: string[];
@@ -5,22 +5,26 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
- * @emails oncall+ws_labs
9
8
  * @format
9
+ * @oncall ws_labs
10
10
  */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.TfidfVectorizer = void 0;
16
+ const Config_1 = __importDefault(require("../../../lib/Config"));
13
17
  const Ngram_1 = require("./Ngram");
14
18
  const SMOOTHING_KEY = '__smoothObjectKey';
15
19
  const VOCAB_IDX_FOR_DOC_WITH_HIGH_DF = '-1';
16
20
  class TfidfVectorizer {
17
- constructor({ rawDocuments, maxDF = 0.8 }) {
21
+ constructor({ rawDocuments, maxDF }) {
18
22
  this.rawDocuments = [];
19
23
  this.vocabulary = Object.create(null);
20
24
  this.documentFrequency = Object.create(null);
21
25
  this.documents = [];
22
26
  this.rawDocuments = rawDocuments;
23
- this.maxDF = maxDF;
27
+ this.maxDF = maxDF !== null && maxDF !== void 0 ? maxDF : Config_1.default.mlMaxDF;
24
28
  }
25
29
  computeTfidfs() {
26
30
  const tokenizedDocuments = this.rawDocuments.map(this.tokenize);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/core",
3
- "version": "1.1.6",
3
+ "version": "1.1.10",
4
4
  "license": "MIT",
5
5
  "description": "memlab core libraries",
6
6
  "author": "Liang Gong <lgong@fb.com>",