@thi.ng/adjacency 2.3.36 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/README.md +4 -3
- package/api.d.ts +6 -0
- package/binary.d.ts +2 -0
- package/binary.js +17 -12
- package/list.d.ts +1 -0
- package/list.js +3 -0
- package/package.json +10 -7
- package/sparse.d.ts +1 -0
- package/sparse.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-10-19T08:38:06Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/adjacency@2.4.0) (2023-10-18)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add AdjacencyBitMatrix.similarity(), other updates ([259b507](https://github.com/thi-ng/umbrella/commit/259b507))
|
|
17
|
+
- add AdjacencyBitMatrix.similarity() to select related nodes (based on shared connections)
|
|
18
|
+
- simplify AdjacencyBitMatrix.neighbors()
|
|
19
|
+
- fix iteration bug in AdjacencyBitMatrix.edges()
|
|
20
|
+
|
|
12
21
|
## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/adjacency@2.3.0) (2022-12-22)
|
|
13
22
|
|
|
14
23
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ For Node.js REPL:
|
|
|
73
73
|
const adjacency = await import("@thi.ng/adjacency");
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 2.
|
|
76
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.57 KB
|
|
77
77
|
|
|
78
78
|
## Dependencies
|
|
79
79
|
|
|
@@ -104,14 +104,15 @@ TODO
|
|
|
104
104
|
|
|
105
105
|
## Authors
|
|
106
106
|
|
|
107
|
-
- [Karsten Schmidt](https://thi.ng)
|
|
107
|
+
- [Karsten Schmidt](https://thi.ng) (Main author)
|
|
108
|
+
- [Igor Loskutov](https://github.com/Firfi)
|
|
108
109
|
|
|
109
110
|
If this project contributes to an academic publication, please cite it as:
|
|
110
111
|
|
|
111
112
|
```bibtex
|
|
112
113
|
@misc{thing-adjacency,
|
|
113
114
|
title = "@thi.ng/adjacency",
|
|
114
|
-
author = "Karsten Schmidt",
|
|
115
|
+
author = "Karsten Schmidt and others",
|
|
115
116
|
note = "https://thi.ng/adjacency",
|
|
116
117
|
year = 2018
|
|
117
118
|
}
|
package/api.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export interface IGraph<T = number> {
|
|
|
38
38
|
* @param to -
|
|
39
39
|
*/
|
|
40
40
|
hasEdge(from: T, to: T): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if a vertex exists for the given id.
|
|
43
|
+
*
|
|
44
|
+
* @param id -
|
|
45
|
+
*/
|
|
46
|
+
hasVertex(id: T): boolean;
|
|
41
47
|
/**
|
|
42
48
|
* Returns number of edges for given vertex. By default only outgoing edges
|
|
43
49
|
* are counted, but can be customized via given {@link DegreeType}. Note: In
|
package/binary.d.ts
CHANGED
|
@@ -23,8 +23,10 @@ export declare class AdjacencyBitMatrix implements IGraph<number> {
|
|
|
23
23
|
addEdge(from: number, to: number): boolean;
|
|
24
24
|
removeEdge(from: number, to: number): boolean;
|
|
25
25
|
hasEdge(from: number, to: number): boolean;
|
|
26
|
+
hasVertex(id: number): boolean;
|
|
26
27
|
degree(id: number, type?: DegreeType): number;
|
|
27
28
|
neighbors(id: number): number[];
|
|
29
|
+
similarity(id: number, threshold?: number): number[][];
|
|
28
30
|
invert(): AdjacencyBitMatrix;
|
|
29
31
|
toString(): string;
|
|
30
32
|
toDot(ids?: string[]): string;
|
package/binary.js
CHANGED
|
@@ -15,7 +15,7 @@ export class AdjacencyBitMatrix {
|
|
|
15
15
|
}
|
|
16
16
|
*edges() {
|
|
17
17
|
const directed = !this.undirected;
|
|
18
|
-
for (let i = this.mat.
|
|
18
|
+
for (let i = this.mat.m; i-- > 0;) {
|
|
19
19
|
for (let n of this.neighbors(i)) {
|
|
20
20
|
if (directed || n > i) {
|
|
21
21
|
yield [i, n];
|
|
@@ -57,6 +57,9 @@ export class AdjacencyBitMatrix {
|
|
|
57
57
|
hasEdge(from, to) {
|
|
58
58
|
return this.mat.at(from, to) !== 0;
|
|
59
59
|
}
|
|
60
|
+
hasVertex(id) {
|
|
61
|
+
return (this.mat.popCountRow(id) !== 0 || this.mat.popCountColumn(id) !== 0);
|
|
62
|
+
}
|
|
60
63
|
degree(id, type = "out") {
|
|
61
64
|
let degree = 0;
|
|
62
65
|
if (this.undirected || type !== "in")
|
|
@@ -66,18 +69,20 @@ export class AdjacencyBitMatrix {
|
|
|
66
69
|
return degree;
|
|
67
70
|
}
|
|
68
71
|
neighbors(id) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
return [...this.mat.row(id, true).positions()];
|
|
73
|
+
}
|
|
74
|
+
similarity(id, threshold = 0) {
|
|
75
|
+
const mat = this.mat;
|
|
76
|
+
const query = mat.row(id, true);
|
|
77
|
+
const acc = [];
|
|
78
|
+
for (let i = 0, m = mat.m; i < m; i++) {
|
|
79
|
+
if (i === id)
|
|
80
|
+
continue;
|
|
81
|
+
const sim = query.similarity(mat.row(i, true));
|
|
82
|
+
if (sim >= threshold)
|
|
83
|
+
acc.push([i, sim]);
|
|
79
84
|
}
|
|
80
|
-
return
|
|
85
|
+
return acc.sort((a, b) => b[1] - a[1]);
|
|
81
86
|
}
|
|
82
87
|
invert() {
|
|
83
88
|
return __invert(new AdjacencyBitMatrix(this.mat.n, undefined, this.undirected), this.edges());
|
package/list.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class AdjacencyList implements IGraph<number> {
|
|
|
12
12
|
edges(): Generator<Edge, void, unknown>;
|
|
13
13
|
addVertex(id: number): void;
|
|
14
14
|
removeVertex(id: number): boolean;
|
|
15
|
+
hasVertex(id: number): boolean;
|
|
15
16
|
addEdge(from: number, to: number): boolean;
|
|
16
17
|
removeEdge(from: number, to: number): boolean;
|
|
17
18
|
hasEdge(from: number, to: number): boolean;
|
package/list.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/adjacency",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
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",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
|
+
"contributors": [
|
|
26
|
+
"Igor Loskutov (https://github.com/Firfi)"
|
|
27
|
+
],
|
|
25
28
|
"license": "Apache-2.0",
|
|
26
29
|
"scripts": {
|
|
27
30
|
"build": "yarn clean && tsc --declaration",
|
|
@@ -35,16 +38,16 @@
|
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
40
|
"@thi.ng/api": "^8.9.5",
|
|
38
|
-
"@thi.ng/arrays": "^2.6.
|
|
39
|
-
"@thi.ng/bitfield": "^2.
|
|
40
|
-
"@thi.ng/dcons": "^3.2.
|
|
41
|
+
"@thi.ng/arrays": "^2.6.3",
|
|
42
|
+
"@thi.ng/bitfield": "^2.3.0",
|
|
43
|
+
"@thi.ng/dcons": "^3.2.64",
|
|
41
44
|
"@thi.ng/errors": "^2.3.5",
|
|
42
|
-
"@thi.ng/sparse": "^0.3.
|
|
45
|
+
"@thi.ng/sparse": "^0.3.69"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@microsoft/api-extractor": "^7.36.4",
|
|
46
49
|
"@thi.ng/testament": "^0.3.23",
|
|
47
|
-
"@thi.ng/vectors": "^7.7.
|
|
50
|
+
"@thi.ng/vectors": "^7.7.19",
|
|
48
51
|
"rimraf": "^5.0.1",
|
|
49
52
|
"tools": "^0.0.1",
|
|
50
53
|
"typedoc": "^0.25.0",
|
|
@@ -122,5 +125,5 @@
|
|
|
122
125
|
],
|
|
123
126
|
"year": 2018
|
|
124
127
|
},
|
|
125
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "ae301a8a5f13f518dec04a975479c6e779a8ca9e\n"
|
|
126
129
|
}
|
package/sparse.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class AdjacencyMatrix extends CSR implements IGraph<number> {
|
|
|
7
7
|
addEdge(from: number, to: number): boolean;
|
|
8
8
|
removeEdge(from: number, to: number): boolean;
|
|
9
9
|
hasEdge(from: number, to: number): boolean;
|
|
10
|
+
hasVertex(id: number): boolean;
|
|
10
11
|
numEdges(): number;
|
|
11
12
|
numVertices(): number;
|
|
12
13
|
degree(id: number, type?: DegreeType): number;
|
package/sparse.js
CHANGED