data-structure-typed 0.8.6 → 0.8.17

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 (57) hide show
  1. package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +21 -0
  3. package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +140 -0
  6. package/dist/data-structures/binary-tree/bst.d.ts +32 -0
  7. package/dist/data-structures/binary-tree/index.d.ts +4 -0
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -0
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +33 -0
  10. package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +11 -0
  12. package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  13. package/dist/data-structures/graph/abstract-graph.d.ts +126 -0
  14. package/dist/data-structures/graph/directed-graph.d.ts +51 -0
  15. package/dist/data-structures/graph/index.d.ts +3 -0
  16. package/dist/data-structures/graph/undirected-graph.d.ts +24 -0
  17. package/dist/data-structures/hash/coordinate-map.d.ts +8 -0
  18. package/dist/data-structures/hash/coordinate-set.d.ts +7 -0
  19. package/dist/data-structures/hash/hash-table.d.ts +1 -0
  20. package/dist/data-structures/hash/index.d.ts +1 -0
  21. package/dist/data-structures/hash/pair.d.ts +1 -0
  22. package/dist/data-structures/hash/tree-map.d.ts +1 -0
  23. package/dist/data-structures/hash/tree-set.d.ts +1 -0
  24. package/dist/data-structures/heap/heap.d.ts +72 -0
  25. package/dist/data-structures/heap/index.d.ts +3 -0
  26. package/dist/data-structures/heap/max-heap.d.ts +14 -0
  27. package/dist/data-structures/heap/min-heap.d.ts +14 -0
  28. package/dist/data-structures/index.d.ts +9 -0
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +59 -0
  30. package/dist/data-structures/linked-list/index.d.ts +2 -0
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +358 -0
  32. package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  33. package/dist/data-structures/matrix/index.d.ts +4 -0
  34. package/dist/data-structures/matrix/index.js +1 -0
  35. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  36. package/dist/data-structures/matrix/matrix2d.d.ts +25 -0
  37. package/dist/data-structures/matrix/navigator.d.ts +31 -0
  38. package/dist/data-structures/matrix/vector2d.d.ts +74 -0
  39. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  40. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -0
  41. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -0
  42. package/dist/data-structures/priority-queue/priority-queue.d.ts +36 -0
  43. package/dist/data-structures/queue/deque.d.ts +37 -0
  44. package/dist/data-structures/queue/index.d.ts +1 -0
  45. package/dist/data-structures/queue/queue.d.ts +76 -0
  46. package/dist/data-structures/stack/index.d.ts +1 -0
  47. package/dist/data-structures/stack/stack.d.ts +69 -0
  48. package/dist/data-structures/trampoline.d.ts +25 -0
  49. package/dist/data-structures/trie/index.d.ts +1 -0
  50. package/dist/data-structures/trie/trie.d.ts +28 -0
  51. package/dist/index.d.ts +1 -0
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/utils.d.ts +37 -113
  54. package/dist/utils.d.ts +122 -0
  55. package/package.json +4 -3
  56. package/src/data-structures/matrix/index.ts +1 -0
  57. package/tsconfig.json +3 -2
@@ -0,0 +1,2 @@
1
+ export declare class AaTree {
2
+ }
@@ -0,0 +1,21 @@
1
+ import { BST, BSTNode } from './bst';
2
+ import { BinaryTreeNodeId } from './binary-tree';
3
+ export interface AVLTreeDeleted<T> {
4
+ deleted: AVLTreeNode<T> | null;
5
+ needBalanced: AVLTreeNode<T> | null;
6
+ }
7
+ export declare class AVLTreeNode<T> extends BSTNode<T> {
8
+ clone(): AVLTreeNode<T>;
9
+ }
10
+ export declare class AVLTree<T> extends BST<T> {
11
+ createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
12
+ put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
13
+ remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[];
14
+ balanceFactor(node: AVLTreeNode<T>): number;
15
+ updateHeight(node: AVLTreeNode<T>): void;
16
+ balancePath(node: AVLTreeNode<T>): void;
17
+ balanceLL(A: AVLTreeNode<T>): void;
18
+ balanceLR(A: AVLTreeNode<T>): void;
19
+ balanceRR(A: AVLTreeNode<T>): void;
20
+ balanceRL(A: AVLTreeNode<T>): void;
21
+ }
@@ -0,0 +1,2 @@
1
+ export declare class BTree {
2
+ }
@@ -0,0 +1,8 @@
1
+ export declare class BinaryIndexedTree {
2
+ private readonly _sumTree;
3
+ constructor(n: number);
4
+ update(i: number, delta: number): void;
5
+ getPrefixSum(i: number): number;
6
+ getRangeSum(start: number, end: number): number;
7
+ static lowBit(x: number): number;
8
+ }
@@ -0,0 +1,140 @@
1
+ export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
2
+ export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
3
+ export type DFSOrderPattern = 'in' | 'pre' | 'post';
4
+ export type BinaryTreeNodeId = number;
5
+ export type BinaryTreeDeleted<T> = {
6
+ deleted: BinaryTreeNode<T> | null | undefined;
7
+ needBalanced: BinaryTreeNode<T> | null;
8
+ };
9
+ export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
10
+ export type ResultsByProperty<T> = ResultByProperty<T>[];
11
+ export interface BinaryTreeNodeObj<T> {
12
+ id: BinaryTreeNodeId;
13
+ val: T;
14
+ count?: number;
15
+ }
16
+ export declare enum FamilyPosition {
17
+ root = 0,
18
+ left = 1,
19
+ right = 2
20
+ }
21
+ export declare enum LoopType {
22
+ iterative = 1,
23
+ recursive = 2
24
+ }
25
+ export declare class BinaryTreeNode<T> {
26
+ protected _id: BinaryTreeNodeId;
27
+ get id(): BinaryTreeNodeId;
28
+ set id(v: BinaryTreeNodeId);
29
+ protected _val: T;
30
+ get val(): T;
31
+ set val(v: T);
32
+ protected _left?: BinaryTreeNode<T> | null;
33
+ get left(): BinaryTreeNode<T> | null | undefined;
34
+ set left(v: BinaryTreeNode<T> | null | undefined);
35
+ protected _right?: BinaryTreeNode<T> | null;
36
+ get right(): BinaryTreeNode<T> | null | undefined;
37
+ set right(v: BinaryTreeNode<T> | null | undefined);
38
+ protected _parent: BinaryTreeNode<T> | null | undefined;
39
+ get parent(): BinaryTreeNode<T> | null | undefined;
40
+ set parent(v: BinaryTreeNode<T> | null | undefined);
41
+ protected _familyPosition: FamilyPosition;
42
+ get familyPosition(): FamilyPosition;
43
+ set familyPosition(v: FamilyPosition);
44
+ protected _count: number;
45
+ get count(): number;
46
+ set count(v: number);
47
+ protected _height: number;
48
+ get height(): number;
49
+ set height(v: number);
50
+ constructor(id: BinaryTreeNodeId, val: T, count?: number);
51
+ swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
52
+ clone(): BinaryTreeNode<T>;
53
+ }
54
+ export declare class BinaryTree<T> {
55
+ protected _root: BinaryTreeNode<T> | null;
56
+ get root(): BinaryTreeNode<T> | null;
57
+ protected set root(v: BinaryTreeNode<T> | null);
58
+ protected _size: number;
59
+ get size(): number;
60
+ protected set size(v: number);
61
+ protected _count: number;
62
+ get count(): number;
63
+ protected set count(v: number);
64
+ private readonly _autoIncrementId;
65
+ private _maxId;
66
+ private readonly _isDuplicatedVal;
67
+ protected _loopType: LoopType;
68
+ protected _visitedId: BinaryTreeNodeId[];
69
+ protected _visitedVal: Array<T>;
70
+ protected _visitedNode: BinaryTreeNode<T>[];
71
+ protected _visitedCount: number[];
72
+ protected _visitedLeftSum: number[];
73
+ protected _resetResults(): void;
74
+ constructor(options?: {
75
+ loopType?: LoopType;
76
+ autoIncrementId?: boolean;
77
+ isDuplicatedVal?: boolean;
78
+ });
79
+ createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
80
+ clear(): void;
81
+ isEmpty(): boolean;
82
+ insertTo({ newNode, parent }: {
83
+ newNode: BinaryTreeNode<T> | null;
84
+ parent: BinaryTreeNode<T>;
85
+ }): BinaryTreeNode<T> | null | undefined;
86
+ put(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
87
+ insertMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
88
+ fill(data: T[] | BinaryTreeNode<T>[]): boolean;
89
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<T>[];
90
+ getDepth(node: BinaryTreeNode<T>): number;
91
+ getHeight(beginRoot?: BinaryTreeNode<T> | null): number;
92
+ getMinHeight(beginRoot?: BinaryTreeNode<T> | null): number;
93
+ isBalanced(beginRoot?: BinaryTreeNode<T> | null): boolean;
94
+ getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (BinaryTreeNode<T> | null | undefined)[];
95
+ has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
96
+ get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
97
+ getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
98
+ protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
99
+ protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
100
+ protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
101
+ getLeftMost(): BinaryTreeNode<T> | null;
102
+ getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
103
+ getRightMost(): BinaryTreeNode<T> | null;
104
+ getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
105
+ isBST(node?: BinaryTreeNode<T> | null): boolean;
106
+ getSubTreeSizeAndCount(subTreeRoot: BinaryTreeNode<T> | null | undefined): [number, number];
107
+ subTreeSum(subTreeRoot: BinaryTreeNode<T>, propertyName?: BinaryTreeNodePropertyName): number;
108
+ subTreeAdd(subTreeRoot: BinaryTreeNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
+ BFS(): BinaryTreeNodeId[];
110
+ BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
111
+ BFS(nodeOrPropertyName: 'val'): T[];
112
+ BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
113
+ BFS(nodeOrPropertyName: 'count'): number[];
114
+ DFS(): BinaryTreeNodeId[];
115
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
116
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
117
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
118
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
119
+ DFSIterative(): BinaryTreeNodeId[];
120
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
121
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
122
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
123
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
124
+ levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
125
+ levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
126
+ levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
127
+ levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
128
+ levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
129
+ listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
130
+ listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
131
+ listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
132
+ listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
133
+ listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
134
+ getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
135
+ morris(): BinaryTreeNodeId[];
136
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
137
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
138
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
139
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
140
+ }
@@ -0,0 +1,32 @@
1
+ import { BinaryTree, BinaryTreeNode, BinaryTreeNodeId, BinaryTreeNodePropertyName, LoopType } from './binary-tree';
2
+ export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
3
+ export type BSTDeletedResult<T> = {
4
+ deleted: BSTNode<T> | null;
5
+ needBalanced: BSTNode<T> | null;
6
+ };
7
+ export declare enum CP {
8
+ lt = -1,
9
+ eq = 0,
10
+ gt = 1
11
+ }
12
+ export declare class BSTNode<T> extends BinaryTreeNode<T> {
13
+ clone(): BSTNode<T>;
14
+ }
15
+ export declare class BST<T> extends BinaryTree<T> {
16
+ protected _comparator: BSTComparator;
17
+ protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP;
18
+ constructor(options?: {
19
+ comparator?: BSTComparator;
20
+ loopType?: LoopType;
21
+ });
22
+ createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
23
+ put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
24
+ get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
25
+ lastKey(): number;
26
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
27
+ getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
28
+ lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
29
+ allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
30
+ balance(): boolean;
31
+ isAVLBalanced(): boolean;
32
+ }
@@ -0,0 +1,4 @@
1
+ export * from './binary-tree';
2
+ export * from './bst';
3
+ export * from './binary-indexed-tree';
4
+ export * from './segment-tree';
@@ -0,0 +1,2 @@
1
+ export declare class RBTree {
2
+ }
@@ -0,0 +1,33 @@
1
+ export type SegmentTreeNodeVal = number;
2
+ export declare class SegmentTreeNode {
3
+ protected _start: number;
4
+ get start(): number;
5
+ set start(v: number);
6
+ protected _end: number;
7
+ get end(): number;
8
+ set end(v: number);
9
+ protected _val: SegmentTreeNodeVal | null;
10
+ get val(): SegmentTreeNodeVal | null;
11
+ set val(v: SegmentTreeNodeVal | null);
12
+ protected _sum: number;
13
+ get sum(): number;
14
+ set sum(v: number);
15
+ protected _left: SegmentTreeNode | null;
16
+ get left(): SegmentTreeNode | null;
17
+ set left(v: SegmentTreeNode | null);
18
+ protected _right: SegmentTreeNode | null;
19
+ get right(): SegmentTreeNode | null;
20
+ set right(v: SegmentTreeNode | null);
21
+ constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
22
+ }
23
+ export declare class SegmentTree {
24
+ protected _values: number[];
25
+ protected _start: number;
26
+ protected _end: number;
27
+ protected _root: SegmentTreeNode | null;
28
+ get root(): SegmentTreeNode | null;
29
+ constructor(values: number[], start?: number, end?: number);
30
+ build(start: number, end: number): SegmentTreeNode;
31
+ updateNode(index: number, sum: number, val?: SegmentTreeNodeVal): void;
32
+ querySumByRange(indexA: number, indexB: number): number;
33
+ }
@@ -0,0 +1,2 @@
1
+ export declare class SplayTree {
2
+ }
@@ -0,0 +1,11 @@
1
+ import { BST, BSTNode } from './bst';
2
+ import { BinaryTreeNodeId } from './binary-tree';
3
+ export type TreeMultiSetDeletedResult<T> = {
4
+ deleted: BSTNode<T> | null;
5
+ needBalanced: BSTNode<T> | null;
6
+ };
7
+ export declare class TreeMultiSet<T> extends BST<T> {
8
+ createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
9
+ put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
10
+ remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
11
+ }
@@ -0,0 +1,2 @@
1
+ export declare class TwoThreeTree {
2
+ }
@@ -0,0 +1,126 @@
1
+ export type VertexId = string | number;
2
+ export type DijkstraResult<V> = {
3
+ distMap: Map<V, number>;
4
+ preMap: Map<V, V | null>;
5
+ seen: Set<V>;
6
+ paths: V[][];
7
+ minDist: number;
8
+ minPath: V[];
9
+ } | null;
10
+ export interface I_Graph<V, E> {
11
+ containsVertex(vertexOrId: V | VertexId): boolean;
12
+ getVertex(vertexOrId: VertexId | V): V | null;
13
+ getVertexId(vertexOrId: V | VertexId): VertexId;
14
+ vertexSet(): Map<VertexId, V>;
15
+ addVertex(v: V): boolean;
16
+ removeVertex(vertexOrId: V | VertexId): boolean;
17
+ removeAllVertices(vertices: V[] | VertexId[]): boolean;
18
+ degreeOf(vertexOrId: V | VertexId): number;
19
+ edgesOf(vertexOrId: V | VertexId): E[];
20
+ containsEdge(src: V | VertexId, dest: V | VertexId): boolean;
21
+ getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
22
+ edgeSet(): E[];
23
+ addEdge(edge: E): boolean;
24
+ removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
25
+ removeEdge(edge: E): E | null;
26
+ setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
27
+ getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
28
+ getNeighbors(vertexOrId: V | VertexId): V[];
29
+ }
30
+ export declare class AbstractVertex {
31
+ private _id;
32
+ get id(): VertexId;
33
+ set id(v: VertexId);
34
+ constructor(id: VertexId);
35
+ }
36
+ export declare abstract class AbstractEdge {
37
+ private _weight;
38
+ get weight(): number;
39
+ set weight(v: number);
40
+ private _hashCode;
41
+ get hashCode(): string;
42
+ set hashCode(v: string);
43
+ protected constructor(weight?: number);
44
+ static DEFAULT_EDGE_WEIGHT: number;
45
+ }
46
+ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements I_Graph<V, E> {
47
+ protected _vertices: Map<VertexId, V>;
48
+ abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
49
+ abstract removeEdge(edge: E): E | null;
50
+ getVertex(vertexOrId: VertexId | V): V | null;
51
+ getVertexId(vertexOrId: V | VertexId): VertexId;
52
+ containsVertex(vertexOrId: V | VertexId): boolean;
53
+ vertexSet(): Map<VertexId, V>;
54
+ abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
55
+ addVertex(newVertex: V): boolean;
56
+ removeVertex(vertexOrId: V | VertexId): boolean;
57
+ removeAllVertices(vertices: V[] | VertexId[]): boolean;
58
+ abstract degreeOf(vertexOrId: V | VertexId): number;
59
+ abstract edgeSet(): E[];
60
+ abstract edgesOf(vertexOrId: V | VertexId): E[];
61
+ containsEdge(v1: VertexId | V, v2: VertexId | V): boolean;
62
+ abstract addEdge(edge: E): boolean;
63
+ setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
64
+ abstract getNeighbors(vertexOrId: V | VertexId): V[];
65
+ getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
66
+ getPathSumWeight(path: V[]): number;
67
+ getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
68
+ getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
69
+ /**
70
+ * Dijkstra algorithm time: O(VE) space: O(V + E)
71
+ * @param src
72
+ * @param dest
73
+ * @param getMinDist
74
+ * @param genPaths
75
+ */
76
+ dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
77
+ /**
78
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
79
+ * @param src
80
+ * @param dest
81
+ * @param getMinDist
82
+ * @param genPaths
83
+ */
84
+ dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
85
+ abstract getEndsOfEdge(edge: E): [V, V] | null;
86
+ /**
87
+ * BellmanFord time:O(VE) space:O(V)
88
+ * one to rest pairs
89
+ * @param src
90
+ * @param scanNegativeCycle
91
+ * @param getMin
92
+ * @param genPath
93
+ */
94
+ bellmanFord(src: V | VertexId, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
95
+ hasNegativeCycle: boolean | undefined;
96
+ distMap: Map<V, number>;
97
+ preMap: Map<V, V>;
98
+ paths: V[][];
99
+ min: number;
100
+ minPath: V[];
101
+ };
102
+ /**
103
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
104
+ * all pairs
105
+ */
106
+ floyd(): {
107
+ costs: number[][];
108
+ predecessor: (V | null)[][];
109
+ };
110
+ /**--- start find cycles --- */
111
+ /**
112
+ * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
113
+ * Tarjan can find cycles in directed or undirected graph
114
+ * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
115
+ * Tarjan solve the bi-connected components of undirected graphs;
116
+ * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
117
+ */
118
+ tarjan(needArticulationPoints?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
119
+ dfnMap: Map<V, number>;
120
+ lowMap: Map<V, number>;
121
+ bridges: E[];
122
+ articulationPoints: V[];
123
+ SCCs: Map<number, V[]>;
124
+ cycles: Map<number, V[]>;
125
+ };
126
+ }
@@ -0,0 +1,51 @@
1
+ import { AbstractEdge, AbstractGraph, AbstractVertex, VertexId } from './abstract-graph';
2
+ export declare class DirectedVertex extends AbstractVertex {
3
+ constructor(id: VertexId);
4
+ }
5
+ export declare class DirectedEdge extends AbstractEdge {
6
+ constructor(src: VertexId, dest: VertexId, weight?: number);
7
+ private _src;
8
+ get src(): VertexId;
9
+ set src(v: VertexId);
10
+ private _dest;
11
+ get dest(): VertexId;
12
+ set dest(v: VertexId);
13
+ }
14
+ export interface I_DirectedGraph<V, E> {
15
+ incomingEdgesOf(vertex: V): E[];
16
+ outgoingEdgesOf(vertex: V): E[];
17
+ inDegreeOf(vertexOrId: V | VertexId): number;
18
+ outDegreeOf(vertexOrId: V | VertexId): number;
19
+ getEdgeSrc(e: E): V | null;
20
+ getEdgeDest(e: E): V | null;
21
+ }
22
+ export type TopologicalStatus = 0 | 1 | 2;
23
+ export declare class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> extends AbstractGraph<V, E> implements I_DirectedGraph<V, E> {
24
+ protected _outEdgeMap: Map<V, E[]>;
25
+ protected _inEdgeMap: Map<V, E[]>;
26
+ constructor();
27
+ getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
28
+ addEdge(edge: E): boolean;
29
+ removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
30
+ removeEdge(edge: E): E | null;
31
+ removeAllEdges(src: VertexId | V, dest: VertexId | V): E[];
32
+ incomingEdgesOf(vertexOrId: V | VertexId): E[];
33
+ outgoingEdgesOf(vertexOrId: V | VertexId): E[];
34
+ degreeOf(vertexOrId: VertexId | V): number;
35
+ inDegreeOf(vertexOrId: VertexId | V): number;
36
+ outDegreeOf(vertexOrId: VertexId | V): number;
37
+ edgesOf(vertexOrId: VertexId | V): E[];
38
+ getEdgeSrc(e: E): V | null;
39
+ getEdgeDest(e: E): V | null;
40
+ getDestinations(vertex: V | null): V[];
41
+ /**--- start find cycles --- */
42
+ /**
43
+ * when stored with adjacency list time: O(V+E)
44
+ * when stored with adjacency matrix time: O(V^2)
45
+ */
46
+ topologicalSort(): V[] | null;
47
+ /**--- end find cycles --- */
48
+ edgeSet(): E[];
49
+ getNeighbors(vertexOrId: V | VertexId): V[];
50
+ getEndsOfEdge(edge: E): [V, V] | null;
51
+ }
@@ -0,0 +1,3 @@
1
+ export * from './abstract-graph';
2
+ export * from './directed-graph';
3
+ export * from './undirected-graph';
@@ -0,0 +1,24 @@
1
+ import { AbstractEdge, AbstractGraph, AbstractVertex, VertexId } from './abstract-graph';
2
+ export declare class UndirectedVertex extends AbstractVertex {
3
+ constructor(id: VertexId);
4
+ }
5
+ export declare class UndirectedEdge extends AbstractEdge {
6
+ private _vertices;
7
+ get vertices(): [VertexId, VertexId];
8
+ set vertices(v: [VertexId, VertexId]);
9
+ constructor(v1: VertexId, v2: VertexId, weight?: number);
10
+ }
11
+ export declare class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
12
+ constructor();
13
+ protected _edges: Map<V, E[]>;
14
+ getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
15
+ addEdge(edge: E): boolean;
16
+ removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
17
+ removeEdge(edge: E): E | null;
18
+ degreeOf(vertexOrId: VertexId | V): number;
19
+ edgesOf(vertexOrId: VertexId | V): E[];
20
+ edgeSet(): E[];
21
+ getEdgesOf(vertexOrId: V | VertexId): E[];
22
+ getNeighbors(vertexOrId: V | VertexId): V[];
23
+ getEndsOfEdge(edge: E): [V, V] | null;
24
+ }
@@ -0,0 +1,8 @@
1
+ export declare class CoordinateSet<V> extends Map<any, V> {
2
+ private readonly _joint;
3
+ constructor(joint?: string);
4
+ has(key: number[]): boolean;
5
+ set(key: number[], value: V): this;
6
+ get(key: number[]): V | undefined;
7
+ delete(key: number[]): boolean;
8
+ }
@@ -0,0 +1,7 @@
1
+ export declare class CoordinateSet extends Set {
2
+ private readonly _joint;
3
+ constructor(joint?: string);
4
+ has(value: number[]): boolean;
5
+ add(value: number[]): this;
6
+ delete(value: number[]): boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './hash-table';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { PriorityQueue } from '../priority-queue';
2
+ export interface HeapOptions<T> {
3
+ priority?: (element: T) => number;
4
+ }
5
+ export interface HeapItem<T> {
6
+ priority: number;
7
+ element: T | null;
8
+ }
9
+ /**
10
+ * @copyright 2021 Pablo Rios <zrwusa@gmail.com>
11
+ * @license MIT
12
+ *
13
+ * @abstract
14
+ * @class Heap
15
+ */
16
+ export declare abstract class Heap<T> {
17
+ protected abstract _pq: PriorityQueue<HeapItem<T>>;
18
+ protected _priorityCb: (element: T) => number;
19
+ /**
20
+ * Creates a priority queue
21
+ * @public
22
+ * @params {object} [options]
23
+ */
24
+ protected constructor(options?: HeapOptions<T>);
25
+ /**
26
+ * @public
27
+ * @returns {number}
28
+ */
29
+ get size(): number;
30
+ /**
31
+ * @public
32
+ * @returns {boolean}
33
+ */
34
+ isEmpty(): boolean;
35
+ /**
36
+ * Returns an element with highest priority in the queue
37
+ * @public
38
+ * @returns {object}
39
+ */
40
+ peek(): HeapItem<T> | null;
41
+ /**
42
+ * Returns an element with lowest priority in the queue
43
+ * @public
44
+ * @returns {object}
45
+ */
46
+ peekLast(): HeapItem<T> | null;
47
+ /**
48
+ * Adds an element to the queue
49
+ * @public
50
+ * @param {any} element
51
+ * @param priority
52
+ * @throws {Error} if priority is not a valid number
53
+ */
54
+ offer(element: T, priority?: number): Heap<T>;
55
+ /**
56
+ * Removes and returns an element with highest priority in the queue
57
+ * @public
58
+ * @returns {object}
59
+ */
60
+ poll(): HeapItem<T> | null;
61
+ /**
62
+ * Returns a sorted list of elements
63
+ * @public
64
+ * @returns {array}
65
+ */
66
+ toArray(): HeapItem<T>[];
67
+ /**
68
+ * Clears the queue
69
+ * @public
70
+ */
71
+ clear(): void;
72
+ }
@@ -0,0 +1,3 @@
1
+ export * from './max-heap';
2
+ export * from './min-heap';
3
+ export * from './heap';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import { Heap, HeapItem, HeapOptions } from './heap';
6
+ import { PriorityQueue } from '../priority-queue';
7
+ /**
8
+ * @class MaxHeap
9
+ * @extends Heap
10
+ */
11
+ export declare class MaxHeap<T> extends Heap<T> {
12
+ protected _pq: PriorityQueue<HeapItem<T>>;
13
+ constructor(options?: HeapOptions<T>);
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import { Heap, HeapItem, HeapOptions } from './heap';
6
+ import { PriorityQueue } from '../priority-queue';
7
+ /**
8
+ * @class MinHeap
9
+ * @extends Heap
10
+ */
11
+ export declare class MinHeap<T> extends Heap<T> {
12
+ protected _pq: PriorityQueue<HeapItem<T>>;
13
+ constructor(options?: HeapOptions<T>);
14
+ }
@@ -0,0 +1,9 @@
1
+ export * from './hash';
2
+ export * from './linked-list';
3
+ export * from './stack';
4
+ export * from './queue';
5
+ export * from './graph';
6
+ export * from './binary-tree';
7
+ export * from './heap';
8
+ export * from './priority-queue';
9
+ export * from './matrix';