graph-typed 2.4.2 → 2.4.4
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/dist/cjs/index.cjs +6 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +6 -14
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +6 -14
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +6 -14
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +10 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +10 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/types/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/types/data-structures/heap/heap.d.ts +3 -7
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
- package/dist/umd/graph-typed.js +6 -14
- package/dist/umd/graph-typed.js.map +1 -1
- package/dist/umd/graph-typed.min.js +1 -1
- package/dist/umd/graph-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +8 -7
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/binary-tree/tree-map.ts +16 -0
- package/src/data-structures/binary-tree/tree-multi-set.ts +5 -5
- package/src/data-structures/binary-tree/tree-set.ts +16 -0
- package/src/data-structures/graph/abstract-graph.ts +18 -18
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +4 -4
- package/src/data-structures/hash/hash-map.ts +6 -4
- package/src/data-structures/heap/heap.ts +17 -14
- package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
- package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
- package/src/data-structures/queue/deque.ts +1 -1
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +10 -5
- package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/stack/stack.ts +1 -1
|
@@ -27,7 +27,7 @@ export declare abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
27
27
|
* @remarks
|
|
28
28
|
* Time O(1), Space O(1).
|
|
29
29
|
*/
|
|
30
|
-
protected _toElementFn?: (rawElement: R) => E;
|
|
30
|
+
protected readonly _toElementFn?: (rawElement: R) => E;
|
|
31
31
|
/**
|
|
32
32
|
* Exposes the current `toElementFn`, if configured.
|
|
33
33
|
*
|
|
@@ -275,7 +275,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
275
275
|
* @param [options] - Configuration options for the tree.
|
|
276
276
|
*/
|
|
277
277
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
278
|
-
protected _isMapMode: boolean;
|
|
278
|
+
protected readonly _isMapMode: boolean;
|
|
279
279
|
/**
|
|
280
280
|
* Gets whether the tree is in Map mode.
|
|
281
281
|
* @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
|
|
@@ -283,7 +283,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
283
283
|
* @returns True if in Map mode, false otherwise.
|
|
284
284
|
*/
|
|
285
285
|
get isMapMode(): boolean;
|
|
286
|
-
protected _isDuplicate: boolean;
|
|
286
|
+
protected readonly _isDuplicate: boolean;
|
|
287
287
|
/**
|
|
288
288
|
* Gets whether the tree allows duplicate keys.
|
|
289
289
|
* @remarks Time O(1)
|
|
@@ -315,7 +315,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
315
315
|
* @returns The size of the tree.
|
|
316
316
|
*/
|
|
317
317
|
get size(): number;
|
|
318
|
-
protected _NIL: BinaryTreeNode<K, V>;
|
|
318
|
+
protected readonly _NIL: BinaryTreeNode<K, V>;
|
|
319
319
|
/**
|
|
320
320
|
* Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
321
321
|
* @remarks Time O(1)
|
|
@@ -323,7 +323,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
323
323
|
* @returns The NIL node.
|
|
324
324
|
*/
|
|
325
325
|
get NIL(): BinaryTreeNode<K, V>;
|
|
326
|
-
protected _toEntryFn?: ToEntryFn<K, V, R>;
|
|
326
|
+
protected readonly _toEntryFn?: ToEntryFn<K, V, R>;
|
|
327
327
|
/**
|
|
328
328
|
* Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
329
329
|
* @remarks Time O(1)
|
|
@@ -682,7 +682,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
682
682
|
* @param node - The node.
|
|
683
683
|
* @returns The node's key or undefined.
|
|
684
684
|
*/
|
|
685
|
-
protected _DEFAULT_NODE_CALLBACK:
|
|
685
|
+
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
686
686
|
/**
|
|
687
687
|
* (Protected) Snapshots the current tree's configuration options.
|
|
688
688
|
* @remarks Time O(1)
|
|
@@ -294,7 +294,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
294
294
|
|
|
295
295
|
* @remarks Time O(1) Space O(1)
|
|
296
296
|
*/
|
|
297
|
-
protected _comparator: Comparator<K>;
|
|
297
|
+
protected readonly _comparator: Comparator<K>;
|
|
298
298
|
/**
|
|
299
299
|
* Gets the comparator function used by the tree.
|
|
300
300
|
* @remarks Time O(1)
|
|
@@ -185,4 +185,14 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
185
185
|
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
186
186
|
*/
|
|
187
187
|
rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a shallow clone of this map.
|
|
190
|
+
* @remarks Time O(n log n), Space O(n)
|
|
191
|
+
* @example
|
|
192
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
193
|
+
* const copy = original.clone();
|
|
194
|
+
* copy.set('c', 3);
|
|
195
|
+
* original.has('c'); // false (original unchanged)
|
|
196
|
+
*/
|
|
197
|
+
clone(): TreeMap<K, V>;
|
|
188
198
|
}
|
|
@@ -178,4 +178,14 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
178
178
|
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
179
179
|
*/
|
|
180
180
|
rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
|
|
181
|
+
/**
|
|
182
|
+
* Creates a shallow clone of this set.
|
|
183
|
+
* @remarks Time O(n log n), Space O(n)
|
|
184
|
+
* @example
|
|
185
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
186
|
+
* const copy = original.clone();
|
|
187
|
+
* copy.add(4);
|
|
188
|
+
* original.has(4); // false (original unchanged)
|
|
189
|
+
*/
|
|
190
|
+
clone(): TreeSet<K>;
|
|
181
191
|
}
|
|
@@ -170,7 +170,7 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
170
170
|
* @returns DirectedGraph with all keys added.
|
|
171
171
|
* @remarks Time O(V), Space O(V)
|
|
172
172
|
*/
|
|
173
|
-
static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K,
|
|
173
|
+
static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, undefined, DirectedVertex<K>, DirectedEdge<undefined>>;
|
|
174
174
|
/**
|
|
175
175
|
* Construct a directed graph from `[key, value]` entries.
|
|
176
176
|
* @template V - Vertex value type.
|
|
@@ -178,7 +178,7 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
178
178
|
* @returns DirectedGraph with all vertices added.
|
|
179
179
|
* @remarks Time O(V), Space O(V)
|
|
180
180
|
*/
|
|
181
|
-
static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V,
|
|
181
|
+
static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, undefined, DirectedVertex<V>, DirectedEdge<undefined>>;
|
|
182
182
|
/**
|
|
183
183
|
* Create a directed vertex instance. Does not insert into the graph.
|
|
184
184
|
* @param key - Vertex identifier.
|
|
@@ -200,7 +200,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
200
200
|
* @returns UndirectedGraph with all keys added.
|
|
201
201
|
* @remarks Time O(V), Space O(V)
|
|
202
202
|
*/
|
|
203
|
-
static fromKeys<K extends VertexKey>(keys: Iterable<K>): UndirectedGraph<K,
|
|
203
|
+
static fromKeys<K extends VertexKey>(keys: Iterable<K>): UndirectedGraph<K, undefined, UndirectedVertex<K>, UndirectedEdge<undefined>>;
|
|
204
204
|
/**
|
|
205
205
|
* Construct an undirected graph from `[key, value]` entries.
|
|
206
206
|
* @template V - Vertex value type.
|
|
@@ -208,7 +208,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
208
208
|
* @returns UndirectedGraph with all vertices added.
|
|
209
209
|
* @remarks Time O(V), Space O(V)
|
|
210
210
|
*/
|
|
211
|
-
static fromEntries<V>(entries: Iterable<[VertexKey, V]>): UndirectedGraph<V,
|
|
211
|
+
static fromEntries<V>(entries: Iterable<[VertexKey, V]>): UndirectedGraph<V, undefined, UndirectedVertex<V>, UndirectedEdge<undefined>>;
|
|
212
212
|
/**
|
|
213
213
|
* Create an undirected vertex instance. Does not insert into the graph.
|
|
214
214
|
* @param key - Vertex identifier.
|
|
@@ -175,7 +175,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
175
175
|
* @returns Map of object→value.
|
|
176
176
|
*/
|
|
177
177
|
get objMap(): Map<object, V>;
|
|
178
|
-
protected _toEntryFn?: (rawElement: R) => [K, V];
|
|
178
|
+
protected readonly _toEntryFn?: (rawElement: R) => [K, V];
|
|
179
179
|
/**
|
|
180
180
|
* Get the raw→entry converter function if present.
|
|
181
181
|
* @remarks Time O(1), Space O(1)
|
|
@@ -346,7 +346,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
346
346
|
* @returns Tail node or sentinel.
|
|
347
347
|
*/
|
|
348
348
|
get tail(): HashMapLinkedNode<K, V | undefined>;
|
|
349
|
-
protected _toEntryFn?: (rawElement: R) => [K, V];
|
|
349
|
+
protected readonly _toEntryFn?: (rawElement: R) => [K, V];
|
|
350
350
|
get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
|
|
351
351
|
protected _size: number;
|
|
352
352
|
get size(): number;
|
|
@@ -414,12 +414,8 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
414
414
|
* @returns A new heap with mapped elements.
|
|
415
415
|
*/
|
|
416
416
|
mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
|
|
417
|
-
protected _DEFAULT_COMPARATOR:
|
|
418
|
-
protected _comparator: Comparator<E>;
|
|
419
|
-
* Get the comparator used to order elements.
|
|
420
|
-
* @remarks Time O(1), Space O(1)
|
|
421
|
-
* @returns Comparator function.
|
|
422
|
-
*/
|
|
417
|
+
protected readonly _DEFAULT_COMPARATOR: Comparator<E>;
|
|
418
|
+
protected readonly _comparator: Comparator<E>;
|
|
423
419
|
/**
|
|
424
420
|
* Get the comparator used to order elements.
|
|
425
421
|
* @remarks Time O(1), Space O(1)
|
|
@@ -501,7 +497,7 @@ export declare class FibonacciHeap<E> {
|
|
|
501
497
|
* @returns Min node or undefined.
|
|
502
498
|
*/
|
|
503
499
|
get min(): FibonacciHeapNode<E> | undefined;
|
|
504
|
-
protected _comparator: Comparator<E>;
|
|
500
|
+
protected readonly _comparator: Comparator<E>;
|
|
505
501
|
get comparator(): Comparator<E>;
|
|
506
502
|
clear(): void;
|
|
507
503
|
add(element: E): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { BSTOptions } from './bst';
|
|
2
|
-
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R
|
|
2
|
+
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { LinearBaseOptions } from '../base';
|
|
2
|
-
export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R
|
|
2
|
+
export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { LinearBaseOptions } from '../base';
|
|
2
|
-
export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R
|
|
2
|
+
export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { HeapOptions } from '../heap';
|
|
2
|
-
export type PriorityQueueOptions<E, R> = HeapOptions<E, R
|
|
2
|
+
export type PriorityQueueOptions<E, R> = HeapOptions<E, R>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IterableElementBaseOptions } from '../base';
|
|
2
|
-
export type StackOptions<E, R> = IterableElementBaseOptions<E, R
|
|
2
|
+
export type StackOptions<E, R> = IterableElementBaseOptions<E, R>;
|
package/dist/umd/graph-typed.js
CHANGED
|
@@ -809,11 +809,6 @@ var graphTyped = (() => {
|
|
|
809
809
|
}
|
|
810
810
|
return out;
|
|
811
811
|
}
|
|
812
|
-
/**
|
|
813
|
-
* Get the comparator used to order elements.
|
|
814
|
-
* @remarks Time O(1), Space O(1)
|
|
815
|
-
* @returns Comparator function.
|
|
816
|
-
*/
|
|
817
812
|
/**
|
|
818
813
|
* Get the comparator used to order elements.
|
|
819
814
|
* @remarks Time O(1), Space O(1)
|
|
@@ -862,8 +857,7 @@ var graphTyped = (() => {
|
|
|
862
857
|
*/
|
|
863
858
|
_createInstance(options) {
|
|
864
859
|
const Ctor = this.constructor;
|
|
865
|
-
|
|
866
|
-
return next;
|
|
860
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
867
861
|
}
|
|
868
862
|
/**
|
|
869
863
|
* (Protected) Create a like-kind instance seeded by elements.
|
|
@@ -2191,8 +2185,8 @@ var graphTyped = (() => {
|
|
|
2191
2185
|
const Ctor = this.constructor;
|
|
2192
2186
|
const instance = new Ctor();
|
|
2193
2187
|
const graph = _options == null ? void 0 : _options.graph;
|
|
2194
|
-
if (graph) instance
|
|
2195
|
-
else instance
|
|
2188
|
+
if (graph) instance["_options"] = { ...instance["_options"], ...graph };
|
|
2189
|
+
else instance["_options"] = { ...instance["_options"], ...this._options };
|
|
2196
2190
|
return instance;
|
|
2197
2191
|
}
|
|
2198
2192
|
/**
|
|
@@ -2225,12 +2219,10 @@ var graphTyped = (() => {
|
|
|
2225
2219
|
const [va, vb] = ends;
|
|
2226
2220
|
const ka = va.key;
|
|
2227
2221
|
const kb = vb.key;
|
|
2228
|
-
const hasA = g.hasVertex ? g.hasVertex(ka) : false;
|
|
2229
|
-
const hasB = g.hasVertex ? g.hasVertex(kb) : false;
|
|
2222
|
+
const hasA = typeof g.hasVertex === "function" ? g.hasVertex(ka) : false;
|
|
2223
|
+
const hasB = typeof g.hasVertex === "function" ? g.hasVertex(kb) : false;
|
|
2230
2224
|
if (hasA && hasB) {
|
|
2231
|
-
const
|
|
2232
|
-
const val = e.value;
|
|
2233
|
-
const newEdge = g.createEdge(ka, kb, w, val);
|
|
2225
|
+
const newEdge = g.createEdge(ka, kb, e.weight, e.value);
|
|
2234
2226
|
g._addEdge(newEdge);
|
|
2235
2227
|
}
|
|
2236
2228
|
}
|