gitnexus 1.2.8 → 1.2.9

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 (38) hide show
  1. package/README.md +194 -186
  2. package/dist/cli/ai-context.js +71 -71
  3. package/dist/cli/analyze.js +1 -1
  4. package/dist/cli/setup.js +8 -1
  5. package/dist/cli/view.d.ts +13 -0
  6. package/dist/cli/view.js +59 -0
  7. package/dist/core/augmentation/engine.js +20 -20
  8. package/dist/core/embeddings/embedding-pipeline.js +26 -26
  9. package/dist/core/graph/html-graph-viewer.d.ts +15 -0
  10. package/dist/core/graph/html-graph-viewer.js +542 -0
  11. package/dist/core/graph/html-graph-viewer.test.d.ts +1 -0
  12. package/dist/core/graph/html-graph-viewer.test.js +67 -0
  13. package/dist/core/ingestion/cluster-enricher.js +16 -16
  14. package/dist/core/kuzu/kuzu-adapter.js +9 -9
  15. package/dist/core/kuzu/schema.js +256 -256
  16. package/dist/core/search/bm25-index.js +5 -5
  17. package/dist/core/search/hybrid-search.js +3 -3
  18. package/dist/core/wiki/graph-queries.js +52 -52
  19. package/dist/core/wiki/html-viewer.js +192 -192
  20. package/dist/core/wiki/prompts.js +82 -82
  21. package/dist/mcp/core/embedder.js +8 -4
  22. package/dist/mcp/local/local-backend.d.ts +6 -0
  23. package/dist/mcp/local/local-backend.js +224 -117
  24. package/dist/mcp/resources.js +42 -42
  25. package/dist/mcp/server.js +16 -16
  26. package/dist/mcp/tools.js +86 -77
  27. package/dist/server/api.d.ts +4 -2
  28. package/dist/server/api.js +253 -83
  29. package/hooks/claude/gitnexus-hook.cjs +135 -135
  30. package/hooks/claude/pre-tool-use.sh +78 -78
  31. package/hooks/claude/session-start.sh +42 -42
  32. package/package.json +82 -82
  33. package/skills/debugging.md +85 -85
  34. package/skills/exploring.md +75 -75
  35. package/skills/impact-analysis.md +94 -94
  36. package/skills/refactoring.md +113 -113
  37. package/vendor/leiden/index.cjs +355 -355
  38. package/vendor/leiden/utils.cjs +392 -392
@@ -1,392 +1,392 @@
1
- /**
2
- * Graphology Leiden Utils
3
- * ========================
4
- *
5
- * Miscellaneous utilities used by the Leiden algorithm.
6
- *
7
- * Vendored from: https://github.com/graphology/graphology/tree/master/src/communities-leiden
8
- * License: MIT
9
- */
10
- var SparseMap = require('mnemonist/sparse-map');
11
- var createRandom = require('pandemonium/random').createRandom;
12
-
13
- function addWeightToCommunity(map, community, weight) {
14
- var currentWeight = map.get(community);
15
-
16
- if (typeof currentWeight === 'undefined') currentWeight = 0;
17
-
18
- currentWeight += weight;
19
-
20
- map.set(community, currentWeight);
21
- }
22
-
23
- function UndirectedLeidenAddenda(index, options) {
24
- options = options || {};
25
-
26
- var rng = options.rng || Math.random;
27
- var randomness = 'randomness' in options ? options.randomness : 0.01;
28
-
29
- this.index = index;
30
- this.random = createRandom(rng);
31
- this.randomness = randomness;
32
- this.rng = rng;
33
-
34
- var NodesPointerArray = index.counts.constructor;
35
- var WeightsArray = index.weights.constructor;
36
-
37
- var order = index.C;
38
- this.resolution = index.resolution;
39
-
40
- // Used to group nodes by communities
41
- this.B = index.C;
42
- this.C = 0;
43
- this.communitiesOffsets = new NodesPointerArray(order);
44
- this.nodesSortedByCommunities = new NodesPointerArray(order);
45
- this.communitiesBounds = new NodesPointerArray(order + 1);
46
-
47
- // Used to merge nodes subsets
48
- this.communityWeights = new WeightsArray(order);
49
- this.degrees = new WeightsArray(order);
50
- this.nonSingleton = new Uint8Array(order);
51
- this.externalEdgeWeightPerCommunity = new WeightsArray(order);
52
- this.belongings = new NodesPointerArray(order);
53
- this.neighboringCommunities = new SparseMap(WeightsArray, order);
54
- this.cumulativeIncrement = new Float64Array(order);
55
- this.macroCommunities = null;
56
- }
57
-
58
- UndirectedLeidenAddenda.prototype.groupByCommunities = function () {
59
- var index = this.index;
60
-
61
- var n, i, c, b, o;
62
-
63
- n = 0;
64
- o = 0;
65
-
66
- for (i = 0; i < index.C; i++) {
67
- c = index.counts[i];
68
-
69
- if (c !== 0) {
70
- this.communitiesBounds[o++] = n;
71
- n += c;
72
- this.communitiesOffsets[i] = n;
73
- }
74
- }
75
-
76
- this.communitiesBounds[o] = n;
77
-
78
- o = 0;
79
-
80
- for (i = 0; i < index.C; i++) {
81
- b = index.belongings[i];
82
- o = --this.communitiesOffsets[b];
83
- this.nodesSortedByCommunities[o] = i;
84
- }
85
-
86
- this.B = index.C - index.U;
87
- this.C = index.C;
88
- };
89
-
90
- UndirectedLeidenAddenda.prototype.communities = function () {
91
- var communities = new Array(this.B);
92
-
93
- var i, j, community, start, stop;
94
-
95
- for (i = 0; i < this.B; i++) {
96
- start = this.communitiesBounds[i];
97
- stop = this.communitiesBounds[i + 1];
98
- community = [];
99
-
100
- for (j = start; j < stop; j++) {
101
- community.push(j);
102
- }
103
-
104
- communities[i] = community;
105
- }
106
-
107
- return communities;
108
- };
109
-
110
- UndirectedLeidenAddenda.prototype.mergeNodesSubset = function (start, stop) {
111
- var index = this.index;
112
- var currentMacroCommunity =
113
- index.belongings[this.nodesSortedByCommunities[start]];
114
- var neighboringCommunities = this.neighboringCommunities;
115
-
116
- var totalNodeWeight = 0;
117
-
118
- var i, j, w;
119
- var ei, el, et;
120
-
121
- // Initializing singletons
122
- for (j = start; j < stop; j++) {
123
- i = this.nodesSortedByCommunities[j];
124
-
125
- this.belongings[i] = i;
126
- this.nonSingleton[i] = 0;
127
- this.degrees[i] = 0;
128
- totalNodeWeight += index.loops[i] / 2;
129
-
130
- this.communityWeights[i] = index.loops[i];
131
- this.externalEdgeWeightPerCommunity[i] = 0;
132
-
133
- ei = index.starts[i];
134
- el = index.starts[i + 1];
135
-
136
- for (; ei < el; ei++) {
137
- et = index.neighborhood[ei];
138
- w = index.weights[ei];
139
-
140
- this.degrees[i] += w;
141
-
142
- if (index.belongings[et] !== currentMacroCommunity) continue;
143
-
144
- totalNodeWeight += w;
145
- this.externalEdgeWeightPerCommunity[i] += w;
146
- this.communityWeights[i] += w;
147
- }
148
- }
149
-
150
- var microDegrees = this.externalEdgeWeightPerCommunity.slice();
151
-
152
- var s, ri, ci;
153
- var order = stop - start;
154
-
155
- var degree,
156
- bestCommunity,
157
- qualityValueIncrement,
158
- maxQualityValueIncrement,
159
- totalTransformedQualityValueIncrement,
160
- targetCommunity,
161
- targetCommunityDegree,
162
- targetCommunityWeight;
163
-
164
- var r, lo, hi, mid, chosenCommunity;
165
-
166
- ri = this.random(start, stop - 1);
167
-
168
- for (s = start; s < stop; s++, ri++) {
169
- j = start + (ri % order);
170
-
171
- i = this.nodesSortedByCommunities[j];
172
-
173
- if (this.nonSingleton[i] === 1) {
174
- continue;
175
- }
176
-
177
- if (
178
- this.externalEdgeWeightPerCommunity[i] <
179
- this.communityWeights[i] *
180
- (totalNodeWeight / 2 - this.communityWeights[i]) *
181
- this.resolution
182
- ) {
183
- continue;
184
- }
185
-
186
- this.communityWeights[i] = 0;
187
- this.externalEdgeWeightPerCommunity[i] = 0;
188
-
189
- neighboringCommunities.clear();
190
- neighboringCommunities.set(i, 0);
191
-
192
- degree = 0;
193
-
194
- ei = index.starts[i];
195
- el = index.starts[i + 1];
196
-
197
- for (; ei < el; ei++) {
198
- et = index.neighborhood[ei];
199
-
200
- if (index.belongings[et] !== currentMacroCommunity) continue;
201
-
202
- w = index.weights[ei];
203
-
204
- degree += w;
205
-
206
- addWeightToCommunity(neighboringCommunities, this.belongings[et], w);
207
- }
208
-
209
- bestCommunity = i;
210
- maxQualityValueIncrement = 0;
211
- totalTransformedQualityValueIncrement = 0;
212
-
213
- for (ci = 0; ci < neighboringCommunities.size; ci++) {
214
- targetCommunity = neighboringCommunities.dense[ci];
215
- targetCommunityDegree = neighboringCommunities.vals[ci];
216
- targetCommunityWeight = this.communityWeights[targetCommunity];
217
-
218
- if (
219
- this.externalEdgeWeightPerCommunity[targetCommunity] >=
220
- targetCommunityWeight *
221
- (totalNodeWeight / 2 - targetCommunityWeight) *
222
- this.resolution
223
- ) {
224
- qualityValueIncrement =
225
- targetCommunityDegree -
226
- ((degree + index.loops[i]) *
227
- targetCommunityWeight *
228
- this.resolution) /
229
- totalNodeWeight;
230
-
231
- if (qualityValueIncrement > maxQualityValueIncrement) {
232
- bestCommunity = targetCommunity;
233
- maxQualityValueIncrement = qualityValueIncrement;
234
- }
235
-
236
- if (qualityValueIncrement >= 0)
237
- totalTransformedQualityValueIncrement += Math.exp(
238
- qualityValueIncrement / this.randomness
239
- );
240
- }
241
-
242
- this.cumulativeIncrement[ci] = totalTransformedQualityValueIncrement;
243
- }
244
-
245
- if (
246
- totalTransformedQualityValueIncrement < Number.MAX_VALUE &&
247
- totalTransformedQualityValueIncrement < Infinity
248
- ) {
249
- r = totalTransformedQualityValueIncrement * this.rng();
250
- lo = -1;
251
- hi = neighboringCommunities.size + 1;
252
-
253
- while (lo < hi - 1) {
254
- mid = (lo + hi) >>> 1;
255
-
256
- if (this.cumulativeIncrement[mid] >= r) hi = mid;
257
- else lo = mid;
258
- }
259
-
260
- chosenCommunity = neighboringCommunities.dense[hi];
261
- } else {
262
- chosenCommunity = bestCommunity;
263
- }
264
-
265
- this.communityWeights[chosenCommunity] += degree + index.loops[i];
266
-
267
- ei = index.starts[i];
268
- el = index.starts[i + 1];
269
-
270
- for (; ei < el; ei++) {
271
- et = index.neighborhood[ei];
272
-
273
- if (index.belongings[et] !== currentMacroCommunity) continue;
274
-
275
- targetCommunity = this.belongings[et];
276
-
277
- if (targetCommunity === chosenCommunity) {
278
- this.externalEdgeWeightPerCommunity[chosenCommunity] -=
279
- microDegrees[et];
280
- } else {
281
- this.externalEdgeWeightPerCommunity[chosenCommunity] +=
282
- microDegrees[et];
283
- }
284
- }
285
-
286
- if (chosenCommunity !== i) {
287
- this.belongings[i] = chosenCommunity;
288
- this.nonSingleton[chosenCommunity] = 1;
289
- this.C--;
290
- }
291
- }
292
-
293
- var microCommunities = this.neighboringCommunities;
294
- microCommunities.clear();
295
-
296
- for (j = start; j < stop; j++) {
297
- i = this.nodesSortedByCommunities[j];
298
- microCommunities.set(this.belongings[i], 1);
299
- }
300
-
301
- return microCommunities.dense.slice(0, microCommunities.size);
302
- };
303
-
304
- UndirectedLeidenAddenda.prototype.refinePartition = function () {
305
- this.groupByCommunities();
306
-
307
- this.macroCommunities = new Array(this.B);
308
-
309
- var i, start, stop, mapping;
310
-
311
- var bounds = this.communitiesBounds;
312
-
313
- for (i = 0; i < this.B; i++) {
314
- start = bounds[i];
315
- stop = bounds[i + 1];
316
-
317
- mapping = this.mergeNodesSubset(start, stop);
318
- this.macroCommunities[i] = mapping;
319
- }
320
- };
321
-
322
- UndirectedLeidenAddenda.prototype.split = function () {
323
- var index = this.index;
324
- var isolates = this.neighboringCommunities;
325
-
326
- isolates.clear();
327
-
328
- var i, community, isolated;
329
-
330
- for (i = 0; i < index.C; i++) {
331
- community = this.belongings[i];
332
-
333
- if (i !== community) continue;
334
-
335
- isolated = index.isolate(i, this.degrees[i]);
336
- isolates.set(community, isolated);
337
- }
338
-
339
- for (i = 0; i < index.C; i++) {
340
- community = this.belongings[i];
341
-
342
- if (i === community) continue;
343
-
344
- isolated = isolates.get(community);
345
- index.move(i, this.degrees[i], isolated);
346
- }
347
-
348
- var j, macro;
349
-
350
- for (i = 0; i < this.macroCommunities.length; i++) {
351
- macro = this.macroCommunities[i];
352
-
353
- for (j = 0; j < macro.length; j++) macro[j] = isolates.get(macro[j]);
354
- }
355
- };
356
-
357
- UndirectedLeidenAddenda.prototype.zoomOut = function () {
358
- var index = this.index;
359
- this.refinePartition();
360
- this.split();
361
-
362
- var newLabels = index.zoomOut();
363
-
364
- var macro, leader, follower;
365
-
366
- var i, j;
367
-
368
- for (i = 0; i < this.macroCommunities.length; i++) {
369
- macro = this.macroCommunities[i];
370
- leader = newLabels[macro[0]];
371
-
372
- for (j = 1; j < macro.length; j++) {
373
- follower = newLabels[macro[j]];
374
- index.expensiveMove(follower, leader);
375
- }
376
- }
377
- };
378
-
379
- UndirectedLeidenAddenda.prototype.onlySingletons = function () {
380
- var index = this.index;
381
-
382
- var i;
383
-
384
- for (i = 0; i < index.C; i++) {
385
- if (index.counts[i] > 1) return false;
386
- }
387
-
388
- return true;
389
- };
390
-
391
- exports.addWeightToCommunity = addWeightToCommunity;
392
- exports.UndirectedLeidenAddenda = UndirectedLeidenAddenda;
1
+ /**
2
+ * Graphology Leiden Utils
3
+ * ========================
4
+ *
5
+ * Miscellaneous utilities used by the Leiden algorithm.
6
+ *
7
+ * Vendored from: https://github.com/graphology/graphology/tree/master/src/communities-leiden
8
+ * License: MIT
9
+ */
10
+ var SparseMap = require('mnemonist/sparse-map');
11
+ var createRandom = require('pandemonium/random').createRandom;
12
+
13
+ function addWeightToCommunity(map, community, weight) {
14
+ var currentWeight = map.get(community);
15
+
16
+ if (typeof currentWeight === 'undefined') currentWeight = 0;
17
+
18
+ currentWeight += weight;
19
+
20
+ map.set(community, currentWeight);
21
+ }
22
+
23
+ function UndirectedLeidenAddenda(index, options) {
24
+ options = options || {};
25
+
26
+ var rng = options.rng || Math.random;
27
+ var randomness = 'randomness' in options ? options.randomness : 0.01;
28
+
29
+ this.index = index;
30
+ this.random = createRandom(rng);
31
+ this.randomness = randomness;
32
+ this.rng = rng;
33
+
34
+ var NodesPointerArray = index.counts.constructor;
35
+ var WeightsArray = index.weights.constructor;
36
+
37
+ var order = index.C;
38
+ this.resolution = index.resolution;
39
+
40
+ // Used to group nodes by communities
41
+ this.B = index.C;
42
+ this.C = 0;
43
+ this.communitiesOffsets = new NodesPointerArray(order);
44
+ this.nodesSortedByCommunities = new NodesPointerArray(order);
45
+ this.communitiesBounds = new NodesPointerArray(order + 1);
46
+
47
+ // Used to merge nodes subsets
48
+ this.communityWeights = new WeightsArray(order);
49
+ this.degrees = new WeightsArray(order);
50
+ this.nonSingleton = new Uint8Array(order);
51
+ this.externalEdgeWeightPerCommunity = new WeightsArray(order);
52
+ this.belongings = new NodesPointerArray(order);
53
+ this.neighboringCommunities = new SparseMap(WeightsArray, order);
54
+ this.cumulativeIncrement = new Float64Array(order);
55
+ this.macroCommunities = null;
56
+ }
57
+
58
+ UndirectedLeidenAddenda.prototype.groupByCommunities = function () {
59
+ var index = this.index;
60
+
61
+ var n, i, c, b, o;
62
+
63
+ n = 0;
64
+ o = 0;
65
+
66
+ for (i = 0; i < index.C; i++) {
67
+ c = index.counts[i];
68
+
69
+ if (c !== 0) {
70
+ this.communitiesBounds[o++] = n;
71
+ n += c;
72
+ this.communitiesOffsets[i] = n;
73
+ }
74
+ }
75
+
76
+ this.communitiesBounds[o] = n;
77
+
78
+ o = 0;
79
+
80
+ for (i = 0; i < index.C; i++) {
81
+ b = index.belongings[i];
82
+ o = --this.communitiesOffsets[b];
83
+ this.nodesSortedByCommunities[o] = i;
84
+ }
85
+
86
+ this.B = index.C - index.U;
87
+ this.C = index.C;
88
+ };
89
+
90
+ UndirectedLeidenAddenda.prototype.communities = function () {
91
+ var communities = new Array(this.B);
92
+
93
+ var i, j, community, start, stop;
94
+
95
+ for (i = 0; i < this.B; i++) {
96
+ start = this.communitiesBounds[i];
97
+ stop = this.communitiesBounds[i + 1];
98
+ community = [];
99
+
100
+ for (j = start; j < stop; j++) {
101
+ community.push(j);
102
+ }
103
+
104
+ communities[i] = community;
105
+ }
106
+
107
+ return communities;
108
+ };
109
+
110
+ UndirectedLeidenAddenda.prototype.mergeNodesSubset = function (start, stop) {
111
+ var index = this.index;
112
+ var currentMacroCommunity =
113
+ index.belongings[this.nodesSortedByCommunities[start]];
114
+ var neighboringCommunities = this.neighboringCommunities;
115
+
116
+ var totalNodeWeight = 0;
117
+
118
+ var i, j, w;
119
+ var ei, el, et;
120
+
121
+ // Initializing singletons
122
+ for (j = start; j < stop; j++) {
123
+ i = this.nodesSortedByCommunities[j];
124
+
125
+ this.belongings[i] = i;
126
+ this.nonSingleton[i] = 0;
127
+ this.degrees[i] = 0;
128
+ totalNodeWeight += index.loops[i] / 2;
129
+
130
+ this.communityWeights[i] = index.loops[i];
131
+ this.externalEdgeWeightPerCommunity[i] = 0;
132
+
133
+ ei = index.starts[i];
134
+ el = index.starts[i + 1];
135
+
136
+ for (; ei < el; ei++) {
137
+ et = index.neighborhood[ei];
138
+ w = index.weights[ei];
139
+
140
+ this.degrees[i] += w;
141
+
142
+ if (index.belongings[et] !== currentMacroCommunity) continue;
143
+
144
+ totalNodeWeight += w;
145
+ this.externalEdgeWeightPerCommunity[i] += w;
146
+ this.communityWeights[i] += w;
147
+ }
148
+ }
149
+
150
+ var microDegrees = this.externalEdgeWeightPerCommunity.slice();
151
+
152
+ var s, ri, ci;
153
+ var order = stop - start;
154
+
155
+ var degree,
156
+ bestCommunity,
157
+ qualityValueIncrement,
158
+ maxQualityValueIncrement,
159
+ totalTransformedQualityValueIncrement,
160
+ targetCommunity,
161
+ targetCommunityDegree,
162
+ targetCommunityWeight;
163
+
164
+ var r, lo, hi, mid, chosenCommunity;
165
+
166
+ ri = this.random(start, stop - 1);
167
+
168
+ for (s = start; s < stop; s++, ri++) {
169
+ j = start + (ri % order);
170
+
171
+ i = this.nodesSortedByCommunities[j];
172
+
173
+ if (this.nonSingleton[i] === 1) {
174
+ continue;
175
+ }
176
+
177
+ if (
178
+ this.externalEdgeWeightPerCommunity[i] <
179
+ this.communityWeights[i] *
180
+ (totalNodeWeight / 2 - this.communityWeights[i]) *
181
+ this.resolution
182
+ ) {
183
+ continue;
184
+ }
185
+
186
+ this.communityWeights[i] = 0;
187
+ this.externalEdgeWeightPerCommunity[i] = 0;
188
+
189
+ neighboringCommunities.clear();
190
+ neighboringCommunities.set(i, 0);
191
+
192
+ degree = 0;
193
+
194
+ ei = index.starts[i];
195
+ el = index.starts[i + 1];
196
+
197
+ for (; ei < el; ei++) {
198
+ et = index.neighborhood[ei];
199
+
200
+ if (index.belongings[et] !== currentMacroCommunity) continue;
201
+
202
+ w = index.weights[ei];
203
+
204
+ degree += w;
205
+
206
+ addWeightToCommunity(neighboringCommunities, this.belongings[et], w);
207
+ }
208
+
209
+ bestCommunity = i;
210
+ maxQualityValueIncrement = 0;
211
+ totalTransformedQualityValueIncrement = 0;
212
+
213
+ for (ci = 0; ci < neighboringCommunities.size; ci++) {
214
+ targetCommunity = neighboringCommunities.dense[ci];
215
+ targetCommunityDegree = neighboringCommunities.vals[ci];
216
+ targetCommunityWeight = this.communityWeights[targetCommunity];
217
+
218
+ if (
219
+ this.externalEdgeWeightPerCommunity[targetCommunity] >=
220
+ targetCommunityWeight *
221
+ (totalNodeWeight / 2 - targetCommunityWeight) *
222
+ this.resolution
223
+ ) {
224
+ qualityValueIncrement =
225
+ targetCommunityDegree -
226
+ ((degree + index.loops[i]) *
227
+ targetCommunityWeight *
228
+ this.resolution) /
229
+ totalNodeWeight;
230
+
231
+ if (qualityValueIncrement > maxQualityValueIncrement) {
232
+ bestCommunity = targetCommunity;
233
+ maxQualityValueIncrement = qualityValueIncrement;
234
+ }
235
+
236
+ if (qualityValueIncrement >= 0)
237
+ totalTransformedQualityValueIncrement += Math.exp(
238
+ qualityValueIncrement / this.randomness
239
+ );
240
+ }
241
+
242
+ this.cumulativeIncrement[ci] = totalTransformedQualityValueIncrement;
243
+ }
244
+
245
+ if (
246
+ totalTransformedQualityValueIncrement < Number.MAX_VALUE &&
247
+ totalTransformedQualityValueIncrement < Infinity
248
+ ) {
249
+ r = totalTransformedQualityValueIncrement * this.rng();
250
+ lo = -1;
251
+ hi = neighboringCommunities.size + 1;
252
+
253
+ while (lo < hi - 1) {
254
+ mid = (lo + hi) >>> 1;
255
+
256
+ if (this.cumulativeIncrement[mid] >= r) hi = mid;
257
+ else lo = mid;
258
+ }
259
+
260
+ chosenCommunity = neighboringCommunities.dense[hi];
261
+ } else {
262
+ chosenCommunity = bestCommunity;
263
+ }
264
+
265
+ this.communityWeights[chosenCommunity] += degree + index.loops[i];
266
+
267
+ ei = index.starts[i];
268
+ el = index.starts[i + 1];
269
+
270
+ for (; ei < el; ei++) {
271
+ et = index.neighborhood[ei];
272
+
273
+ if (index.belongings[et] !== currentMacroCommunity) continue;
274
+
275
+ targetCommunity = this.belongings[et];
276
+
277
+ if (targetCommunity === chosenCommunity) {
278
+ this.externalEdgeWeightPerCommunity[chosenCommunity] -=
279
+ microDegrees[et];
280
+ } else {
281
+ this.externalEdgeWeightPerCommunity[chosenCommunity] +=
282
+ microDegrees[et];
283
+ }
284
+ }
285
+
286
+ if (chosenCommunity !== i) {
287
+ this.belongings[i] = chosenCommunity;
288
+ this.nonSingleton[chosenCommunity] = 1;
289
+ this.C--;
290
+ }
291
+ }
292
+
293
+ var microCommunities = this.neighboringCommunities;
294
+ microCommunities.clear();
295
+
296
+ for (j = start; j < stop; j++) {
297
+ i = this.nodesSortedByCommunities[j];
298
+ microCommunities.set(this.belongings[i], 1);
299
+ }
300
+
301
+ return microCommunities.dense.slice(0, microCommunities.size);
302
+ };
303
+
304
+ UndirectedLeidenAddenda.prototype.refinePartition = function () {
305
+ this.groupByCommunities();
306
+
307
+ this.macroCommunities = new Array(this.B);
308
+
309
+ var i, start, stop, mapping;
310
+
311
+ var bounds = this.communitiesBounds;
312
+
313
+ for (i = 0; i < this.B; i++) {
314
+ start = bounds[i];
315
+ stop = bounds[i + 1];
316
+
317
+ mapping = this.mergeNodesSubset(start, stop);
318
+ this.macroCommunities[i] = mapping;
319
+ }
320
+ };
321
+
322
+ UndirectedLeidenAddenda.prototype.split = function () {
323
+ var index = this.index;
324
+ var isolates = this.neighboringCommunities;
325
+
326
+ isolates.clear();
327
+
328
+ var i, community, isolated;
329
+
330
+ for (i = 0; i < index.C; i++) {
331
+ community = this.belongings[i];
332
+
333
+ if (i !== community) continue;
334
+
335
+ isolated = index.isolate(i, this.degrees[i]);
336
+ isolates.set(community, isolated);
337
+ }
338
+
339
+ for (i = 0; i < index.C; i++) {
340
+ community = this.belongings[i];
341
+
342
+ if (i === community) continue;
343
+
344
+ isolated = isolates.get(community);
345
+ index.move(i, this.degrees[i], isolated);
346
+ }
347
+
348
+ var j, macro;
349
+
350
+ for (i = 0; i < this.macroCommunities.length; i++) {
351
+ macro = this.macroCommunities[i];
352
+
353
+ for (j = 0; j < macro.length; j++) macro[j] = isolates.get(macro[j]);
354
+ }
355
+ };
356
+
357
+ UndirectedLeidenAddenda.prototype.zoomOut = function () {
358
+ var index = this.index;
359
+ this.refinePartition();
360
+ this.split();
361
+
362
+ var newLabels = index.zoomOut();
363
+
364
+ var macro, leader, follower;
365
+
366
+ var i, j;
367
+
368
+ for (i = 0; i < this.macroCommunities.length; i++) {
369
+ macro = this.macroCommunities[i];
370
+ leader = newLabels[macro[0]];
371
+
372
+ for (j = 1; j < macro.length; j++) {
373
+ follower = newLabels[macro[j]];
374
+ index.expensiveMove(follower, leader);
375
+ }
376
+ }
377
+ };
378
+
379
+ UndirectedLeidenAddenda.prototype.onlySingletons = function () {
380
+ var index = this.index;
381
+
382
+ var i;
383
+
384
+ for (i = 0; i < index.C; i++) {
385
+ if (index.counts[i] > 1) return false;
386
+ }
387
+
388
+ return true;
389
+ };
390
+
391
+ exports.addWeightToCommunity = addWeightToCommunity;
392
+ exports.UndirectedLeidenAddenda = UndirectedLeidenAddenda;