data-structure-typed 1.18.6 → 1.18.7

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 (143) hide show
  1. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +48 -24
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.js +51 -26
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -4
  4. package/dist/data-structures/binary-tree/avl-tree.js +5 -3
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +13 -3
  6. package/dist/data-structures/binary-tree/binary-tree.js +14 -5
  7. package/dist/data-structures/binary-tree/bst.d.ts +26 -5
  8. package/dist/data-structures/binary-tree/bst.js +26 -4
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
  10. package/dist/data-structures/binary-tree/rb-tree.js +27 -14
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +15 -4
  12. package/dist/data-structures/binary-tree/tree-multiset.js +15 -3
  13. package/dist/data-structures/graph/abstract-graph.d.ts +20 -21
  14. package/dist/data-structures/graph/abstract-graph.js +24 -19
  15. package/dist/data-structures/graph/directed-graph.d.ts +10 -9
  16. package/dist/data-structures/graph/directed-graph.js +18 -18
  17. package/dist/data-structures/graph/undirected-graph.d.ts +5 -11
  18. package/dist/data-structures/graph/undirected-graph.js +4 -17
  19. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +101 -0
  20. package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
  21. package/dist/data-structures/interfaces/abstract-graph.d.ts +1 -4
  22. package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
  23. package/dist/data-structures/interfaces/binary-tree.d.ts +4 -24
  24. package/dist/data-structures/interfaces/bst.d.ts +18 -1
  25. package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
  26. package/dist/data-structures/interfaces/index.d.ts +1 -1
  27. package/dist/data-structures/interfaces/index.js +1 -1
  28. package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
  29. package/dist/data-structures/interfaces/rb-tree.js +2 -0
  30. package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
  31. package/dist/data-structures/types/abstract-binary-tree.d.ts +2 -2
  32. package/dist/utils/utils.js +62 -0
  33. package/docs/assets/search.js +1 -1
  34. package/docs/classes/AVLTree.html +292 -180
  35. package/docs/classes/AVLTreeNode.html +126 -77
  36. package/docs/classes/AaTree.html +12 -6
  37. package/docs/classes/AbstractBinaryTree.html +258 -163
  38. package/docs/classes/AbstractBinaryTreeNode.html +117 -84
  39. package/docs/classes/AbstractEdge.html +22 -16
  40. package/docs/classes/AbstractGraph.html +137 -140
  41. package/docs/classes/AbstractVertex.html +19 -13
  42. package/docs/classes/ArrayDeque.html +25 -19
  43. package/docs/classes/BST.html +275 -174
  44. package/docs/classes/BSTNode.html +127 -77
  45. package/docs/classes/BTree.html +12 -6
  46. package/docs/classes/BinaryIndexedTree.html +20 -14
  47. package/docs/classes/BinaryTree.html +265 -169
  48. package/docs/classes/BinaryTreeNode.html +110 -61
  49. package/docs/classes/Character.html +15 -9
  50. package/docs/classes/CoordinateMap.html +20 -14
  51. package/docs/classes/CoordinateSet.html +19 -13
  52. package/docs/classes/Deque.html +45 -39
  53. package/docs/classes/DirectedEdge.html +26 -20
  54. package/docs/classes/DirectedGraph.html +189 -154
  55. package/docs/classes/DirectedVertex.html +17 -11
  56. package/docs/classes/DoublyLinkedList.html +48 -42
  57. package/docs/classes/DoublyLinkedListNode.html +22 -16
  58. package/docs/classes/HashTable.html +12 -6
  59. package/docs/classes/Heap.html +26 -20
  60. package/docs/classes/HeapItem.html +19 -13
  61. package/docs/classes/Matrix2D.html +27 -21
  62. package/docs/classes/MatrixNTI2D.html +15 -9
  63. package/docs/classes/MaxHeap.html +26 -20
  64. package/docs/classes/MaxPriorityQueue.html +45 -39
  65. package/docs/classes/MinHeap.html +26 -20
  66. package/docs/classes/MinPriorityQueue.html +45 -39
  67. package/docs/classes/Navigator.html +21 -15
  68. package/docs/classes/ObjectDeque.html +36 -30
  69. package/docs/classes/Pair.html +12 -6
  70. package/docs/classes/PriorityQueue.html +43 -37
  71. package/docs/classes/Queue.html +25 -19
  72. package/docs/classes/RBTree.html +2388 -0
  73. package/docs/classes/RBTreeNode.html +516 -0
  74. package/docs/classes/SegmentTree.html +28 -22
  75. package/docs/classes/SegmentTreeNode.html +31 -25
  76. package/docs/classes/SinglyLinkedList.html +45 -39
  77. package/docs/classes/SinglyLinkedListNode.html +19 -13
  78. package/docs/classes/SkipLinkedList.html +12 -6
  79. package/docs/classes/SplayTree.html +12 -6
  80. package/docs/classes/Stack.html +23 -17
  81. package/docs/classes/TreeMap.html +12 -6
  82. package/docs/classes/TreeMultiSet.html +273 -172
  83. package/docs/classes/TreeMultiSetNode.html +126 -77
  84. package/docs/classes/TreeNode.html +27 -21
  85. package/docs/classes/TreeSet.html +12 -6
  86. package/docs/classes/Trie.html +24 -18
  87. package/docs/classes/TrieNode.html +22 -16
  88. package/docs/classes/TwoThreeTree.html +12 -6
  89. package/docs/classes/UndirectedEdge.html +23 -17
  90. package/docs/classes/UndirectedGraph.html +160 -146
  91. package/docs/classes/UndirectedVertex.html +17 -11
  92. package/docs/classes/Vector2D.html +39 -33
  93. package/docs/enums/CP.html +15 -9
  94. package/docs/enums/FamilyPosition.html +15 -9
  95. package/docs/enums/LoopType.html +14 -8
  96. package/docs/enums/RBColor.html +14 -8
  97. package/docs/enums/TopologicalProperty.html +15 -9
  98. package/docs/index.html +11 -5
  99. package/docs/interfaces/IAVLTree.html +1378 -0
  100. package/docs/interfaces/IAVLTreeNode.html +405 -0
  101. package/docs/interfaces/IAbstractBinaryTree.html +1124 -0
  102. package/docs/interfaces/{IBinaryTreeNode.html → IAbstractBinaryTreeNode.html} +61 -73
  103. package/docs/interfaces/{IGraph.html → IAbstractGraph.html} +52 -90
  104. package/docs/interfaces/IBST.html +1271 -0
  105. package/docs/interfaces/IBSTNode.html +408 -0
  106. package/docs/interfaces/IDirectedGraph.html +329 -16
  107. package/docs/interfaces/IUNDirectedGraph.html +322 -8
  108. package/docs/modules.html +22 -10
  109. package/docs/types/AVLTreeOptions.html +12 -6
  110. package/docs/types/{AbstractResultsByProperty.html → AbstractBinaryTreeNodeProperties.html} +16 -10
  111. package/docs/types/{AbstractResultByProperty.html → AbstractBinaryTreeNodeProperty.html} +16 -10
  112. package/docs/types/AbstractBinaryTreeOptions.html +12 -6
  113. package/docs/types/AbstractRecursiveBinaryTreeNode.html +12 -6
  114. package/docs/types/BSTComparator.html +12 -6
  115. package/docs/types/BSTOptions.html +12 -6
  116. package/docs/types/BinaryTreeDeletedResult.html +12 -6
  117. package/docs/types/BinaryTreeNodeId.html +12 -6
  118. package/docs/types/BinaryTreeNodePropertyName.html +12 -6
  119. package/docs/types/BinaryTreeOptions.html +12 -6
  120. package/docs/types/DFSOrderPattern.html +12 -6
  121. package/docs/types/DijkstraResult.html +12 -6
  122. package/docs/types/Direction.html +12 -6
  123. package/docs/types/EdgeId.html +12 -6
  124. package/docs/types/HeapOptions.html +12 -6
  125. package/docs/types/IdObject.html +12 -6
  126. package/docs/types/KeyValObject.html +12 -6
  127. package/docs/types/NavigatorParams.html +12 -6
  128. package/docs/types/NodeOrPropertyName.html +12 -6
  129. package/docs/types/PriorityQueueComparator.html +12 -6
  130. package/docs/types/PriorityQueueDFSOrderPattern.html +12 -6
  131. package/docs/types/PriorityQueueOptions.html +12 -6
  132. package/docs/types/RBTreeOptions.html +12 -6
  133. package/docs/types/RecursiveAVLTreeNode.html +12 -6
  134. package/docs/types/RecursiveBSTNode.html +12 -6
  135. package/docs/types/RecursiveBinaryTreeNode.html +12 -6
  136. package/docs/types/RecursiveTreeMultiSetNode.html +12 -6
  137. package/docs/types/SegmentTreeNodeVal.html +12 -6
  138. package/docs/types/TopologicalStatus.html +12 -6
  139. package/docs/types/TreeMultiSetOptions.html +12 -6
  140. package/docs/types/Turning.html +12 -6
  141. package/docs/types/VertexId.html +12 -6
  142. package/package.json +2 -2
  143. package/docs/interfaces/IBinaryTree.html +0 -189
@@ -1,26 +1,6 @@
1
- import { BinaryTreeNodeId, FamilyPosition } from '../types';
2
- export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> {
3
- _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
4
- get id(): BinaryTreeNodeId;
5
- set id(v: BinaryTreeNodeId);
6
- get val(): T;
7
- set val(v: T);
8
- get left(): FAMILY | null | undefined;
9
- set left(v: FAMILY | null | undefined);
10
- get right(): FAMILY | null | undefined;
11
- set right(v: FAMILY | null | undefined);
12
- get parent(): FAMILY | null | undefined;
13
- set parent(v: FAMILY | null | undefined);
14
- get familyPosition(): FamilyPosition;
15
- set familyPosition(v: FamilyPosition);
16
- get count(): number;
17
- set count(v: number);
18
- get height(): number;
19
- set height(v: number);
20
- _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
21
- swapLocation(swapNode: FAMILY): FAMILY;
22
- clone(): FAMILY | null;
1
+ import { BinaryTreeNode } from '../binary-tree';
2
+ import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
3
+ export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> extends IAbstractBinaryTreeNode<T, FAMILY> {
23
4
  }
24
- export interface IBinaryTree<N extends IBinaryTreeNode<N['val'], N>> {
25
- _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
5
+ export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
26
6
  }
@@ -1 +1,18 @@
1
- export {};
1
+ import { BSTNode } from '../binary-tree';
2
+ import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
3
+ import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
4
+ export interface IBSTNode<T, FAMILY extends IBSTNode<T, FAMILY>> extends IBinaryTreeNode<T, FAMILY> {
5
+ createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
6
+ }
7
+ export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
8
+ createNode(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N;
9
+ add(id: BinaryTreeNodeId, val: N['val'] | null, count: number): N | null;
10
+ get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
11
+ lastKey(): BinaryTreeNodeId;
12
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
13
+ getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
14
+ lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
15
+ allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
16
+ balance(): boolean;
17
+ isAVLBalanced(): boolean;
18
+ }
@@ -1,9 +1,12 @@
1
1
  import { VertexId } from '../types';
2
- export interface IDirectedGraph<V, E> {
2
+ import { IAbstractGraph } from './abstract-graph';
3
+ export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {
3
4
  incomingEdgesOf(vertex: V): E[];
4
5
  outgoingEdgesOf(vertex: V): E[];
5
6
  inDegreeOf(vertexOrId: V | VertexId): number;
6
7
  outDegreeOf(vertexOrId: V | VertexId): number;
7
8
  getEdgeSrc(e: E): V | null;
8
9
  getEdgeDest(e: E): V | null;
10
+ removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
11
+ removeEdgesBetween(v1: V | VertexId, v2: V | VertexId): E[];
9
12
  }
@@ -1,4 +1,4 @@
1
- export * from './binary-tree';
1
+ export * from './abstract-binary-tree';
2
2
  export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./binary-tree"), exports);
17
+ __exportStar(require("./abstract-binary-tree"), exports);
18
18
  __exportStar(require("./bst"), exports);
19
19
  __exportStar(require("./avl-tree"), exports);
20
20
  __exportStar(require("./segment-tree"), exports);
@@ -0,0 +1,9 @@
1
+ import { RBTreeNode } from '../binary-tree';
2
+ import { IBST, IBSTNode } from './bst';
3
+ import { BinaryTreeNodeId } from '../types';
4
+ export interface IRBTreeNode<T, FAMILY extends IRBTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
5
+ createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY;
6
+ }
7
+ export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
8
+ createNode(id: BinaryTreeNodeId, val?: N | null, count?: number): N;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,5 @@
1
- export interface IUNDirectedGraph<V, E> {
1
+ import { VertexId } from '../types';
2
+ import { IAbstractGraph } from './abstract-graph';
3
+ export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E> {
4
+ removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
2
5
  }
@@ -22,8 +22,8 @@ export type BinaryTreeDeletedResult<N> = {
22
22
  deleted: N | null | undefined;
23
23
  needBalanced: N | null;
24
24
  };
25
- export type AbstractResultByProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
26
- export type AbstractResultsByProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractResultByProperty<N>[];
25
+ export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
26
+ export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
27
27
  export type AbstractRecursiveBinaryTreeNode<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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
28
28
  export type AbstractBinaryTreeOptions = {
29
29
  loopType?: LoopType;
@@ -149,3 +149,65 @@ var trampolineAsync = function (fn) {
149
149
  }, { cont: cont });
150
150
  };
151
151
  exports.trampolineAsync = trampolineAsync;
152
+ // export class AutoPruneMap<K, V> extends Map<K, V> {
153
+ //
154
+ // private _proxySet: Set<V>;
155
+ // get proxySet(): Set<V> {
156
+ // return this._proxySet;
157
+ // }
158
+ //
159
+ // set proxySet(value: Set<V>) {
160
+ // this._proxySet = value;
161
+ // }
162
+ //
163
+ // private _isEmptyArrayAllowed: boolean;
164
+ //
165
+ // get isEmptyArrayAllowed(): boolean {
166
+ // return this._isEmptyArrayAllowed;
167
+ // }
168
+ //
169
+ // set isEmptyArrayAllowed(value: boolean) {
170
+ // this._isEmptyArrayAllowed = value;
171
+ // }
172
+ //
173
+ // constructor(isEmptyArrayAllowed: boolean = false) {
174
+ // super();
175
+ // this._isEmptyArrayAllowed = isEmptyArrayAllowed;
176
+ // this._proxySet = new Set<V>();
177
+ // }
178
+ //
179
+ // set(key: K, value: V): this {
180
+ // if (Array.isArray(value) && !this.proxySet.has(value)) {
181
+ // if(!this.isEmptyArrayAllowed && value.length === 0) return this;
182
+ // value = this.createArrayProxy(value, key);
183
+ // if (!this.proxySet.has(value)) this.proxySet.add(value);
184
+ // }
185
+ // super.set(key, value);
186
+ // return this;
187
+ // }
188
+ //
189
+ // private createArrayProxy(array: V & any[], key: K) {
190
+ // const that = this;
191
+ // const proxyHandler: ProxyHandler<V & any[]> = {
192
+ // set(target: any, property: PropertyKey, value: any): boolean {
193
+ // const result = Reflect.set(target, property, value);
194
+ // that.checkAndDeleteEmptyArray(key);
195
+ // return result;
196
+ // },
197
+ // deleteProperty(target: any, property: PropertyKey): boolean {
198
+ // const result = Reflect.deleteProperty(target, property);
199
+ // that.checkAndDeleteEmptyArray(key);
200
+ // return result;
201
+ // },
202
+ // }
203
+ // return new Proxy(array, proxyHandler);
204
+ // }
205
+ //
206
+ // private checkAndDeleteEmptyArray(key: K): void {
207
+ // const value = this.get(key);
208
+ //
209
+ // if (Array.isArray(value) && value.length === 0) {
210
+ // super.delete(key);
211
+ // }
212
+ // }
213
+ // }