@thi.ng/adjacency 2.5.50 → 2.5.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/bfs.js +1 -2
- package/binary.js +2 -4
- package/dfs.js +1 -2
- package/floyd-warshall.js +1 -2
- package/list.js +11 -22
- package/package.json +14 -14
- package/sparse.js +2 -4
- package/utils.d.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
package/bfs.js
CHANGED
package/binary.js
CHANGED
|
@@ -73,11 +73,9 @@ class AdjacencyBitMatrix {
|
|
|
73
73
|
const query = mat.row(id, true);
|
|
74
74
|
const acc = [];
|
|
75
75
|
for (let i = 0, m = mat.m; i < m; i++) {
|
|
76
|
-
if (i === id)
|
|
77
|
-
continue;
|
|
76
|
+
if (i === id) continue;
|
|
78
77
|
const sim = query.similarity(mat.row(i, true));
|
|
79
|
-
if (sim >= threshold)
|
|
80
|
-
acc.push([i, sim]);
|
|
78
|
+
if (sim >= threshold) acc.push([i, sim]);
|
|
81
79
|
}
|
|
82
80
|
return acc.sort((a, b) => b[1] - a[1]);
|
|
83
81
|
}
|
package/dfs.js
CHANGED
package/floyd-warshall.js
CHANGED
package/list.js
CHANGED
|
@@ -16,18 +16,15 @@ class AdjacencyList {
|
|
|
16
16
|
*vertices() {
|
|
17
17
|
const { adjacency } = this;
|
|
18
18
|
for (let i = 0, n = adjacency.length; i < n; i++) {
|
|
19
|
-
if (adjacency[i])
|
|
20
|
-
yield i;
|
|
19
|
+
if (adjacency[i]) yield i;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
*edges() {
|
|
24
23
|
const { adjacency } = this;
|
|
25
24
|
for (let i = 0, n = adjacency.length; i < n; i++) {
|
|
26
25
|
const vertex = adjacency[i];
|
|
27
|
-
if (!vertex)
|
|
28
|
-
|
|
29
|
-
for (let j of vertex)
|
|
30
|
-
yield [i, j];
|
|
26
|
+
if (!vertex) continue;
|
|
27
|
+
for (let j of vertex) yield [i, j];
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
addVertex(id) {
|
|
@@ -36,8 +33,7 @@ class AdjacencyList {
|
|
|
36
33
|
removeVertex(id) {
|
|
37
34
|
const { adjacency, indegree } = this;
|
|
38
35
|
const vertex = adjacency[id];
|
|
39
|
-
if (!vertex)
|
|
40
|
-
return false;
|
|
36
|
+
if (!vertex) return false;
|
|
41
37
|
while (vertex.length) {
|
|
42
38
|
indegree[vertex.pop()]--;
|
|
43
39
|
this.numE--;
|
|
@@ -45,10 +41,8 @@ class AdjacencyList {
|
|
|
45
41
|
delete adjacency[id];
|
|
46
42
|
for (let i = 0, n = adjacency.length; i < n && indegree[id] > 0; i++) {
|
|
47
43
|
const vertex2 = adjacency[i];
|
|
48
|
-
if (!vertex2)
|
|
49
|
-
|
|
50
|
-
while (vertex2.includes(id))
|
|
51
|
-
this.removeEdge(i, id);
|
|
44
|
+
if (!vertex2) continue;
|
|
45
|
+
while (vertex2.includes(id)) this.removeEdge(i, id);
|
|
52
46
|
}
|
|
53
47
|
this.numV--;
|
|
54
48
|
return true;
|
|
@@ -85,10 +79,8 @@ class AdjacencyList {
|
|
|
85
79
|
let degree = 0;
|
|
86
80
|
const vertex = this.adjacency[id];
|
|
87
81
|
if (vertex) {
|
|
88
|
-
if (type !== "in")
|
|
89
|
-
|
|
90
|
-
if (type !== "out")
|
|
91
|
-
degree += this.indegree[id];
|
|
82
|
+
if (type !== "in") degree += vertex.length;
|
|
83
|
+
if (type !== "out") degree += this.indegree[id];
|
|
92
84
|
}
|
|
93
85
|
return degree;
|
|
94
86
|
}
|
|
@@ -115,8 +107,7 @@ class AdjacencyList {
|
|
|
115
107
|
}
|
|
116
108
|
ensureVertexData(id) {
|
|
117
109
|
const vertex = this.adjacency[id];
|
|
118
|
-
if (vertex)
|
|
119
|
-
return vertex;
|
|
110
|
+
if (vertex) return vertex;
|
|
120
111
|
this.numV++;
|
|
121
112
|
this.indegree[id] = 0;
|
|
122
113
|
return this.adjacency[id] = [];
|
|
@@ -127,10 +118,8 @@ const adjListFromAdjacency = (src) => {
|
|
|
127
118
|
const res = new AdjacencyList();
|
|
128
119
|
for (let i = 0, n = src.length; i < n; i++) {
|
|
129
120
|
const v = src[i];
|
|
130
|
-
if (!v)
|
|
131
|
-
|
|
132
|
-
for (let w of v)
|
|
133
|
-
res.addEdge(i, w);
|
|
121
|
+
if (!v) continue;
|
|
122
|
+
for (let w of v) res.addEdge(i, w);
|
|
134
123
|
}
|
|
135
124
|
return res;
|
|
136
125
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/adjacency",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.52",
|
|
4
4
|
"description": "Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/adjacency",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
43
|
-
"@thi.ng/arrays": "^2.9.
|
|
44
|
-
"@thi.ng/bitfield": "^2.3.
|
|
45
|
-
"@thi.ng/dcons": "^3.2.
|
|
46
|
-
"@thi.ng/errors": "^2.5.
|
|
47
|
-
"@thi.ng/sparse": "^0.3.
|
|
42
|
+
"@thi.ng/api": "^8.11.3",
|
|
43
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
44
|
+
"@thi.ng/bitfield": "^2.3.42",
|
|
45
|
+
"@thi.ng/dcons": "^3.2.114",
|
|
46
|
+
"@thi.ng/errors": "^2.5.8",
|
|
47
|
+
"@thi.ng/sparse": "^0.3.119"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@microsoft/api-extractor": "^7.
|
|
51
|
-
"@thi.ng/vectors": "^7.
|
|
52
|
-
"esbuild": "^0.
|
|
53
|
-
"typedoc": "^0.25.
|
|
54
|
-
"typescript": "^5.
|
|
50
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
51
|
+
"@thi.ng/vectors": "^7.11.0",
|
|
52
|
+
"esbuild": "^0.21.5",
|
|
53
|
+
"typedoc": "^0.25.13",
|
|
54
|
+
"typescript": "^5.5.2"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"adjacency",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
],
|
|
126
126
|
"year": 2018
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
129
129
|
}
|
package/sparse.js
CHANGED
|
@@ -52,10 +52,8 @@ class AdjacencyMatrix extends CSR {
|
|
|
52
52
|
degree(id, type = "out") {
|
|
53
53
|
let degree = 0;
|
|
54
54
|
ensureIndex2(id, id, this.m, this.n);
|
|
55
|
-
if (this.undirected || type !== "in")
|
|
56
|
-
|
|
57
|
-
if (!this.undirected && type !== "out")
|
|
58
|
-
degree += this.nnzCol(id);
|
|
55
|
+
if (this.undirected || type !== "in") degree += this.nnzRow(id);
|
|
56
|
+
if (!this.undirected && type !== "out") degree += this.nnzCol(id);
|
|
59
57
|
return degree;
|
|
60
58
|
}
|
|
61
59
|
neighbors(id) {
|
package/utils.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export declare const __toDot: (edges: Iterable<Pair<number, number>>, undirected
|
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare const __into: (graph: IGraph, edges: Iterable<Edge>) => void;
|
|
7
7
|
/** @internal */
|
|
8
|
-
export declare const __invert: <T extends IGraph
|
|
8
|
+
export declare const __invert: <T extends IGraph>(graph: T, edges: Iterable<Edge>) => T;
|
|
9
9
|
//# sourceMappingURL=utils.d.ts.map
|