@thi.ng/adjacency 2.5.56 → 3.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-07-19T14:56:20Z
3
+ - **Last updated**: 2024-07-22T13:15:57Z
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
+ # [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/adjacency@3.0.0) (2024-07-22)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - migrate/remove DisjointSet ([#486](https://github.com/thi-ng/umbrella/issues/486)) ([c4a9798](https://github.com/thi-ng/umbrella/commit/c4a9798))
17
+ - BREAKING CHANGE: migrate DisjointSet to [@thi.ng/disjoint-set](https://github.com/thi-ng/umbrella/tree/main/packages/disjoint-set) pkg
18
+ - remove obsolete files
19
+ - update pkg
20
+
12
21
  ### [2.5.48](https://github.com/thi-ng/umbrella/tree/@thi.ng/adjacency@2.5.48) (2024-04-20)
13
22
 
14
23
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 189 standalone projects, maintained as part
10
+ > This is one of 198 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
  >
@@ -31,6 +31,12 @@
31
31
 
32
32
  Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs.
33
33
 
34
+ > [!IMPORTANT]
35
+ > In July 2024 this package was restructured and split-up to extract some
36
+ > features into smaller more focused packages:
37
+ >
38
+ > - [@thi.ng/disjoint-set](https://thi.ng/disjoint-set)
39
+
34
40
  ### Graph implementations
35
41
 
36
42
  The following types all implement the [`IGraph`
@@ -84,7 +90,7 @@ For Node.js REPL:
84
90
  const adj = await import("@thi.ng/adjacency");
85
91
  ```
86
92
 
87
- Package sizes (brotli'd, pre-treeshake): ESM: 2.74 KB
93
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.53 KB
88
94
 
89
95
  ## Dependencies
90
96
 
@@ -92,9 +98,12 @@ Package sizes (brotli'd, pre-treeshake): ESM: 2.74 KB
92
98
  - [@thi.ng/arrays](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays)
93
99
  - [@thi.ng/bitfield](https://github.com/thi-ng/umbrella/tree/develop/packages/bitfield)
94
100
  - [@thi.ng/dcons](https://github.com/thi-ng/umbrella/tree/develop/packages/dcons)
101
+ - [@thi.ng/disjoint-set](https://github.com/thi-ng/umbrella/tree/develop/packages/disjoint-set)
95
102
  - [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
96
103
  - [@thi.ng/sparse](https://github.com/thi-ng/umbrella/tree/develop/packages/sparse)
97
104
 
105
+ Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
106
+
98
107
  ## Usage examples
99
108
 
100
109
  One project in this repo's
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./api.js";
2
2
  export * from "./binary.js";
3
- export * from "./disjoint-set.js";
4
3
  export * from "./floyd-warshall.js";
5
4
  export * from "./list.js";
6
5
  export * from "./sparse.js";
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./api.js";
2
2
  export * from "./binary.js";
3
- export * from "./disjoint-set.js";
4
3
  export * from "./floyd-warshall.js";
5
4
  export * from "./list.js";
6
5
  export * from "./sparse.js";
package/mst.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { sortByCachedKey } from "@thi.ng/arrays/sort-cached";
2
- import { DisjointSet } from "./disjoint-set.js";
2
+ import { DisjointSet } from "@thi.ng/disjoint-set";
3
3
  const mst = (edges, maxID, cost, verts) => {
4
4
  const graph = new DisjointSet(maxID + 1);
5
5
  const res = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/adjacency",
3
- "version": "2.5.56",
3
+ "version": "3.0.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",
@@ -39,16 +39,17 @@
39
39
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@thi.ng/api": "^8.11.6",
43
- "@thi.ng/arrays": "^2.9.11",
44
- "@thi.ng/bitfield": "^2.3.46",
45
- "@thi.ng/dcons": "^3.2.118",
46
- "@thi.ng/errors": "^2.5.12",
47
- "@thi.ng/sparse": "^0.3.123"
42
+ "@thi.ng/api": "^8.11.7",
43
+ "@thi.ng/arrays": "^2.9.13",
44
+ "@thi.ng/bitfield": "^2.3.47",
45
+ "@thi.ng/dcons": "^3.2.120",
46
+ "@thi.ng/disjoint-set": "^1.1.0",
47
+ "@thi.ng/errors": "^2.5.13",
48
+ "@thi.ng/sparse": "^0.3.125"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@microsoft/api-extractor": "^7.47.0",
51
- "@thi.ng/vectors": "^7.11.4",
52
+ "@thi.ng/vectors": "^7.11.6",
52
53
  "esbuild": "^0.23.0",
53
54
  "typedoc": "^0.26.3",
54
55
  "typescript": "^5.5.3"
@@ -103,9 +104,6 @@
103
104
  "./dfs": {
104
105
  "default": "./dfs.js"
105
106
  },
106
- "./disjoint-set": {
107
- "default": "./disjoint-set.js"
108
- },
109
107
  "./floyd-warshall": {
110
108
  "default": "./floyd-warshall.js"
111
109
  },
@@ -125,5 +123,5 @@
125
123
  ],
126
124
  "year": 2018
127
125
  },
128
- "gitHead": "c7aaa453b01a45e5235517db9d2a283b97abac96\n"
126
+ "gitHead": "bd22b0826134b79064169371665b4d6caa9b6066\n"
129
127
  }
package/disjoint-set.d.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * Typed array based Disjoint Set implementation with quick union and path
3
- * compression, after Sedgewick & Wayne.
4
- *
5
- * @remarks
6
- * - https://en.wikipedia.org/wiki/Disjoint-set_data_structure
7
- * - https://algs4.cs.princeton.edu/lectures/15UnionFind-2x2.pdf
8
- */
9
- export declare class DisjointSet {
10
- roots: Uint32Array;
11
- ranks: Uint8Array;
12
- count: number;
13
- /**
14
- * Creates new instance with `n` initial singular subsets.
15
- *
16
- * @param n - initial capacity, ID range [0..n)
17
- */
18
- constructor(n: number);
19
- /**
20
- * Returns canonical ID (tree root) for given `id`. Unless `id`
21
- * already is unified with some other ID, this will always return
22
- * `id` itself (since each node is initially its own root).
23
- *
24
- * @param id - node ID
25
- */
26
- canonical(id: number): number;
27
- /**
28
- * Connects combines the trees of the given two node IDs and returns
29
- * the new resulting canonical tree root ID.
30
- *
31
- * @param a - node ID
32
- * @param b - node ID
33
- */
34
- union(a: number, b: number): number;
35
- /**
36
- * Returns true, if the given two nodes belong to the same tree /
37
- * subset.
38
- *
39
- * @param a - node ID
40
- * @param b - node ID
41
- */
42
- unified(a: number, b: number): boolean;
43
- /**
44
- * Returns a `Map` of all subsets (connected components) with their
45
- * canonical tree root IDs as keys and arrays of node IDs as values.
46
- *
47
- * @remarks
48
- * If only the number of subsets is required, use the `count`
49
- * property of this class instance instead (O(1), updated with each
50
- * call to {@link DisjointSet.union}).
51
- */
52
- subsets(): Map<number, number[]>;
53
- }
54
- /**
55
- * Creates a new {@link DisjointSet} with capacity `n`.
56
- *
57
- * @param n -
58
- */
59
- export declare const defDisjointSet: (n: number) => DisjointSet;
60
- //# sourceMappingURL=disjoint-set.d.ts.map
package/disjoint-set.js DELETED
@@ -1,91 +0,0 @@
1
- import { fillRange } from "@thi.ng/arrays/fill-range";
2
- class DisjointSet {
3
- roots;
4
- ranks;
5
- count;
6
- /**
7
- * Creates new instance with `n` initial singular subsets.
8
- *
9
- * @param n - initial capacity, ID range [0..n)
10
- */
11
- constructor(n) {
12
- this.roots = fillRange(new Uint32Array(n));
13
- this.ranks = new Uint8Array(n);
14
- this.count = n;
15
- }
16
- /**
17
- * Returns canonical ID (tree root) for given `id`. Unless `id`
18
- * already is unified with some other ID, this will always return
19
- * `id` itself (since each node is initially its own root).
20
- *
21
- * @param id - node ID
22
- */
23
- canonical(id) {
24
- const roots = this.roots;
25
- while (id !== roots[id]) {
26
- id = roots[id] = roots[roots[id]];
27
- }
28
- return id;
29
- }
30
- /**
31
- * Connects combines the trees of the given two node IDs and returns
32
- * the new resulting canonical tree root ID.
33
- *
34
- * @param a - node ID
35
- * @param b - node ID
36
- */
37
- union(a, b) {
38
- const rootA = this.canonical(a);
39
- const rootB = this.canonical(b);
40
- if (rootA === rootB) {
41
- return rootA;
42
- }
43
- this.count--;
44
- const ranks = this.ranks;
45
- const ra = ranks[rootA];
46
- const rb = ranks[rootB];
47
- if (ra < rb) {
48
- return this.roots[rootA] = rootB;
49
- }
50
- ra === rb && ranks[rootA]++;
51
- return this.roots[rootB] = rootA;
52
- }
53
- /**
54
- * Returns true, if the given two nodes belong to the same tree /
55
- * subset.
56
- *
57
- * @param a - node ID
58
- * @param b - node ID
59
- */
60
- unified(a, b) {
61
- return this.canonical(a) === this.canonical(b);
62
- }
63
- /**
64
- * Returns a `Map` of all subsets (connected components) with their
65
- * canonical tree root IDs as keys and arrays of node IDs as values.
66
- *
67
- * @remarks
68
- * If only the number of subsets is required, use the `count`
69
- * property of this class instance instead (O(1), updated with each
70
- * call to {@link DisjointSet.union}).
71
- */
72
- subsets() {
73
- const sets = /* @__PURE__ */ new Map();
74
- const roots = this.roots;
75
- for (let i = roots.length; i-- > 0; ) {
76
- const id = this.canonical(i);
77
- const s = sets.get(id);
78
- if (s) {
79
- s.push(i);
80
- } else {
81
- sets.set(id, [i]);
82
- }
83
- }
84
- return sets;
85
- }
86
- }
87
- const defDisjointSet = (n) => new DisjointSet(n);
88
- export {
89
- DisjointSet,
90
- defDisjointSet
91
- };