data-structure-typed 1.51.2 → 1.51.4

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 (37) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/POSTS_zh-CN.md +54 -0
  3. package/README.md +198 -172
  4. package/benchmark/report.html +1 -37
  5. package/benchmark/report.json +3 -405
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +2 -2
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.js +1 -1
  9. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  10. package/dist/cjs/data-structures/index.d.ts +1 -1
  11. package/dist/cjs/data-structures/index.js +1 -1
  12. package/dist/cjs/data-structures/index.js.map +1 -1
  13. package/dist/cjs/utils/index.d.ts +1 -0
  14. package/dist/cjs/utils/index.js +1 -0
  15. package/dist/cjs/utils/index.js.map +1 -1
  16. package/dist/cjs/utils/number.d.ts +1 -0
  17. package/dist/cjs/utils/number.js +12 -0
  18. package/dist/cjs/utils/number.js.map +1 -0
  19. package/dist/mjs/data-structures/binary-tree/binary-tree.js +2 -2
  20. package/dist/mjs/data-structures/binary-tree/bst.js +1 -1
  21. package/dist/mjs/data-structures/index.d.ts +1 -1
  22. package/dist/mjs/data-structures/index.js +1 -1
  23. package/dist/mjs/utils/index.d.ts +1 -0
  24. package/dist/mjs/utils/index.js +1 -0
  25. package/dist/mjs/utils/number.d.ts +1 -0
  26. package/dist/mjs/utils/number.js +7 -0
  27. package/dist/umd/data-structure-typed.js +116 -108
  28. package/dist/umd/data-structure-typed.min.js +2 -2
  29. package/dist/umd/data-structure-typed.min.js.map +1 -1
  30. package/package.json +92 -69
  31. package/src/data-structures/binary-tree/binary-tree.ts +2 -2
  32. package/src/data-structures/binary-tree/bst.ts +1 -1
  33. package/src/data-structures/index.ts +1 -1
  34. package/src/utils/index.ts +1 -0
  35. package/src/utils/number.ts +9 -0
  36. package/test/performance/data-structures/tree/tree.test.ts +0 -0
  37. package/test/unit/data-structures/tree/tree.test.ts +0 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.51.2",
3
+ "version": "1.51.4",
4
4
  "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -66,11 +66,11 @@
66
66
  "@typescript-eslint/eslint-plugin": "^6.7.4",
67
67
  "@typescript-eslint/parser": "^6.7.4",
68
68
  "auto-changelog": "^2.4.0",
69
- "avl-tree-typed": "^1.51.1",
69
+ "avl-tree-typed": "^1.51.3",
70
70
  "benchmark": "^2.1.4",
71
- "binary-tree-typed": "^1.51.1",
72
- "bst-typed": "^1.51.1",
73
- "data-structure-typed": "^1.51.1",
71
+ "binary-tree-typed": "^1.51.3",
72
+ "bst-typed": "^1.51.3",
73
+ "data-structure-typed": "^1.51.3",
74
74
  "dependency-cruiser": "^14.1.0",
75
75
  "doctoc": "^2.2.1",
76
76
  "eslint": "^8.50.0",
@@ -79,7 +79,7 @@
79
79
  "eslint-import-resolver-typescript": "^3.6.1",
80
80
  "eslint-plugin-import": "^2.28.1",
81
81
  "fast-glob": "^3.3.1",
82
- "heap-typed": "^1.51.1",
82
+ "heap-typed": "^1.51.3",
83
83
  "istanbul-badges-readme": "^1.8.5",
84
84
  "jest": "^29.7.0",
85
85
  "js-sdsl": "^4.4.2",
@@ -92,54 +92,17 @@
92
92
  "typescript": "^5.3.2"
93
93
  },
94
94
  "keywords": [
95
- "data structure",
96
- "data structures",
97
- "datastructure",
98
- "datastructures",
99
95
  "data",
100
96
  "structure",
101
97
  "structures",
102
- "min",
103
- "max",
104
- "heap",
105
- "priority",
106
- "queue",
107
- "min heap",
108
- "min-heap",
109
- "max heap",
110
- "max-heap",
111
- "priority queue",
112
- "priority-queue",
113
- "max priority queue",
114
- "max-priority-queue",
115
- "min priority queue",
116
- "min-priority-queue",
117
- "binary search tree",
118
- "binary-search-tree",
119
- "BST",
120
- "binary tree",
121
- "binary-tree",
122
- "red black tree",
123
- "red black tree",
124
- "red-black-tree",
125
- "rb tree",
126
- "trie",
127
- "prefix tree",
128
- "prefix-tree",
129
- "avl tree",
130
- "avl-tree",
131
- "tree set",
132
- "tree-set",
133
- "tree multiset",
134
- "tree-multiset",
135
- "tree map",
136
- "tree-map",
137
- "tree multimap",
138
- "tree-multimap",
139
- "binary indexed tree",
140
- "binary-indexed-tree",
141
- "segment tree",
142
- "segment-tree",
98
+ "data structure",
99
+ "datastructure",
100
+ "data-structure",
101
+ "data structures",
102
+ "datastructures",
103
+ "data-structures",
104
+ "in data structures",
105
+ "in data structure",
143
106
  "binary",
144
107
  "depth",
145
108
  "breadth",
@@ -149,7 +112,7 @@
149
112
  "avl",
150
113
  "red",
151
114
  "black",
152
- "red black",
115
+ "redblack",
153
116
  "RB",
154
117
  "segment",
155
118
  "prefix",
@@ -159,26 +122,18 @@
159
122
  "set",
160
123
  "multiset",
161
124
  "multimap",
125
+ "directed",
126
+ "undirected",
127
+ "graph",
128
+ "min",
129
+ "max",
130
+ "heap",
131
+ "priority",
132
+ "queue",
162
133
  "singly",
163
134
  "doubly",
164
135
  "linked",
165
136
  "list",
166
- "linked list",
167
- "linked-list",
168
- "singly linked list",
169
- "singly-linked-list",
170
- "doubly linked list",
171
- "doubly-linked-list",
172
- "javascript data structure",
173
- "javascript data structures",
174
- "typescript data structures",
175
- "js data structure",
176
- "js data structures",
177
- "data-structure",
178
- "data-structures",
179
- "directed",
180
- "undirected",
181
- "graph",
182
137
  "js",
183
138
  "ts",
184
139
  "javascript",
@@ -195,6 +150,7 @@
195
150
  "Python",
196
151
  "collections",
197
152
  "Python Collections",
153
+ "pythoncollections",
198
154
  "python-collections",
199
155
  "C#",
200
156
  "System.Collections.Generic",
@@ -202,6 +158,43 @@
202
158
  "java.util",
203
159
  "Java",
204
160
  "util",
161
+ "binary search tree",
162
+ "binarysearchtree",
163
+ "binary-search-tree",
164
+ "BST",
165
+ "binary tree",
166
+ "binarytree",
167
+ "binary-tree",
168
+ "red black tree",
169
+ "redblacktree",
170
+ "redblack tree",
171
+ "red-black-tree",
172
+ "redblack-tree",
173
+ "trie",
174
+ "prefix tree",
175
+ "prefixtree",
176
+ "prefix-tree",
177
+ "avl tree",
178
+ "avltree",
179
+ "avl-tree",
180
+ "tree set",
181
+ "treeset",
182
+ "tree-set",
183
+ "tree multiset",
184
+ "treemultiset",
185
+ "tree-multiset",
186
+ "tree map",
187
+ "treemap",
188
+ "tree-map",
189
+ "tree multimap",
190
+ "treemultimap",
191
+ "tree-multimap",
192
+ "binary indexed tree",
193
+ "binaryindexedtree",
194
+ "binary-indexed-tree",
195
+ "segment tree",
196
+ "segmenttree",
197
+ "segment-tree",
205
198
  "sort",
206
199
  "sorted",
207
200
  "order",
@@ -210,31 +203,61 @@
210
203
  "morris",
211
204
  "Morris",
212
205
  "bellman ford",
206
+ "bellmanford",
213
207
  "bellman-ford",
214
208
  "dijkstra",
215
209
  "Dijkstra",
216
210
  "floyd warshall",
211
+ "floydwarshall",
217
212
  "floyd-warshall",
218
213
  "tarjan",
219
214
  "tarjan's",
220
215
  "dfs",
221
216
  "depth first Search",
217
+ "depthfirstSearch",
222
218
  "depth-first-Search",
223
219
  "bfs",
224
220
  "breadth first search",
221
+ "breadthfirstsearch",
225
222
  "dfs iterative",
226
223
  "recursive",
227
224
  "iterative",
228
225
  "directed graph",
226
+ "directedgraph",
229
227
  "directed-graph",
230
228
  "undirected graph",
229
+ "undirectedgraph",
231
230
  "undirected-graph",
231
+ "min heap",
232
+ "minheap",
233
+ "min-heap",
234
+ "max heap",
235
+ "maxheap",
236
+ "max-heap",
237
+ "priority queue",
238
+ "priorityqueue",
239
+ "priority-queue",
240
+ "max priority queue",
241
+ "maxpriorityqueue",
242
+ "max-priority-queue",
243
+ "min priority queue",
244
+ "minpriorityqueue",
245
+ "min-priority-queue",
232
246
  "hash",
233
247
  "map",
234
- "hashmap",
235
248
  "hash map",
249
+ "hashmap",
236
250
  "hash-map",
237
251
  "deque",
252
+ "linked list",
253
+ "linkedlist",
254
+ "linked-list",
255
+ "singly linked list",
256
+ "singlylinkedlist",
257
+ "singly-linked-list",
258
+ "doubly linked list",
259
+ "doublylinkedlist",
260
+ "doubly-linked-list",
238
261
  "stack",
239
262
  "CommonJS",
240
263
  "ES6",
@@ -316,8 +316,8 @@ export class BinaryTree<
316
316
  * @returns a boolean value.
317
317
  */
318
318
  isRealNode(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE {
319
- if (!this.isNode(node)) return false;
320
- return node !== this.NIL;
319
+ if (node === this.NIL || node === null || node === undefined) return false;
320
+ return this.isNode(node);
321
321
  }
322
322
 
323
323
  /**
@@ -695,7 +695,7 @@ export class BST<
695
695
  if (!current) return undefined;
696
696
 
697
697
  if (this._variant === 'STANDARD') {
698
- // For BSTVariant.MIN, find the rightmost node
698
+ // For 'STANDARD', find the rightmost node
699
699
  while (current.right !== undefined) {
700
700
  current = current.right;
701
701
  }
@@ -4,9 +4,9 @@ export * from './stack';
4
4
  export * from './queue';
5
5
  export * from './graph';
6
6
  export * from './binary-tree';
7
- export * from './tree';
8
7
  export * from './heap';
9
8
  export * from './priority-queue';
10
9
  export * from './matrix';
11
10
  export * from './trie';
12
11
  export * from './base';
12
+ export * from './tree';
@@ -1 +1,2 @@
1
1
  export * from './utils';
2
+ export * from './number';
@@ -0,0 +1,9 @@
1
+ export function toBinaryString(num: number, digit = 32) {
2
+ // Convert number to binary string
3
+ let binaryString = (num >>> 0).toString(2); // Use the unsigned right shift operator to ensure you get a binary representation of a 32-bit unsigned integer
4
+
5
+ // Use pad Start to ensure the string length is 32 bits
6
+ binaryString = binaryString.padStart(digit, '0');
7
+
8
+ return binaryString;
9
+ }
@@ -1,39 +0,0 @@
1
- import { TreeNode } from '../../../../src';
2
-
3
- describe('TreeNode', () => {
4
- it('should create a TreeNode with the given key and value', () => {
5
- const node = new TreeNode<string>('1', 'Node 1');
6
- expect(node.key).toBe('1');
7
- expect(node.value).toBe('Node 1');
8
- expect(node.children).toEqual([]);
9
- });
10
-
11
- it('should add children to the TreeNode', () => {
12
- const parentNode = new TreeNode<string>('1', 'Parent Node');
13
- const child1 = new TreeNode<string>('2', 'Child 1');
14
- const child2 = new TreeNode<string>('3', 'Child 2');
15
-
16
- parentNode.addChildren([child1, child2]);
17
-
18
- expect(parentNode.children).toEqual([child1, child2]);
19
- });
20
-
21
- it('should calculate the height of the tree correctly', () => {
22
- const rootNode = new TreeNode<string>('1', 'Root Node');
23
- const child1 = new TreeNode<string>('2', 'Child 1');
24
- const child2 = new TreeNode<string>('3', 'Child 2');
25
- const grandchild1 = new TreeNode<string>('4', 'Grandchild 1');
26
- const grandchild2 = new TreeNode<string>('5', 'Grandchild 2');
27
-
28
- rootNode.addChildren([child1, child2]);
29
- child1.addChildren([grandchild1]);
30
- child2.addChildren([grandchild2]);
31
-
32
- expect(rootNode.getHeight()).toBe(2); // Height of the tree should be 2
33
- });
34
-
35
- it('should handle nodes without children when calculating height', () => {
36
- const rootNode = new TreeNode<string>('1', 'Root Node');
37
- expect(rootNode.getHeight()).toBe(0); // Height of a single node should be 0
38
- });
39
- });