@thi.ng/adjacency 2.3.36 → 2.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-08-27T11:20:58Z
3
+ - **Last updated**: 2023-10-18T18:06:31Z
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.55 KB
76
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.54 KB
77
77
 
78
78
  ## Dependencies
79
79
 
package/binary.d.ts CHANGED
@@ -25,6 +25,7 @@ export declare class AdjacencyBitMatrix implements IGraph<number> {
25
25
  hasEdge(from: number, to: number): boolean;
26
26
  degree(id: number, type?: DegreeType): number;
27
27
  neighbors(id: number): number[];
28
+ similarity(id: number, threshold?: number): number[][];
28
29
  invert(): AdjacencyBitMatrix;
29
30
  toString(): string;
30
31
  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.n; i-- > 0;) {
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];
@@ -66,18 +66,20 @@ export class AdjacencyBitMatrix {
66
66
  return degree;
67
67
  }
68
68
  neighbors(id) {
69
- const res = [];
70
- const { data, stride } = this.mat;
71
- id *= stride;
72
- for (let i = this.mat.n - 1, j = id + stride - 1; i >= 0; i -= 8, j--) {
73
- const v = data[j];
74
- if (v !== 0) {
75
- for (let k = 31 - Math.clz32(v); k >= 0; k--) {
76
- (v & (1 << k)) !== 0 && res.push(i - k);
77
- }
78
- }
69
+ return [...this.mat.row(id, true).positions()];
70
+ }
71
+ similarity(id, threshold = 0) {
72
+ const mat = this.mat;
73
+ const query = mat.row(id, true);
74
+ const acc = [];
75
+ for (let i = 0, m = mat.m; i < m; i++) {
76
+ if (i === id)
77
+ continue;
78
+ const sim = query.similarity(mat.row(i, true));
79
+ if (sim >= threshold)
80
+ acc.push([i, sim]);
79
81
  }
80
- return res;
82
+ return acc.sort((a, b) => b[1] - a[1]);
81
83
  }
82
84
  invert() {
83
85
  return __invert(new AdjacencyBitMatrix(this.mat.n, undefined, this.undirected), this.edges());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/adjacency",
3
- "version": "2.3.36",
3
+ "version": "2.4.0",
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",
@@ -35,16 +35,16 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@thi.ng/api": "^8.9.5",
38
- "@thi.ng/arrays": "^2.6.2",
39
- "@thi.ng/bitfield": "^2.2.38",
40
- "@thi.ng/dcons": "^3.2.63",
38
+ "@thi.ng/arrays": "^2.6.3",
39
+ "@thi.ng/bitfield": "^2.3.0",
40
+ "@thi.ng/dcons": "^3.2.64",
41
41
  "@thi.ng/errors": "^2.3.5",
42
- "@thi.ng/sparse": "^0.3.68"
42
+ "@thi.ng/sparse": "^0.3.69"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.36.4",
46
46
  "@thi.ng/testament": "^0.3.23",
47
- "@thi.ng/vectors": "^7.7.18",
47
+ "@thi.ng/vectors": "^7.7.19",
48
48
  "rimraf": "^5.0.1",
49
49
  "tools": "^0.0.1",
50
50
  "typedoc": "^0.25.0",
@@ -122,5 +122,5 @@
122
122
  ],
123
123
  "year": 2018
124
124
  },
125
- "gitHead": "d492ecb41df758db372a76449ea9b5bad47b25c4\n"
125
+ "gitHead": "46e445c09f2909d1aeaa9fdc8d8b3aa61c114db2\n"
126
126
  }