data-structure-typed 1.35.0 → 1.36.0
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/.github/workflows/ci.yml +3 -0
- package/CHANGELOG.md +8 -1
- package/CONTRIBUTING.md +18 -0
- package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +21 -0
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +270 -7
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +100 -0
- package/dist/data-structures/heap/heap.js +215 -76
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +12 -0
- package/dist/data-structures/heap/max-heap.js +16 -6
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +12 -0
- package/dist/data-structures/heap/min-heap.js +16 -6
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +16 -17
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +16 -17
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/priority-queue.js +11 -174
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +1 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/lib/data-structures/graph/abstract-graph.js +3 -5
- package/lib/data-structures/heap/heap.d.ts +85 -68
- package/lib/data-structures/heap/heap.js +186 -108
- package/lib/data-structures/heap/max-heap.d.ts +6 -17
- package/lib/data-structures/heap/max-heap.js +11 -17
- package/lib/data-structures/heap/min-heap.d.ts +6 -18
- package/lib/data-structures/heap/min-heap.js +11 -18
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +5 -8
- package/lib/data-structures/priority-queue/max-priority-queue.js +11 -30
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +5 -8
- package/lib/data-structures/priority-queue/min-priority-queue.js +11 -31
- package/lib/data-structures/priority-queue/priority-queue.d.ts +6 -174
- package/lib/data-structures/priority-queue/priority-queue.js +11 -315
- package/lib/types/data-structures/heap.d.ts +1 -3
- package/package.json +11 -7
- package/src/data-structures/graph/abstract-graph.ts +3 -5
- package/src/data-structures/heap/heap.ts +182 -140
- package/src/data-structures/heap/max-heap.ts +15 -22
- package/src/data-structures/heap/min-heap.ts +15 -23
- package/src/data-structures/priority-queue/max-priority-queue.ts +14 -47
- package/src/data-structures/priority-queue/min-priority-queue.ts +14 -48
- package/src/data-structures/priority-queue/priority-queue.ts +7 -350
- package/src/types/data-structures/heap.ts +1 -5
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +8 -8
- package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +26 -18
- package/test/unit/data-structures/heap/max-heap.test.ts +50 -42
- package/test/unit/data-structures/heap/min-heap.test.ts +38 -68
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -9
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +14 -30
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.LICENSE.txt +8 -0
- package/umd/bundle.min.js.map +1 -1
- package/test/unit/data-structures/graph/index.ts +0 -2
- package/test/unit/data-structures/linked-list/index.ts +0 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AVLTreeNode } from '../data-structures';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
+
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BSTNode } from '../data-structures';
|
|
2
|
+
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
|
+
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './abstract-binary-tree';
|
|
2
|
+
export * from './abstract-graph';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './binary-tree';
|
|
5
|
+
export * from './bst';
|
|
6
|
+
export * from './directed-graph';
|
|
7
|
+
export * from './doubly-linked-list';
|
|
8
|
+
export * from './heap';
|
|
9
|
+
export * from './navigator';
|
|
10
|
+
export * from './priority-queue';
|
|
11
|
+
export * from './rb-tree';
|
|
12
|
+
export * from './segment-tree';
|
|
13
|
+
export * from './singly-linked-list';
|
|
14
|
+
export * from './tree-multiset';
|
|
15
|
+
export * from './undirected-graph';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RBTreeNode } from '../data-structures';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TreeMultisetNode } from '../data-structures';
|
|
2
|
+
import { IAVLTree, IAVLTreeNode } from './avl-tree';
|
|
3
|
+
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IAVLTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AbstractBinaryTreeNode } from '../../data-structures';
|
|
2
|
+
/**
|
|
3
|
+
* Enum representing different loop types.
|
|
4
|
+
*
|
|
5
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
6
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
7
|
+
*/
|
|
8
|
+
export declare enum LoopType {
|
|
9
|
+
ITERATIVE = "ITERATIVE",
|
|
10
|
+
RECURSIVE = "RECURSIVE"
|
|
11
|
+
}
|
|
12
|
+
export declare enum FamilyPosition {
|
|
13
|
+
ROOT = "ROOT",
|
|
14
|
+
LEFT = "LEFT",
|
|
15
|
+
RIGHT = "RIGHT",
|
|
16
|
+
ROOT_LEFT = "ROOT_LEFT",
|
|
17
|
+
ROOT_RIGHT = "ROOT_RIGHT",
|
|
18
|
+
ISOLATED = "ISOLATED",
|
|
19
|
+
MAL_NODE = "MAL_NODE"
|
|
20
|
+
}
|
|
21
|
+
export type BinaryTreeNodePropertyName = 'key' | 'val';
|
|
22
|
+
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
23
|
+
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
24
|
+
export type BinaryTreeNodeKey = number;
|
|
25
|
+
export type BinaryTreeDeletedResult<N> = {
|
|
26
|
+
deleted: N | null | undefined;
|
|
27
|
+
needBalanced: N | null;
|
|
28
|
+
};
|
|
29
|
+
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeKey;
|
|
30
|
+
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
|
|
31
|
+
export type AbstractBinaryTreeNodeNested<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
32
|
+
export type AbstractBinaryTreeOptions = {
|
|
33
|
+
loopType?: LoopType;
|
|
34
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FamilyPosition = exports.LoopType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing different loop types.
|
|
6
|
+
*
|
|
7
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
8
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
9
|
+
*/
|
|
4
10
|
var LoopType;
|
|
5
11
|
(function (LoopType) {
|
|
6
12
|
LoopType["ITERATIVE"] = "ITERATIVE";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-binary-tree.js","sourceRoot":"","sources":["../../../src/types/data-structures/abstract-binary-tree.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"abstract-binary-tree.js","sourceRoot":"","sources":["../../../src/types/data-structures/abstract-binary-tree.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AAEH,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,mCAAuB,CAAA;IACvB,mCAAuB,CAAA;AACzB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED,IAAY,cAQX;AARD,WAAY,cAAc;IACxB,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,iCAAe,CAAA;IACf,yCAAuB,CAAA;IACvB,2CAAyB,CAAA;IACzB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EARW,cAAc,8BAAd,cAAc,QAQzB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type VertexKey = string | number;
|
|
2
|
+
export type EdgeKey = string;
|
|
3
|
+
export type DijkstraResult<V> = {
|
|
4
|
+
distMap: Map<V, number>;
|
|
5
|
+
distPaths?: Map<V, V[]>;
|
|
6
|
+
preMap: Map<V, V | null>;
|
|
7
|
+
seen: Set<V>;
|
|
8
|
+
paths: V[][];
|
|
9
|
+
minDist: number;
|
|
10
|
+
minPath: V[];
|
|
11
|
+
} | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AVLTreeNode } from '../../data-structures';
|
|
2
|
+
import { BSTOptions } from './bst';
|
|
3
|
+
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
|
|
3
|
+
export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type BinaryTreeOptions = AbstractBinaryTreeOptions & {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BSTNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
+
import { BinaryTreeNodeKey } from './abstract-binary-tree';
|
|
4
|
+
export type BSTComparator = (a: BinaryTreeNodeKey, b: BinaryTreeNodeKey) => number;
|
|
5
|
+
export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTOptions = BinaryTreeOptions & {
|
|
7
|
+
comparator?: BSTComparator;
|
|
8
|
+
};
|
|
9
|
+
export declare enum CP {
|
|
10
|
+
lt = "lt",
|
|
11
|
+
eq = "eq",
|
|
12
|
+
gt = "gt"
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type HashFunction<K> = (key: K) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type CompareFunction<T> = (a: T, b: T) => number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './binary-tree';
|
|
2
|
+
export * from './bst';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './segment-tree';
|
|
5
|
+
export * from './tree-multiset';
|
|
6
|
+
export * from './abstract-graph';
|
|
7
|
+
export * from './map-graph';
|
|
8
|
+
export * from './abstract-binary-tree';
|
|
9
|
+
export * from './rb-tree';
|
|
10
|
+
export * from './directed-graph';
|
|
11
|
+
export * from './priority-queue';
|
|
12
|
+
export * from './heap';
|
|
13
|
+
export * from './singly-linked-list';
|
|
14
|
+
export * from './doubly-linked-list';
|
|
15
|
+
export * from './navigator';
|
|
16
|
+
export * from './hash';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MapGraphCoordinate = [number, number];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Direction = 'up' | 'right' | 'down' | 'left';
|
|
2
|
+
export type Turning = {
|
|
3
|
+
[key in Direction]: Direction;
|
|
4
|
+
};
|
|
5
|
+
export type NavigatorParams<T = any> = {
|
|
6
|
+
matrix: T[][];
|
|
7
|
+
turning: Turning;
|
|
8
|
+
onMove: (cur: [number, number]) => void;
|
|
9
|
+
init: {
|
|
10
|
+
cur: [number, number];
|
|
11
|
+
charDir: Direction;
|
|
12
|
+
VISITED: T;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BinaryTreeOptions } from './binary-tree';
|
|
2
|
+
import { RBTreeNode } from '../../data-structures/binary-tree';
|
|
3
|
+
export declare enum RBColor {
|
|
4
|
+
RED = "RED",
|
|
5
|
+
BLACK = "BLACK"
|
|
6
|
+
}
|
|
7
|
+
export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
8
|
+
export type RBTreeOptions = BinaryTreeOptions & {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SegmentTreeNodeVal = number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TreeMultisetNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import { AVLTreeOptions } from './avl-tree';
|
|
3
|
+
export type TreeMultisetNodeNested<T> = TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeByKey'> & {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
3
|
+
__THUNK__: symbol;
|
|
4
|
+
};
|
|
5
|
+
export type TrlFn = (...args: any[]) => any;
|
|
6
|
+
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
|
+
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type KeyValueObject = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type KeyValueObjectWithKey = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
key: string | number | symbol;
|
|
7
|
+
};
|
|
8
|
+
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
9
|
+
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
|
|
10
|
+
export type ObjectWithNonNumberKey = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
key: string | boolean | symbol | null | object | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type ObjectWithNumberKey = {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
key: number;
|
|
17
|
+
};
|
|
18
|
+
export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;
|
|
19
|
+
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | ((...args: []) => any) | never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
9
|
+
export declare const uuidV4: () => string;
|
|
10
|
+
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
11
|
+
export declare const THUNK_SYMBOL: unique symbol;
|
|
12
|
+
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
13
|
+
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
14
|
+
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
15
|
+
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
16
|
+
};
|
|
17
|
+
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
18
|
+
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
19
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { arrayRemove, uuidV4 } from '../../utils';
|
|
@@ -523,9 +523,7 @@ export class AbstractGraph {
|
|
|
523
523
|
if (vertexOrKey instanceof AbstractVertex)
|
|
524
524
|
distMap.set(vertexOrKey, Infinity);
|
|
525
525
|
}
|
|
526
|
-
const heap = new PriorityQueue(
|
|
527
|
-
comparator: (a, b) => a.key - b.key
|
|
528
|
-
});
|
|
526
|
+
const heap = new PriorityQueue((a, b) => a.key - b.key);
|
|
529
527
|
heap.add({ key: 0, val: srcVertex });
|
|
530
528
|
distMap.set(srcVertex, 0);
|
|
531
529
|
preMap.set(srcVertex, null);
|
|
@@ -1,83 +1,100 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Kirk Qi
|
|
5
|
+
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
import type { CompareFunction } from '../../types';
|
|
9
|
+
export declare class Heap<T> {
|
|
10
|
+
private nodes;
|
|
11
|
+
private readonly comparator;
|
|
12
|
+
constructor(comparator: CompareFunction<T>);
|
|
13
|
+
/**
|
|
14
|
+
* Insert an element into the heap and maintain the heap properties.
|
|
15
|
+
* @param value - The element to be inserted.
|
|
16
|
+
*/
|
|
17
|
+
add(value: T): Heap<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
20
|
+
* @returns The top element or null if the heap is empty.
|
|
21
|
+
*/
|
|
22
|
+
poll(): T | null;
|
|
23
|
+
/**
|
|
24
|
+
* Float operation to maintain heap properties after adding an element.
|
|
25
|
+
* @param index - The index of the newly added element.
|
|
26
|
+
*/
|
|
27
|
+
protected bubbleUp(index: number): void;
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
29
|
+
* Sinking operation to maintain heap properties after removing the top element.
|
|
30
|
+
* @param index - The index from which to start sinking.
|
|
31
31
|
*/
|
|
32
|
-
protected
|
|
33
|
-
protected abstract _pq: PriorityQueue<HeapItem<V>>;
|
|
34
|
-
get pq(): PriorityQueue<HeapItem<V>>;
|
|
35
|
-
protected _priorityExtractor: (val: V) => number;
|
|
36
|
-
get priorityExtractor(): (val: V) => number;
|
|
32
|
+
protected sinkDown(index: number): void;
|
|
37
33
|
/**
|
|
38
|
-
*
|
|
39
|
-
|
|
34
|
+
* Fix the entire heap to maintain heap properties.
|
|
35
|
+
*/
|
|
36
|
+
protected fix(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Peek at the top element of the heap without removing it.
|
|
39
|
+
* @returns The top element or null if the heap is empty.
|
|
40
|
+
*/
|
|
41
|
+
peek(): T | null;
|
|
42
|
+
/**
|
|
43
|
+
* Get the size (number of elements) of the heap.
|
|
40
44
|
*/
|
|
41
45
|
get size(): number;
|
|
42
46
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @returns
|
|
47
|
+
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
48
|
+
* @returns The last element or null if the heap is empty.
|
|
45
49
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
peekLast(isItem?: undefined): V | undefined;
|
|
51
|
-
peekLast(isItem: false): V | undefined;
|
|
52
|
-
peekLast(isItem: true): HeapItem<V> | null;
|
|
53
|
-
/**
|
|
54
|
-
* The `add` function adds an val to a priority queue with an optional priority value.
|
|
55
|
-
* @param {V} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
|
|
56
|
-
* type.
|
|
57
|
-
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
58
|
-
* val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
|
|
59
|
-
* the value of `val`. If the `val` parameter is not a number, then the
|
|
60
|
-
* @returns The `add` method returns the instance of the `Heap` class.
|
|
61
|
-
* @throws {Error} if priority is not a valid number
|
|
62
|
-
*/
|
|
63
|
-
add(priority: number, val?: V): Heap<V>;
|
|
64
|
-
poll(isItem?: undefined): V | undefined;
|
|
65
|
-
poll(isItem: false): V | undefined;
|
|
66
|
-
poll(isItem: true): HeapItem<V> | null;
|
|
67
|
-
/**
|
|
68
|
-
* The function checks if a given node or value exists in the priority queue.
|
|
69
|
-
* @param {V | HeapItem<V>} node - The parameter `node` can be of type `V` or `HeapItem<V>`.
|
|
70
|
-
* @returns a boolean value.
|
|
71
|
-
*/
|
|
72
|
-
has(node: V | HeapItem<V>): boolean;
|
|
73
|
-
toArray(isItem?: undefined): (V | undefined)[];
|
|
74
|
-
toArray(isItem: false): (V | undefined)[];
|
|
75
|
-
toArray(isItem: true): (HeapItem<V> | null)[];
|
|
76
|
-
sort(isItem?: undefined): (V | undefined)[];
|
|
77
|
-
sort(isItem: false): (V | undefined)[];
|
|
78
|
-
sort(isItem: true): (HeapItem<V> | null)[];
|
|
79
|
-
/**
|
|
80
|
-
* The clear function clears the priority queue.
|
|
50
|
+
leaf(): T | null;
|
|
51
|
+
/**
|
|
52
|
+
* Check if the heap is empty.
|
|
53
|
+
* @returns True if the heap is empty, otherwise false.
|
|
81
54
|
*/
|
|
55
|
+
isEmpty(): boolean;
|
|
82
56
|
clear(): void;
|
|
57
|
+
refill(nodes: T[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
60
|
+
* @param value - the element to check.
|
|
61
|
+
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
|
62
|
+
*/
|
|
63
|
+
has(value: T): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Use a comparison function to find the index of an element in the heap.
|
|
66
|
+
* @param value - the element to find.
|
|
67
|
+
* @param index - the index currently being searched.
|
|
68
|
+
* @returns The index of the element, or -1 if not found.
|
|
69
|
+
*/
|
|
70
|
+
private findIndex;
|
|
71
|
+
/**
|
|
72
|
+
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
73
|
+
* @param order - Traversal order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
74
|
+
* @returns An array containing elements traversed in the specified order.
|
|
75
|
+
*/
|
|
76
|
+
dfs(order: 'in' | 'pre' | 'post'): T[];
|
|
77
|
+
/**
|
|
78
|
+
* Convert the heap to an array.
|
|
79
|
+
* @returns An array containing the elements of the heap.
|
|
80
|
+
*/
|
|
81
|
+
toArray(): T[];
|
|
82
|
+
getNodes(): T[];
|
|
83
|
+
/**
|
|
84
|
+
* Clone the heap, creating a new heap with the same elements.
|
|
85
|
+
* @returns A new Heap instance containing the same elements.
|
|
86
|
+
*/
|
|
87
|
+
clone(): Heap<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Sort the elements in the heap and return them as an array.
|
|
90
|
+
* @returns An array containing the elements sorted in ascending order.
|
|
91
|
+
*/
|
|
92
|
+
sort(): T[];
|
|
93
|
+
/**
|
|
94
|
+
* Static method that creates a binary heap from an array of nodes and a comparison function.
|
|
95
|
+
* @param nodes
|
|
96
|
+
* @param comparator - Comparison function.
|
|
97
|
+
* @returns A new Heap instance.
|
|
98
|
+
*/
|
|
99
|
+
static heapify<T>(nodes: T[], comparator: CompareFunction<T>): Heap<T>;
|
|
83
100
|
}
|