stack-typed 2.1.0 → 2.1.2
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 +552 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +548 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/stack-typed.js +563 -0
- package/dist/umd/stack-typed.js.map +1 -0
- package/dist/umd/stack-typed.min.js +9 -0
- package/dist/umd/stack-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { DijkstraResult, EntryCallback, GraphOptions, VertexKey } from '../../types';
|
|
9
|
-
import { IterableEntryBase } from '../base';
|
|
10
|
-
import { IGraph } from '../../interfaces';
|
|
11
|
-
export declare abstract class AbstractVertex<V = any> {
|
|
12
|
-
key: VertexKey;
|
|
13
|
-
value: V | undefined;
|
|
14
|
-
protected constructor(key: VertexKey, value?: V);
|
|
15
|
-
}
|
|
16
|
-
export declare abstract class AbstractEdge<E = any> {
|
|
17
|
-
value: E | undefined;
|
|
18
|
-
weight: number;
|
|
19
|
-
protected constructor(weight?: number, value?: E);
|
|
20
|
-
protected _hashCode: string;
|
|
21
|
-
get hashCode(): string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Abstract graph over vertices and edges.
|
|
25
|
-
* @template V - Vertex value type.
|
|
26
|
-
* @template E - Edge value type.
|
|
27
|
-
* @template VO - Concrete vertex subclass (extends AbstractVertex<V>).
|
|
28
|
-
* @template EO - Concrete edge subclass (extends AbstractEdge<E>).
|
|
29
|
-
* @remarks Time O(1), Space O(1)
|
|
30
|
-
* @example examples will be generated by unit test
|
|
31
|
-
*/
|
|
32
|
-
export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> extends IterableEntryBase<VertexKey, V | undefined> implements IGraph<V, E, VO, EO> {
|
|
33
|
-
/**
|
|
34
|
-
* Construct a graph with runtime defaults.
|
|
35
|
-
* @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
36
|
-
* @remarks Time O(1), Space O(1)
|
|
37
|
-
*/
|
|
38
|
-
constructor(options?: Partial<Record<string, unknown>>);
|
|
39
|
-
protected _options: GraphOptions<V>;
|
|
40
|
-
get options(): Readonly<GraphOptions<V>>;
|
|
41
|
-
protected _vertexMap: Map<VertexKey, VO>;
|
|
42
|
-
get vertexMap(): Map<VertexKey, VO>;
|
|
43
|
-
set vertexMap(v: Map<VertexKey, VO>);
|
|
44
|
-
get size(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Create a new vertex instance (implementation specific).
|
|
47
|
-
* @param key - Vertex identifier.
|
|
48
|
-
* @param value - Optional payload.
|
|
49
|
-
* @returns Concrete vertex instance.
|
|
50
|
-
* @remarks Time O(1), Space O(1)
|
|
51
|
-
*/
|
|
52
|
-
abstract createVertex(key: VertexKey, value?: V): VO;
|
|
53
|
-
/**
|
|
54
|
-
* Create a new edge instance (implementation specific).
|
|
55
|
-
* @param srcOrV1 - Source/endpoint A key.
|
|
56
|
-
* @param destOrV2 - Destination/endpoint B key.
|
|
57
|
-
* @param weight - Edge weight (defaults may apply).
|
|
58
|
-
* @param value - Edge payload.
|
|
59
|
-
* @returns Concrete edge instance.
|
|
60
|
-
* @remarks Time O(1), Space O(1)
|
|
61
|
-
*/
|
|
62
|
-
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
63
|
-
/**
|
|
64
|
-
* Delete an edge by instance.
|
|
65
|
-
* @param edge - Edge instance.
|
|
66
|
-
* @returns Removed edge or `undefined`.
|
|
67
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
68
|
-
*/
|
|
69
|
-
abstract deleteEdge(edge: EO): EO | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Get an edge between two vertices if present.
|
|
72
|
-
* @param srcOrKey - Source/endpoint A vertex or key.
|
|
73
|
-
* @param destOrKey - Destination/endpoint B vertex or key.
|
|
74
|
-
* @returns Edge instance or `undefined`.
|
|
75
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
76
|
-
*/
|
|
77
|
-
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Degree of a vertex in this graph model.
|
|
80
|
-
* @param vertexOrKey - Vertex or key.
|
|
81
|
-
* @returns Non-negative integer degree.
|
|
82
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
83
|
-
*/
|
|
84
|
-
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
85
|
-
/**
|
|
86
|
-
* All edges in the graph (unique, order not guaranteed).
|
|
87
|
-
* @returns Array of edges.
|
|
88
|
-
* @remarks Time O(E), Space O(E)
|
|
89
|
-
*/
|
|
90
|
-
abstract edgeSet(): EO[];
|
|
91
|
-
/**
|
|
92
|
-
* Incident edges of a vertex.
|
|
93
|
-
* @param vertexOrKey - Vertex or key.
|
|
94
|
-
* @returns Array of incident edges.
|
|
95
|
-
* @remarks Time O(deg), Space O(deg)
|
|
96
|
-
*/
|
|
97
|
-
abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
98
|
-
/**
|
|
99
|
-
* One-step neighbors of a vertex.
|
|
100
|
-
* @param vertexOrKey - Vertex or key.
|
|
101
|
-
* @returns Array of neighbor vertices.
|
|
102
|
-
* @remarks Time O(deg), Space O(deg)
|
|
103
|
-
*/
|
|
104
|
-
abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
105
|
-
/**
|
|
106
|
-
* Resolve endpoints of an edge to vertex instances.
|
|
107
|
-
* @param edge - Edge instance.
|
|
108
|
-
* @returns `[v1, v2]` or `undefined` if missing.
|
|
109
|
-
* @remarks Time O(1), Space O(1)
|
|
110
|
-
*/
|
|
111
|
-
abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Get vertex instance by key.
|
|
114
|
-
* @param vertexKey - Vertex key.
|
|
115
|
-
* @returns Vertex instance or `undefined`.
|
|
116
|
-
* @remarks Time O(1), Space O(1)
|
|
117
|
-
*/
|
|
118
|
-
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
119
|
-
/**
|
|
120
|
-
* Whether a vertex exists.
|
|
121
|
-
* @param vertexOrKey - Vertex or key.
|
|
122
|
-
* @returns `true` if present, otherwise `false`.
|
|
123
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
124
|
-
*/
|
|
125
|
-
hasVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
126
|
-
addVertex(vertex: VO): boolean;
|
|
127
|
-
addVertex(key: VertexKey, value?: V): boolean;
|
|
128
|
-
/**
|
|
129
|
-
* Type guard: check if a value is a valid vertex key.
|
|
130
|
-
* @param potentialKey - Value to test.
|
|
131
|
-
* @returns `true` if string/number; else `false`.
|
|
132
|
-
* @remarks Time O(1), Space O(1)
|
|
133
|
-
*/
|
|
134
|
-
isVertexKey(potentialKey: any): potentialKey is VertexKey;
|
|
135
|
-
/**
|
|
136
|
-
* Delete a vertex and its incident edges.
|
|
137
|
-
* @param vertexOrKey - Vertex or key.
|
|
138
|
-
* @returns `true` if removed; otherwise `false`.
|
|
139
|
-
* @remarks Time O(deg), Space O(1)
|
|
140
|
-
*/
|
|
141
|
-
abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Delete multiple vertices.
|
|
144
|
-
* @param vertexMap - Array of vertices or keys.
|
|
145
|
-
* @returns `true` if any vertex was removed.
|
|
146
|
-
* @remarks Time O(sum(deg)), Space O(1)
|
|
147
|
-
*/
|
|
148
|
-
removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Whether an edge exists between two vertices.
|
|
151
|
-
* @param v1 - Endpoint A vertex or key.
|
|
152
|
-
* @param v2 - Endpoint B vertex or key.
|
|
153
|
-
* @returns `true` if present; otherwise `false`.
|
|
154
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
155
|
-
*/
|
|
156
|
-
hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
|
|
157
|
-
addEdge(edge: EO): boolean;
|
|
158
|
-
addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Set the weight of an existing edge.
|
|
161
|
-
* @param srcOrKey - Source vertex or key.
|
|
162
|
-
* @param destOrKey - Destination vertex or key.
|
|
163
|
-
* @param weight - New weight.
|
|
164
|
-
* @returns `true` if updated; otherwise `false`.
|
|
165
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
166
|
-
*/
|
|
167
|
-
setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Enumerate simple paths up to a limit.
|
|
170
|
-
* @param v1 - Source vertex or key.
|
|
171
|
-
* @param v2 - Destination vertex or key.
|
|
172
|
-
* @param limit - Maximum number of paths to collect.
|
|
173
|
-
* @returns Array of paths (each path is an array of vertices).
|
|
174
|
-
* @remarks Time O(paths) worst-case exponential, Space O(V + paths)
|
|
175
|
-
*/
|
|
176
|
-
getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
|
|
177
|
-
/**
|
|
178
|
-
* Sum the weights along a vertex path.
|
|
179
|
-
* @param path - Sequence of vertices.
|
|
180
|
-
* @returns Path weight sum (0 if empty or edge missing).
|
|
181
|
-
* @remarks Time O(L), Space O(1) where L is path length
|
|
182
|
-
*/
|
|
183
|
-
getPathSumWeight(path: VO[]): number;
|
|
184
|
-
/**
|
|
185
|
-
* Minimum hops/weight between two vertices.
|
|
186
|
-
* @param v1 - Source vertex or key.
|
|
187
|
-
* @param v2 - Destination vertex or key.
|
|
188
|
-
* @param isWeight - If `true`, compare by path weight; otherwise by hop count.
|
|
189
|
-
* @returns Minimum cost or `undefined` if missing/unreachable.
|
|
190
|
-
* @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
|
|
191
|
-
*/
|
|
192
|
-
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* Minimum path (as vertex sequence) between two vertices.
|
|
195
|
-
* @param v1 - Source vertex or key.
|
|
196
|
-
* @param v2 - Destination vertex or key.
|
|
197
|
-
* @param isWeight - If `true`, compare by path weight; otherwise by hop count.
|
|
198
|
-
* @param isDFS - For weighted mode only: if `true`, brute-force all paths; if `false`, use Dijkstra.
|
|
199
|
-
* @returns Vertex sequence, or `undefined`/empty when unreachable depending on branch.
|
|
200
|
-
* @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
|
|
201
|
-
*/
|
|
202
|
-
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
203
|
-
/**
|
|
204
|
-
* Dijkstra without heap (array-based selection).
|
|
205
|
-
* @param src - Source vertex or key.
|
|
206
|
-
* @param dest - Optional destination for early stop.
|
|
207
|
-
* @param getMinDist - If `true`, compute global minimum distance.
|
|
208
|
-
* @param genPaths - If `true`, also generate path arrays.
|
|
209
|
-
* @returns Result bag or `undefined` if source missing.
|
|
210
|
-
* @remarks Time O(V^2 + E), Space O(V + E)
|
|
211
|
-
*/
|
|
212
|
-
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO> | undefined;
|
|
213
|
-
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO> | undefined;
|
|
214
|
-
/**
|
|
215
|
-
* Bellman-Ford single-source shortest paths with option to scan negative cycles.
|
|
216
|
-
* @param src - Source vertex or key.
|
|
217
|
-
* @param scanNegativeCycle - If `true`, also detect negative cycles.
|
|
218
|
-
* @param getMin - If `true`, compute global minimum distance.
|
|
219
|
-
* @param genPath - If `true`, generate path arrays via predecessor map.
|
|
220
|
-
* @returns Result bag including distances, predecessors, and optional cycle flag.
|
|
221
|
-
* @remarks Time O(V * E), Space O(V + E)
|
|
222
|
-
*/
|
|
223
|
-
bellmanFord(src: VO | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
|
|
224
|
-
hasNegativeCycle: boolean | undefined;
|
|
225
|
-
distMap: Map<VO, number>;
|
|
226
|
-
preMap: Map<VO, VO>;
|
|
227
|
-
paths: VO[][];
|
|
228
|
-
min: number;
|
|
229
|
-
minPath: VO[];
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Floyd–Warshall all-pairs shortest paths.
|
|
233
|
-
* @returns `{ costs, predecessor }` matrices.
|
|
234
|
-
* @remarks Time O(V^3), Space O(V^2)
|
|
235
|
-
*/
|
|
236
|
-
floydWarshall(): {
|
|
237
|
-
costs: number[][];
|
|
238
|
-
predecessor: (VO | undefined)[][];
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Enumerate simple cycles (may be expensive).
|
|
242
|
-
* @param isInclude2Cycle - If `true`, include 2-cycles when graph semantics allow.
|
|
243
|
-
* @returns Array of cycles (each as array of vertex keys).
|
|
244
|
-
* @remarks Time exponential in worst-case, Space O(V + E)
|
|
245
|
-
*/
|
|
246
|
-
getCycles(isInclude2Cycle?: boolean): VertexKey[][];
|
|
247
|
-
/**
|
|
248
|
-
* Induced-subgraph filter: keep vertices where `predicate(key, value)` is true,
|
|
249
|
-
* and only keep edges whose endpoints both survive.
|
|
250
|
-
* @param predicate - `(key, value, index, self) => boolean`.
|
|
251
|
-
* @param thisArg - Optional `this` for callback.
|
|
252
|
-
* @returns A new graph of the same concrete class (`this` type).
|
|
253
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
254
|
-
*/
|
|
255
|
-
filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): this;
|
|
256
|
-
/**
|
|
257
|
-
* Preserve the old behavior: return filtered entries as an array.
|
|
258
|
-
* @remarks Time O(V), Space O(V)
|
|
259
|
-
*/
|
|
260
|
-
filterEntries(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
|
|
261
|
-
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
|
|
262
|
-
/**
|
|
263
|
-
* Create a deep clone of the graph with the same species.
|
|
264
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
265
|
-
*/
|
|
266
|
-
/**
|
|
267
|
-
* Create a deep clone of the graph with the same species.
|
|
268
|
-
* @returns A new graph of the same concrete class (`this` type).
|
|
269
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
270
|
-
*/
|
|
271
|
-
clone(): this;
|
|
272
|
-
/**
|
|
273
|
-
* Internal iterator over `[key, value]` entries in insertion order.
|
|
274
|
-
* @returns Iterator of `[VertexKey, V | undefined]`.
|
|
275
|
-
* @remarks Time O(V), Space O(1)
|
|
276
|
-
*/
|
|
277
|
-
protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
|
|
278
|
-
/**
|
|
279
|
-
* Capture configuration needed to reproduce the current graph.
|
|
280
|
-
* Currently the graph has no runtime options, so we return an empty object.
|
|
281
|
-
*/
|
|
282
|
-
/**
|
|
283
|
-
* Capture configuration needed to reproduce the current graph.
|
|
284
|
-
* @returns Options bag (opaque to callers).
|
|
285
|
-
* @remarks Time O(1), Space O(1)
|
|
286
|
-
*/
|
|
287
|
-
protected _snapshotOptions(): Record<string, unknown>;
|
|
288
|
-
/**
|
|
289
|
-
* Create an empty graph instance of the same concrete species (Directed/Undirected/etc).
|
|
290
|
-
* @remarks Time O(1), Space O(1)
|
|
291
|
-
*/
|
|
292
|
-
/**
|
|
293
|
-
* Create an empty graph instance of the same concrete species.
|
|
294
|
-
* @param _options - Snapshot options from `_snapshotOptions()`.
|
|
295
|
-
* @returns A new empty graph instance of `this` type.
|
|
296
|
-
* @remarks Time O(1), Space O(1)
|
|
297
|
-
*/
|
|
298
|
-
protected _createInstance(_options?: Partial<Record<string, unknown>>): this;
|
|
299
|
-
/**
|
|
300
|
-
* Create a same-species graph populated with the given entries.
|
|
301
|
-
* Also preserves edges between kept vertices from the source graph.
|
|
302
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
303
|
-
*/
|
|
304
|
-
/**
|
|
305
|
-
* Create a same-species graph populated with entries; preserves edges among kept vertices.
|
|
306
|
-
* @param iter - Optional entries to seed the new graph.
|
|
307
|
-
* @param options - Snapshot options.
|
|
308
|
-
* @returns A new graph of `this` type.
|
|
309
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
310
|
-
*/
|
|
311
|
-
protected _createLike(iter?: Iterable<[VertexKey, V | undefined]>, options?: Partial<Record<string, unknown>>): this;
|
|
312
|
-
/**
|
|
313
|
-
* Internal hook to attach an edge into adjacency structures.
|
|
314
|
-
* @param edge - Edge instance.
|
|
315
|
-
* @returns `true` if inserted; otherwise `false`.
|
|
316
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
317
|
-
*/
|
|
318
|
-
protected abstract _addEdge(edge: EO): boolean;
|
|
319
|
-
/**
|
|
320
|
-
* Insert a pre-built vertex into the graph.
|
|
321
|
-
* @param newVertex - Concrete vertex instance.
|
|
322
|
-
* @returns `true` if inserted; `false` if key already exists.
|
|
323
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
324
|
-
*/
|
|
325
|
-
protected _addVertex(newVertex: VO): boolean;
|
|
326
|
-
/**
|
|
327
|
-
* Resolve a vertex key or instance to the concrete vertex instance.
|
|
328
|
-
* @param vertexOrKey - Vertex key or existing vertex.
|
|
329
|
-
* @returns Vertex instance or `undefined`.
|
|
330
|
-
* @remarks Time O(1), Space O(1)
|
|
331
|
-
*/
|
|
332
|
-
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
333
|
-
/**
|
|
334
|
-
* Resolve a vertex key from a key or vertex instance.
|
|
335
|
-
* @param vertexOrKey - Vertex key or existing vertex.
|
|
336
|
-
* @returns The vertex key.
|
|
337
|
-
* @remarks Time O(1), Space O(1)
|
|
338
|
-
*/
|
|
339
|
-
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
340
|
-
}
|