typescript-ds-lib 0.4.0 → 0.4.5

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 (39) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -5
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +5 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/binary-search-tree.js +2 -2
  7. package/dist/lib/binary-search-tree.js.map +1 -1
  8. package/dist/lib/deque.js.map +1 -1
  9. package/dist/lib/graph/base.d.ts +167 -0
  10. package/dist/lib/graph/base.js +233 -0
  11. package/dist/lib/graph/base.js.map +1 -0
  12. package/dist/lib/graph/linked-list-graph.d.ts +18 -0
  13. package/dist/lib/graph/linked-list-graph.js +71 -0
  14. package/dist/lib/graph/linked-list-graph.js.map +1 -0
  15. package/dist/lib/graph/matrix-graph.d.ts +18 -0
  16. package/dist/lib/graph/matrix-graph.js +102 -0
  17. package/dist/lib/graph/matrix-graph.js.map +1 -0
  18. package/dist/lib/hash-table.js.map +1 -1
  19. package/dist/lib/hash-utils.js +3 -2
  20. package/dist/lib/hash-utils.js.map +1 -1
  21. package/dist/lib/heap.js +2 -4
  22. package/dist/lib/heap.js.map +1 -1
  23. package/dist/lib/linked-list.js.map +1 -1
  24. package/dist/lib/map.js.map +1 -1
  25. package/dist/lib/matrix.js +14 -6
  26. package/dist/lib/matrix.js.map +1 -1
  27. package/dist/lib/priority-queue.js.map +1 -1
  28. package/dist/lib/queue.js.map +1 -1
  29. package/dist/lib/red-black-tree.js +1 -2
  30. package/dist/lib/red-black-tree.js.map +1 -1
  31. package/dist/lib/set.js.map +1 -1
  32. package/dist/lib/stack.d.ts +1 -1
  33. package/dist/lib/stack.js.map +1 -1
  34. package/dist/lib/utils.js +13 -17
  35. package/dist/lib/utils.js.map +1 -1
  36. package/package.json +9 -5
  37. package/dist/lib/graph.d.ts +0 -14
  38. package/dist/lib/graph.js +0 -3
  39. package/dist/lib/graph.js.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Artiom Baloian
3
+ Copyright (c) 2025 Artiom Baloian
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -8,7 +8,7 @@ TypeScript data structure implementations without external dependencies. Why to
8
8
  - 0 Dependencies
9
9
  - Lightweight
10
10
  - Comes with Comparator (for custom types)
11
- - `equals()` method supported for all data structures
11
+ - `equals()` method provided for all data structures
12
12
  - Well documented
13
13
 
14
14
 
@@ -42,6 +42,7 @@ See the [documentation](https://github.com/baloian/typescript-ds-lib/blob/master
42
42
  ## Data Structures
43
43
  - Binary Search Tree
44
44
  - Deque
45
+ - Graph (beta version and partially tested)
45
46
  - Hash Table (unordered map)
46
47
  - Heap
47
48
  - Linked List
@@ -52,7 +53,6 @@ See the [documentation](https://github.com/baloian/typescript-ds-lib/blob/master
52
53
  - Red-Black Tree
53
54
  - Set
54
55
  - Stack
55
- - Graph (coming soon)
56
56
 
57
57
 
58
58
  ## `Map-Set` vs Native JavaScript `Map-Set`
@@ -69,9 +69,7 @@ You can consider the library's `Map` and `Set` as ordered map and set, and nativ
69
69
 
70
70
  ## Contributions
71
71
  Contributions are welcome and can be made by submitting GitHub pull requests
72
- to this repository. In general, the source code follows
73
- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) and the
74
- rules specified in `.eslintrc.json` file.
72
+ to this repository.
75
73
 
76
74
 
77
75
  ## License
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './types';
2
2
  export { BinarySearchTree } from './lib/binary-search-tree';
3
3
  export { Deque } from './lib/deque';
4
+ export { MatrixGraph } from './lib/graph/matrix-graph';
5
+ export { LinkedListGraph } from './lib/graph/linked-list-graph';
4
6
  export { HashTable } from './lib/hash-table';
5
7
  export { Heap } from './lib/heap';
6
8
  export { LinkedList } from './lib/linked-list';
package/dist/index.js CHANGED
@@ -14,12 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Stack = exports.Set = exports.RedBlackTree = exports.Queue = exports.PriorityQueue = exports.Matrix = exports.Map = exports.LinkedList = exports.Heap = exports.HashTable = exports.Deque = exports.BinarySearchTree = void 0;
17
+ exports.Stack = exports.Set = exports.RedBlackTree = exports.Queue = exports.PriorityQueue = exports.Matrix = exports.Map = exports.LinkedList = exports.Heap = exports.HashTable = exports.LinkedListGraph = exports.MatrixGraph = exports.Deque = exports.BinarySearchTree = void 0;
18
18
  __exportStar(require("./types"), exports);
19
19
  var binary_search_tree_1 = require("./lib/binary-search-tree");
20
20
  Object.defineProperty(exports, "BinarySearchTree", { enumerable: true, get: function () { return binary_search_tree_1.BinarySearchTree; } });
21
21
  var deque_1 = require("./lib/deque");
22
22
  Object.defineProperty(exports, "Deque", { enumerable: true, get: function () { return deque_1.Deque; } });
23
+ var matrix_graph_1 = require("./lib/graph/matrix-graph");
24
+ Object.defineProperty(exports, "MatrixGraph", { enumerable: true, get: function () { return matrix_graph_1.MatrixGraph; } });
25
+ var linked_list_graph_1 = require("./lib/graph/linked-list-graph");
26
+ Object.defineProperty(exports, "LinkedListGraph", { enumerable: true, get: function () { return linked_list_graph_1.LinkedListGraph; } });
23
27
  var hash_table_1 = require("./lib/hash-table");
24
28
  Object.defineProperty(exports, "HashTable", { enumerable: true, get: function () { return hash_table_1.HashTable; } });
25
29
  var heap_1 = require("./lib/heap");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+DAA4D;AAAnD,sHAAA,gBAAgB,OAAA;AACzB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,+CAA6C;AAApC,uGAAA,SAAS,OAAA;AAClB,mCAAkC;AAAzB,4FAAA,IAAI,OAAA;AACb,iDAA+C;AAAtC,yGAAA,UAAU,OAAA;AACnB,iCAAgC;AAAvB,0FAAA,GAAG,OAAA;AACZ,uCAAsC;AAA7B,gGAAA,MAAM,OAAA;AACf,uDAAqD;AAA5C,+GAAA,aAAa,OAAA;AACtB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,uDAAoD;AAA3C,8GAAA,YAAY,OAAA;AACrB,iCAAgC;AAAvB,0FAAA,GAAG,OAAA;AACZ,qCAAoC;AAA3B,8FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+DAA4D;AAAnD,sHAAA,gBAAgB,OAAA;AACzB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,yDAAuD;AAA9C,2GAAA,WAAW,OAAA;AACpB,mEAAgE;AAAvD,oHAAA,eAAe,OAAA;AACxB,+CAA6C;AAApC,uGAAA,SAAS,OAAA;AAClB,mCAAkC;AAAzB,4FAAA,IAAI,OAAA;AACb,iDAA+C;AAAtC,yGAAA,UAAU,OAAA;AACnB,iCAAgC;AAAvB,0FAAA,GAAG,OAAA;AACZ,uCAAsC;AAA7B,gGAAA,MAAM,OAAA;AACf,uDAAqD;AAA5C,+GAAA,aAAa,OAAA;AACtB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,uDAAoD;AAA3C,8GAAA,YAAY,OAAA;AACrB,iCAAgC;AAAvB,0FAAA,GAAG,OAAA;AACZ,qCAAoC;AAA3B,8FAAA,KAAK,OAAA"}
@@ -218,9 +218,9 @@ class BinarySearchTree extends base_collection_1.BaseCollection {
218
218
  return true;
219
219
  if (node1 === null || node2 === null)
220
220
  return false;
221
- return this.isEqual(node1.value, node2.value) &&
221
+ return (this.isEqual(node1.value, node2.value) &&
222
222
  this.areTreesEqual(node1.left, node2.left) &&
223
- this.areTreesEqual(node1.right, node2.right);
223
+ this.areTreesEqual(node1.right, node2.right));
224
224
  }
225
225
  }
226
226
  exports.BinarySearchTree = BinarySearchTree;
@@ -1 +1 @@
1
- {"version":3,"file":"binary-search-tree.js","sourceRoot":"","sources":["../../lib/binary-search-tree.ts"],"names":[],"mappings":";;;AACA,uDAAmD;AAanD,MAAM,QAAQ;IACZ,KAAK,CAAI;IACT,IAAI,CAAqB;IACzB,KAAK,CAAqB;IAE1B,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;CACF;AAGD,MAAa,gBAAoB,SAAQ,gCAAiB;IAChD,IAAI,CAAqB;IACzB,UAAU,CAAgB;IAC1B,SAAS,CAAS;IAE1B,YAAY,aAA4B,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC;QAC3D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAQ;QACb,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;YACpB,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,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,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAe;QACpB,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACtD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AA9ED,sBA8EC"}
@@ -0,0 +1,167 @@
1
+ import { BaseCollection } from '../base-collection';
2
+ /**
3
+ * Base class for Graph data structure implementations.
4
+ * Provides common functionality that can be extended by specific implementations
5
+ * like LinkedList-based or Matrix-based graphs.
6
+ */
7
+ export declare abstract class BaseGraph<V, W = number> extends BaseCollection<V> {
8
+ protected vertices: Set<V>;
9
+ protected vertexToIndex: Map<V, number>;
10
+ protected indexToVertex: Map<number, V>;
11
+ protected nextVertexIndex: number;
12
+ constructor();
13
+ /**
14
+ * Adds a vertex to the graph.
15
+ * @param vertex - The vertex to add
16
+ */
17
+ addVertex(vertex: V): void;
18
+ /**
19
+ * Removes a vertex from the graph and all its associated edges.
20
+ * @param vertex - The vertex to remove
21
+ */
22
+ removeVertex(vertex: V): void;
23
+ /**
24
+ * Adds an edge between two vertices with an optional weight.
25
+ * @param from - The source vertex
26
+ * @param to - The destination vertex
27
+ * @param weight - The weight of the edge (default: 1)
28
+ */
29
+ addEdge(from: V, to: V, weight?: W): void;
30
+ /**
31
+ * Removes an edge between two vertices.
32
+ * @param from - The source vertex
33
+ * @param to - The destination vertex
34
+ */
35
+ removeEdge(from: V, to: V): void;
36
+ /**
37
+ * Gets all neighbors of a vertex.
38
+ * @param vertex - The vertex to get neighbors for
39
+ * @returns Array of neighboring vertices
40
+ */
41
+ getNeighbors(vertex: V): V[];
42
+ /**
43
+ * Gets the weight of an edge between two vertices.
44
+ * @param from - The source vertex
45
+ * @param to - The destination vertex
46
+ * @returns The weight of the edge, or undefined if no edge exists
47
+ */
48
+ getEdgeWeight(from: V, to: V): W | undefined;
49
+ /**
50
+ * Gets all vertices in the graph.
51
+ * @returns Array of all vertices
52
+ */
53
+ getVertices(): V[];
54
+ /**
55
+ * Checks if a vertex exists in the graph.
56
+ * @param vertex - The vertex to check
57
+ * @returns True if the vertex exists, false otherwise
58
+ */
59
+ hasVertex(vertex: V): boolean;
60
+ /**
61
+ * Checks if an edge exists between two vertices.
62
+ * @param from - The source vertex
63
+ * @param to - The destination vertex
64
+ * @returns True if the edge exists, false otherwise
65
+ */
66
+ hasEdge(from: V, to: V): boolean;
67
+ /**
68
+ * Returns the number of vertices in the graph.
69
+ * @returns The number of vertices
70
+ */
71
+ vertexCount(): number;
72
+ /**
73
+ * Returns the number of edges in the graph.
74
+ * @returns The number of edges
75
+ */
76
+ edgeCount(): number;
77
+ /**
78
+ * Clears all vertices and edges from the graph.
79
+ */
80
+ clear(): void;
81
+ /**
82
+ * Returns the number of elements (vertices) in the graph.
83
+ * @returns The number of vertices
84
+ */
85
+ size(): number;
86
+ /**
87
+ * Checks if the graph is empty.
88
+ * @returns True if the graph has no vertices, false otherwise
89
+ */
90
+ isEmpty(): boolean;
91
+ /**
92
+ * Checks if this graph equals another graph.
93
+ * @param other - The other graph to compare with
94
+ * @returns True if the graphs are equal, false otherwise
95
+ */
96
+ equals(other: BaseGraph<V, W>): boolean;
97
+ /**
98
+ * Gets the index of a vertex.
99
+ * @param vertex - The vertex to get the index for
100
+ * @returns The index of the vertex, or -1 if not found
101
+ */
102
+ protected getVertexIndex(vertex: V): number;
103
+ /**
104
+ * Gets the vertex at a given index.
105
+ * @param index - The index to get the vertex for
106
+ * @returns The vertex at the index, or undefined if not found
107
+ */
108
+ protected getVertexAt(index: number): V | undefined;
109
+ /**
110
+ * Gets all vertex indices.
111
+ * @returns Array of vertex indices
112
+ */
113
+ protected getAllVertexIndices(): number[];
114
+ /**
115
+ * Called when a vertex is added to the graph.
116
+ * @param vertex - The vertex that was added
117
+ */
118
+ protected abstract onVertexAdded(vertex: V): void;
119
+ /**
120
+ * Called when a vertex is removed from the graph.
121
+ * @param vertex - The vertex that was removed
122
+ * @param vertexIndex - The index of the removed vertex
123
+ */
124
+ protected abstract onVertexRemoved(vertex: V, vertexIndex: number): void;
125
+ /**
126
+ * Called when an edge is added to the graph.
127
+ * @param from - The source vertex
128
+ * @param to - The destination vertex
129
+ * @param weight - The weight of the edge
130
+ */
131
+ protected abstract onEdgeAdded(from: V, to: V, weight: W): void;
132
+ /**
133
+ * Called when an edge is removed from the graph.
134
+ * @param from - The source vertex
135
+ * @param to - The destination vertex
136
+ */
137
+ protected abstract onEdgeRemoved(from: V, to: V): void;
138
+ /**
139
+ * Gets the neighbors of a vertex.
140
+ * @param vertex - The vertex to get neighbors for
141
+ * @returns Array of neighboring vertices
142
+ */
143
+ protected abstract onGetNeighbors(vertex: V): V[];
144
+ /**
145
+ * Gets the weight of an edge between two vertices.
146
+ * @param from - The source vertex
147
+ * @param to - The destination vertex
148
+ * @returns The weight of the edge, or undefined if no edge exists
149
+ */
150
+ protected abstract onGetEdgeWeight(from: V, to: V): W | undefined;
151
+ /**
152
+ * Checks if an edge exists between two vertices.
153
+ * @param from - The source vertex
154
+ * @param to - The destination vertex
155
+ * @returns True if the edge exists, false otherwise
156
+ */
157
+ protected abstract onHasEdge(from: V, to: V): boolean;
158
+ /**
159
+ * Gets the total number of edges in the graph.
160
+ * @returns The number of edges
161
+ */
162
+ protected abstract onGetEdgeCount(): number;
163
+ /**
164
+ * Called when the graph is cleared.
165
+ */
166
+ protected abstract onClear(): void;
167
+ }
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseGraph = void 0;
4
+ const base_collection_1 = require("../base-collection");
5
+ /**
6
+ * Base class for Graph data structure implementations.
7
+ * Provides common functionality that can be extended by specific implementations
8
+ * like LinkedList-based or Matrix-based graphs.
9
+ */
10
+ class BaseGraph extends base_collection_1.BaseCollection {
11
+ vertices;
12
+ vertexToIndex;
13
+ indexToVertex;
14
+ nextVertexIndex;
15
+ constructor() {
16
+ super();
17
+ this.vertices = new Set();
18
+ this.vertexToIndex = new Map();
19
+ this.indexToVertex = new Map();
20
+ this.nextVertexIndex = 0;
21
+ }
22
+ /**
23
+ * Adds a vertex to the graph.
24
+ * @param vertex - The vertex to add
25
+ */
26
+ addVertex(vertex) {
27
+ if (!this.vertices.has(vertex)) {
28
+ this.vertices.add(vertex);
29
+ this.vertexToIndex.set(vertex, this.nextVertexIndex);
30
+ this.indexToVertex.set(this.nextVertexIndex, vertex);
31
+ this.nextVertexIndex++;
32
+ this.onVertexAdded(vertex);
33
+ }
34
+ }
35
+ /**
36
+ * Removes a vertex from the graph and all its associated edges.
37
+ * @param vertex - The vertex to remove
38
+ */
39
+ removeVertex(vertex) {
40
+ if (this.vertices.has(vertex)) {
41
+ const vertexIndex = this.vertexToIndex.get(vertex);
42
+ // Remove all edges connected to this vertex
43
+ this.getVertices().forEach((otherVertex) => {
44
+ if (otherVertex !== vertex) {
45
+ this.removeEdge(vertex, otherVertex);
46
+ this.removeEdge(otherVertex, vertex);
47
+ }
48
+ });
49
+ // Remove from tracking collections
50
+ this.vertices.delete(vertex);
51
+ this.indexToVertex.delete(vertexIndex);
52
+ this.vertexToIndex.delete(vertex);
53
+ this.onVertexRemoved(vertex, vertexIndex);
54
+ }
55
+ }
56
+ /**
57
+ * Adds an edge between two vertices with an optional weight.
58
+ * @param from - The source vertex
59
+ * @param to - The destination vertex
60
+ * @param weight - The weight of the edge (default: 1)
61
+ */
62
+ addEdge(from, to, weight = 1) {
63
+ if (!this.vertices.has(from)) {
64
+ this.addVertex(from);
65
+ }
66
+ if (!this.vertices.has(to)) {
67
+ this.addVertex(to);
68
+ }
69
+ if (from !== to) {
70
+ this.onEdgeAdded(from, to, weight);
71
+ }
72
+ }
73
+ /**
74
+ * Removes an edge between two vertices.
75
+ * @param from - The source vertex
76
+ * @param to - The destination vertex
77
+ */
78
+ removeEdge(from, to) {
79
+ if (this.vertices.has(from) && this.vertices.has(to)) {
80
+ this.onEdgeRemoved(from, to);
81
+ }
82
+ }
83
+ /**
84
+ * Gets all neighbors of a vertex.
85
+ * @param vertex - The vertex to get neighbors for
86
+ * @returns Array of neighboring vertices
87
+ */
88
+ getNeighbors(vertex) {
89
+ if (!this.vertices.has(vertex)) {
90
+ return [];
91
+ }
92
+ return this.onGetNeighbors(vertex);
93
+ }
94
+ /**
95
+ * Gets the weight of an edge between two vertices.
96
+ * @param from - The source vertex
97
+ * @param to - The destination vertex
98
+ * @returns The weight of the edge, or undefined if no edge exists
99
+ */
100
+ getEdgeWeight(from, to) {
101
+ if (!this.vertices.has(from) || !this.vertices.has(to)) {
102
+ return undefined;
103
+ }
104
+ return this.onGetEdgeWeight(from, to);
105
+ }
106
+ /**
107
+ * Gets all vertices in the graph.
108
+ * @returns Array of all vertices
109
+ */
110
+ getVertices() {
111
+ return Array.from(this.vertices);
112
+ }
113
+ /**
114
+ * Checks if a vertex exists in the graph.
115
+ * @param vertex - The vertex to check
116
+ * @returns True if the vertex exists, false otherwise
117
+ */
118
+ hasVertex(vertex) {
119
+ return this.vertices.has(vertex);
120
+ }
121
+ /**
122
+ * Checks if an edge exists between two vertices.
123
+ * @param from - The source vertex
124
+ * @param to - The destination vertex
125
+ * @returns True if the edge exists, false otherwise
126
+ */
127
+ hasEdge(from, to) {
128
+ if (!this.vertices.has(from) || !this.vertices.has(to)) {
129
+ return false;
130
+ }
131
+ return this.onHasEdge(from, to);
132
+ }
133
+ /**
134
+ * Returns the number of vertices in the graph.
135
+ * @returns The number of vertices
136
+ */
137
+ vertexCount() {
138
+ return this.vertices.size;
139
+ }
140
+ /**
141
+ * Returns the number of edges in the graph.
142
+ * @returns The number of edges
143
+ */
144
+ edgeCount() {
145
+ return this.onGetEdgeCount();
146
+ }
147
+ /**
148
+ * Clears all vertices and edges from the graph.
149
+ */
150
+ clear() {
151
+ this.vertices.clear();
152
+ this.vertexToIndex.clear();
153
+ this.indexToVertex.clear();
154
+ this.nextVertexIndex = 0;
155
+ this.onClear();
156
+ }
157
+ /**
158
+ * Returns the number of elements (vertices) in the graph.
159
+ * @returns The number of vertices
160
+ */
161
+ size() {
162
+ return this.vertexCount();
163
+ }
164
+ /**
165
+ * Checks if the graph is empty.
166
+ * @returns True if the graph has no vertices, false otherwise
167
+ */
168
+ isEmpty() {
169
+ return this.vertices.size === 0;
170
+ }
171
+ /**
172
+ * Checks if this graph equals another graph.
173
+ * @param other - The other graph to compare with
174
+ * @returns True if the graphs are equal, false otherwise
175
+ */
176
+ equals(other) {
177
+ if (!(other instanceof BaseGraph)) {
178
+ return false;
179
+ }
180
+ if (this.vertexCount() !== other.vertexCount()) {
181
+ return false;
182
+ }
183
+ const thisVertices = this.getVertices();
184
+ const otherVertices = other.getVertices();
185
+ // Check if all vertices exist in both graphs
186
+ for (const vertex of thisVertices) {
187
+ if (!other.hasVertex(vertex)) {
188
+ return false;
189
+ }
190
+ }
191
+ // Check if all edges exist in both graphs
192
+ for (const from of thisVertices) {
193
+ for (const to of thisVertices) {
194
+ if (this.hasEdge(from, to) !== other.hasEdge(from, to)) {
195
+ return false;
196
+ }
197
+ if (this.hasEdge(from, to)) {
198
+ const thisWeight = this.getEdgeWeight(from, to);
199
+ const otherWeight = other.getEdgeWeight(from, to);
200
+ if (thisWeight !== otherWeight) {
201
+ return false;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ return true;
207
+ }
208
+ /**
209
+ * Gets the index of a vertex.
210
+ * @param vertex - The vertex to get the index for
211
+ * @returns The index of the vertex, or -1 if not found
212
+ */
213
+ getVertexIndex(vertex) {
214
+ return this.vertexToIndex.get(vertex) ?? -1;
215
+ }
216
+ /**
217
+ * Gets the vertex at a given index.
218
+ * @param index - The index to get the vertex for
219
+ * @returns The vertex at the index, or undefined if not found
220
+ */
221
+ getVertexAt(index) {
222
+ return this.indexToVertex.get(index);
223
+ }
224
+ /**
225
+ * Gets all vertex indices.
226
+ * @returns Array of vertex indices
227
+ */
228
+ getAllVertexIndices() {
229
+ return Array.from(this.vertexToIndex.values());
230
+ }
231
+ }
232
+ exports.BaseGraph = BaseGraph;
233
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../lib/graph/base.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAEpD;;;;GAIG;AACH,MAAsB,SAAyB,SAAQ,gCAAiB;IAC5D,QAAQ,CAAS;IACjB,aAAa,CAAiB;IAC9B,aAAa,CAAiB;IAC9B,eAAe,CAAS;IAElC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAK,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAa,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAa,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AAa,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACO,WAAW,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACO,mBAAmB;QAC3B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CAiEF;AAvTD,8BAuTC"}
@@ -0,0 +1,18 @@
1
+ import { BaseGraph } from './base';
2
+ /**
3
+ * LinkedList-based Graph implementation.
4
+ * Uses adjacency lists to represent the graph.
5
+ */
6
+ export declare class LinkedListGraph<V, W = number> extends BaseGraph<V, W> {
7
+ private adjacencyLists;
8
+ constructor();
9
+ protected onVertexAdded(vertex: V): void;
10
+ protected onVertexRemoved(vertex: V, vertexIndex: number): void;
11
+ protected onEdgeAdded(from: V, to: V, weight: W): void;
12
+ protected onEdgeRemoved(from: V, to: V): void;
13
+ protected onGetNeighbors(vertex: V): V[];
14
+ protected onGetEdgeWeight(from: V, to: V): W | undefined;
15
+ protected onHasEdge(from: V, to: V): boolean;
16
+ protected onGetEdgeCount(): number;
17
+ protected onClear(): void;
18
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkedListGraph = void 0;
4
+ const linked_list_1 = require("../linked-list");
5
+ const base_1 = require("./base");
6
+ /**
7
+ * LinkedList-based Graph implementation.
8
+ * Uses adjacency lists to represent the graph.
9
+ */
10
+ class LinkedListGraph extends base_1.BaseGraph {
11
+ adjacencyLists;
12
+ constructor() {
13
+ super();
14
+ this.adjacencyLists = new Map();
15
+ }
16
+ onVertexAdded(vertex) {
17
+ this.adjacencyLists.set(vertex, new linked_list_1.LinkedList());
18
+ }
19
+ onVertexRemoved(vertex, vertexIndex) {
20
+ this.adjacencyLists.delete(vertex);
21
+ }
22
+ onEdgeAdded(from, to, weight) {
23
+ const fromList = this.adjacencyLists.get(from);
24
+ if (fromList) {
25
+ // Remove existing edge if it exists
26
+ fromList.removeIf((edge) => edge.vertex === to);
27
+ fromList.pushBack({ vertex: to, weight });
28
+ }
29
+ }
30
+ onEdgeRemoved(from, to) {
31
+ const fromList = this.adjacencyLists.get(from);
32
+ if (fromList) {
33
+ fromList.removeIf((edge) => edge.vertex === to);
34
+ }
35
+ }
36
+ onGetNeighbors(vertex) {
37
+ const list = this.adjacencyLists.get(vertex);
38
+ if (!list)
39
+ return [];
40
+ const neighbors = [];
41
+ list.forEach((edge) => neighbors.push(edge.vertex));
42
+ return neighbors;
43
+ }
44
+ onGetEdgeWeight(from, to) {
45
+ const list = this.adjacencyLists.get(from);
46
+ if (!list)
47
+ return undefined;
48
+ for (let i = 0; i < list.size(); i++) {
49
+ const edge = list.get(i);
50
+ if (edge && edge.vertex === to) {
51
+ return edge.weight;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+ onHasEdge(from, to) {
57
+ return this.onGetEdgeWeight(from, to) !== undefined;
58
+ }
59
+ onGetEdgeCount() {
60
+ let count = 0;
61
+ this.adjacencyLists.forEach((list) => {
62
+ count += list.size();
63
+ });
64
+ return count;
65
+ }
66
+ onClear() {
67
+ this.adjacencyLists.clear();
68
+ }
69
+ }
70
+ exports.LinkedListGraph = LinkedListGraph;
71
+ //# sourceMappingURL=linked-list-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-list-graph.js","sourceRoot":"","sources":["../../../lib/graph/linked-list-graph.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAC5C,iCAAmC;AAEnC;;;GAGG;AACH,MAAa,eAA+B,SAAQ,gBAAe;IACzD,cAAc,CAA+C;IAErE;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAA2C,CAAC;IAC3E,CAAC;IAES,aAAa,CAAC,MAAS;QAC/B,IAAI,C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AAK;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACzB,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;gBAC/B,OAAO,IAAI,CAAC,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAES,SAAS,CAAC,IAAO,EAAE,EAAK;QAChC,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,SAAS,CAAC;IACtD,CAAC;IAES,cAAc;QACtB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACnC,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;IAES,OAAO;QACf,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AArED,0CAqEC"}
@@ -0,0 +1,18 @@
1
+ import { BaseGraph } from './base';
2
+ /**
3
+ * Matrix-based Graph implementation.
4
+ * Uses adjacency matrix to represent the graph.
5
+ */
6
+ export declare class MatrixGraph<V, W = number> extends BaseGraph<V, W> {
7
+ private adjacencyMatrix;
8
+ constructor();
9
+ protected onVertexAdded(vertex: V): void;
10
+ protected onVertexRemoved(vertex: V, vertexIndex: number): void;
11
+ protected onEdgeAdded(from: V, to: V, weight: W): void;
12
+ protected onEdgeRemoved(from: V, to: V): void;
13
+ protected onGetNeighbors(vertex: V): V[];
14
+ protected onGetEdgeWeight(from: V, to: V): W | undefined;
15
+ protected onHasEdge(from: V, to: V): boolean;
16
+ protected onGetEdgeCount(): number;
17
+ protected onClear(): void;
18
+ }