data-structure-typed 1.36.0 → 1.36.1

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 (62) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +3 -509
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1 -1175
  4. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -1
  6. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +506 -1
  8. package/dist/data-structures/binary-tree/binary-tree.js +1173 -2
  9. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/data-structures/binary-tree/bst.d.ts +1 -1
  11. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  12. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -1
  13. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  15. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  16. package/dist/data-structures/heap/heap.d.ts +22 -23
  17. package/dist/data-structures/heap/heap.js +8 -25
  18. package/dist/data-structures/heap/heap.js.map +1 -1
  19. package/dist/data-structures/heap/max-heap.d.ts +2 -2
  20. package/dist/data-structures/heap/min-heap.d.ts +2 -2
  21. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  22. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  23. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
  24. package/dist/types/data-structures/abstract-binary-tree.d.ts +1 -3
  25. package/dist/types/data-structures/binary-tree.d.ts +4 -2
  26. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +3 -509
  27. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1 -1175
  28. package/lib/data-structures/binary-tree/avl-tree.d.ts +1 -1
  29. package/lib/data-structures/binary-tree/binary-tree.d.ts +506 -1
  30. package/lib/data-structures/binary-tree/binary-tree.js +1173 -2
  31. package/lib/data-structures/binary-tree/bst.d.ts +1 -1
  32. package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
  33. package/lib/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  34. package/lib/data-structures/heap/heap.d.ts +22 -23
  35. package/lib/data-structures/heap/heap.js +8 -25
  36. package/lib/data-structures/heap/max-heap.d.ts +2 -2
  37. package/lib/data-structures/heap/min-heap.d.ts +2 -2
  38. package/lib/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  39. package/lib/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  40. package/lib/data-structures/priority-queue/priority-queue.d.ts +2 -2
  41. package/lib/types/data-structures/abstract-binary-tree.d.ts +1 -3
  42. package/lib/types/data-structures/binary-tree.d.ts +4 -2
  43. package/package.json +4 -4
  44. package/src/data-structures/binary-tree/abstract-binary-tree.ts +4 -1527
  45. package/src/data-structures/binary-tree/avl-tree.ts +3 -3
  46. package/src/data-structures/binary-tree/binary-tree.ts +1524 -5
  47. package/src/data-structures/binary-tree/bst.ts +3 -3
  48. package/src/data-structures/binary-tree/rb-tree.ts +3 -3
  49. package/src/data-structures/binary-tree/tree-multiset.ts +3 -3
  50. package/src/data-structures/heap/heap.ts +29 -47
  51. package/src/data-structures/heap/max-heap.ts +2 -2
  52. package/src/data-structures/heap/min-heap.ts +2 -2
  53. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  54. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -2
  55. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  56. package/src/types/data-structures/abstract-binary-tree.ts +1 -1
  57. package/src/types/data-structures/binary-tree.ts +2 -2
  58. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +2 -1
  59. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  60. package/umd/bundle.min.js +1 -1
  61. package/umd/bundle.min.js.LICENSE.txt +7 -0
  62. package/umd/bundle.min.js.map +1 -1
@@ -9,7 +9,7 @@ import type { BinaryTreeNodeKey, BinaryTreeNodePropertyName, BSTComparator, BSTN
9
9
  import { CP } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBST, IBSTNode } from '../../interfaces';
12
- export declare class BSTNode<V = any, NEIGHBOR extends BSTNode<V, NEIGHBOR> = BSTNodeNested<V>> extends BinaryTreeNode<V, NEIGHBOR> implements IBSTNode<V, NEIGHBOR> {
12
+ export declare class BSTNode<V = any, FAMILY extends BSTNode<V, FAMILY> = BSTNodeNested<V>> extends BinaryTreeNode<V, FAMILY> implements IBSTNode<V, FAMILY> {
13
13
  constructor(key: BinaryTreeNodeKey, val?: V);
14
14
  }
15
15
  export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBST<N> {
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions } from '../../types';
2
2
  import { IRBTree, IRBTreeNode } from '../../interfaces';
3
3
  import { BST, BSTNode } from './bst';
4
- export declare class RBTreeNode<V = any, NEIGHBOR extends RBTreeNode<V, NEIGHBOR> = RBTreeNodeNested<V>> extends BSTNode<V, NEIGHBOR> implements IRBTreeNode<V, NEIGHBOR> {
4
+ export declare class RBTreeNode<V = any, FAMILY extends RBTreeNode<V, FAMILY> = RBTreeNodeNested<V>> extends BSTNode<V, FAMILY> implements IRBTreeNode<V, FAMILY> {
5
5
  private _color;
6
6
  constructor(key: BinaryTreeNodeKey, val?: V);
7
7
  get color(): RBColor;
@@ -9,7 +9,7 @@ import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } f
9
9
  import { BinaryTreeDeletedResult, DFSOrderPattern } from '../../types';
10
10
  import { ITreeMultiset, ITreeMultisetNode } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
- export declare class TreeMultisetNode<V = any, NEIGHBOR extends TreeMultisetNode<V, NEIGHBOR> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, NEIGHBOR> implements ITreeMultisetNode<V, NEIGHBOR> {
12
+ export declare class TreeMultisetNode<V = any, FAMILY extends TreeMultisetNode<V, FAMILY> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, FAMILY> implements ITreeMultisetNode<V, FAMILY> {
13
13
  /**
14
14
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
15
15
  * @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
@@ -1,25 +1,24 @@
1
1
  /**
2
2
  * data-structure-typed
3
- *
4
3
  * @author Kirk Qi
5
4
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
5
  * @license MIT License
7
6
  */
8
7
  import type { CompareFunction } from '../../types';
9
- export declare class Heap<T> {
10
- private nodes;
8
+ export declare class Heap<E> {
9
+ protected nodes: E[];
11
10
  private readonly comparator;
12
- constructor(comparator: CompareFunction<T>);
11
+ constructor(comparator: CompareFunction<E>);
13
12
  /**
14
13
  * Insert an element into the heap and maintain the heap properties.
15
14
  * @param value - The element to be inserted.
16
15
  */
17
- add(value: T): Heap<T>;
16
+ add(value: E): Heap<E>;
18
17
  /**
19
18
  * Remove and return the top element (smallest or largest element) from the heap.
20
19
  * @returns The top element or null if the heap is empty.
21
20
  */
22
- poll(): T | null;
21
+ poll(): E | null;
23
22
  /**
24
23
  * Float operation to maintain heap properties after adding an element.
25
24
  * @param index - The index of the newly added element.
@@ -38,7 +37,7 @@ export declare class Heap<T> {
38
37
  * Peek at the top element of the heap without removing it.
39
38
  * @returns The top element or null if the heap is empty.
40
39
  */
41
- peek(): T | null;
40
+ peek(): E | null;
42
41
  /**
43
42
  * Get the size (number of elements) of the heap.
44
43
  */
@@ -47,54 +46,54 @@ export declare class Heap<T> {
47
46
  * Get the last element in the heap, which is not necessarily a leaf node.
48
47
  * @returns The last element or null if the heap is empty.
49
48
  */
50
- leaf(): T | null;
49
+ get leaf(): E | null;
51
50
  /**
52
51
  * Check if the heap is empty.
53
52
  * @returns True if the heap is empty, otherwise false.
54
53
  */
55
54
  isEmpty(): boolean;
55
+ /**
56
+ * Reset the nodes of the heap. Make the nodes empty.
57
+ */
56
58
  clear(): void;
57
- refill(nodes: T[]): void;
59
+ /**
60
+ * Clear and add nodes of the heap
61
+ * @param nodes
62
+ */
63
+ refill(nodes: E[]): void;
58
64
  /**
59
65
  * Use a comparison function to check whether a binary heap contains a specific element.
60
66
  * @param value - the element to check.
61
67
  * @returns Returns true if the specified element is contained; otherwise, returns false.
62
68
  */
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;
69
+ has(value: E): boolean;
71
70
  /**
72
71
  * Depth-first search (DFS) method, different traversal orders can be selected。
73
72
  * @param order - Traversal order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
74
73
  * @returns An array containing elements traversed in the specified order.
75
74
  */
76
- dfs(order: 'in' | 'pre' | 'post'): T[];
75
+ dfs(order: 'in' | 'pre' | 'post'): E[];
77
76
  /**
78
77
  * Convert the heap to an array.
79
78
  * @returns An array containing the elements of the heap.
80
79
  */
81
- toArray(): T[];
82
- getNodes(): T[];
80
+ toArray(): E[];
81
+ getNodes(): E[];
83
82
  /**
84
83
  * Clone the heap, creating a new heap with the same elements.
85
84
  * @returns A new Heap instance containing the same elements.
86
85
  */
87
- clone(): Heap<T>;
86
+ clone(): Heap<E>;
88
87
  /**
89
88
  * Sort the elements in the heap and return them as an array.
90
89
  * @returns An array containing the elements sorted in ascending order.
91
90
  */
92
- sort(): T[];
91
+ sort(): E[];
93
92
  /**
94
93
  * Static method that creates a binary heap from an array of nodes and a comparison function.
95
94
  * @param nodes
96
95
  * @param comparator - Comparison function.
97
96
  * @returns A new Heap instance.
98
97
  */
99
- static heapify<T>(nodes: T[], comparator: CompareFunction<T>): Heap<T>;
98
+ static heapify<E>(nodes: E[], comparator: CompareFunction<E>): Heap<E>;
100
99
  }
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * data-structure-typed
3
- *
4
3
  * @author Kirk Qi
5
4
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
5
  * @license MIT License
@@ -103,7 +102,7 @@ export class Heap {
103
102
  * Get the last element in the heap, which is not necessarily a leaf node.
104
103
  * @returns The last element or null if the heap is empty.
105
104
  */
106
- leaf() {
105
+ get leaf() {
107
106
  var _a;
108
107
  return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : null;
109
108
  }
@@ -114,9 +113,16 @@ export class Heap {
114
113
  isEmpty() {
115
114
  return this.size === 0;
116
115
  }
116
+ /**
117
+ * Reset the nodes of the heap. Make the nodes empty.
118
+ */
117
119
  clear() {
118
120
  this.nodes = [];
119
121
  }
122
+ /**
123
+ * Clear and add nodes of the heap
124
+ * @param nodes
125
+ */
120
126
  refill(nodes) {
121
127
  this.nodes = nodes;
122
128
  this.fix();
@@ -129,29 +135,6 @@ export class Heap {
129
135
  has(value) {
130
136
  return this.nodes.includes(value);
131
137
  }
132
- /**
133
- * Use a comparison function to find the index of an element in the heap.
134
- * @param value - the element to find.
135
- * @param index - the index currently being searched.
136
- * @returns The index of the element, or -1 if not found.
137
- */
138
- findIndex(value, index) {
139
- if (index >= this.size) {
140
- return -1;
141
- }
142
- const compareResult = this.comparator(value, this.nodes[index]);
143
- if (compareResult === 0) {
144
- return index; // Element found
145
- }
146
- else if (compareResult < 0) {
147
- // The element should be in the left subtree
148
- return this.findIndex(value, 2 * index + 1);
149
- }
150
- else {
151
- // The element should be in the right subtree
152
- return this.findIndex(value, 2 * index + 2);
153
- }
154
- }
155
138
  /**
156
139
  * Depth-first search (DFS) method, different traversal orders can be selected。
157
140
  * @param order - Traversal order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { Heap } from './heap';
9
9
  import type { CompareFunction } from '../../types';
10
- export declare class MaxHeap<T = any> extends Heap<T> {
11
- constructor(comparator?: CompareFunction<T>);
10
+ export declare class MaxHeap<E = any> extends Heap<E> {
11
+ constructor(comparator?: CompareFunction<E>);
12
12
  }
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { Heap } from './heap';
9
9
  import type { CompareFunction } from '../../types';
10
- export declare class MinHeap<T = any> extends Heap<T> {
11
- constructor(comparator?: CompareFunction<T>);
10
+ export declare class MinHeap<E = any> extends Heap<E> {
11
+ constructor(comparator?: CompareFunction<E>);
12
12
  }
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { PriorityQueue } from './priority-queue';
9
9
  import type { CompareFunction } from '../../types';
10
- export declare class MaxPriorityQueue<T = any> extends PriorityQueue<T> {
11
- constructor(compare?: CompareFunction<T>);
10
+ export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ constructor(compare?: CompareFunction<E>);
12
12
  }
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { PriorityQueue } from './priority-queue';
9
9
  import type { CompareFunction } from '../../types';
10
- export declare class MinPriorityQueue<T = any> extends PriorityQueue<T> {
11
- constructor(compare?: CompareFunction<T>);
10
+ export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ constructor(compare?: CompareFunction<E>);
12
12
  }
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { Heap } from '../heap';
9
9
  import { CompareFunction } from '../../types';
10
- export declare class PriorityQueue<T> extends Heap<T> {
11
- constructor(comparator: CompareFunction<T>);
10
+ export declare class PriorityQueue<E> extends Heap<E> {
11
+ constructor(comparator: CompareFunction<E>);
12
12
  }
@@ -29,6 +29,4 @@ export type BinaryTreeDeletedResult<N> = {
29
29
  export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeKey;
30
30
  export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
31
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
- };
32
+ export type AbstractBinaryTreeOptions = {};
@@ -1,4 +1,6 @@
1
1
  import { BinaryTreeNode } from '../../data-structures/binary-tree';
2
- import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
2
+ import { AbstractBinaryTreeOptions, LoopType } from './abstract-binary-tree';
3
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 & {};
4
+ export type BinaryTreeOptions = AbstractBinaryTreeOptions & {
5
+ loopType?: LoopType;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.36.0",
3
+ "version": "1.36.1",
4
4
  "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -54,10 +54,10 @@
54
54
  "@typescript-eslint/eslint-plugin": "^6.7.4",
55
55
  "@typescript-eslint/parser": "^6.7.4",
56
56
  "auto-changelog": "^2.4.0",
57
- "avl-tree-typed": "^1.35.1",
57
+ "avl-tree-typed": "^1.36.0",
58
58
  "benchmark": "^2.1.4",
59
- "binary-tree-typed": "^1.35.1",
60
- "bst-typed": "^1.35.1",
59
+ "binary-tree-typed": "^1.36.0",
60
+ "bst-typed": "^1.36.0",
61
61
  "dependency-cruiser": "^14.1.0",
62
62
  "eslint": "^8.50.0",
63
63
  "eslint-config-prettier": "^9.0.0",