binary-tree-typed 2.4.4 → 2.5.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.
Files changed (85) hide show
  1. package/README.md +0 -84
  2. package/dist/cjs/index.cjs +965 -420
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +962 -417
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +965 -421
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +962 -418
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/common/error.d.ts +23 -0
  11. package/dist/types/common/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  13. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
  14. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
  15. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +439 -78
  16. package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +217 -31
  18. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
  19. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
  20. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
  21. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
  22. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
  23. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
  24. package/dist/types/data-structures/graph/directed-graph.d.ts +220 -47
  25. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +218 -59
  27. package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
  28. package/dist/types/data-structures/heap/heap.d.ts +287 -99
  29. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  30. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  31. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
  32. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
  33. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
  34. package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/queue/deque.d.ts +313 -66
  39. package/dist/types/data-structures/queue/queue.d.ts +211 -42
  40. package/dist/types/data-structures/stack/stack.d.ts +174 -32
  41. package/dist/types/data-structures/trie/trie.d.ts +213 -43
  42. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  43. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  44. package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
  45. package/dist/umd/binary-tree-typed.js +959 -414
  46. package/dist/umd/binary-tree-typed.js.map +1 -1
  47. package/dist/umd/binary-tree-typed.min.js +3 -3
  48. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/common/error.ts +60 -0
  51. package/src/common/index.ts +2 -0
  52. package/src/data-structures/base/iterable-element-base.ts +2 -2
  53. package/src/data-structures/binary-tree/avl-tree.ts +134 -51
  54. package/src/data-structures/binary-tree/binary-indexed-tree.ts +303 -247
  55. package/src/data-structures/binary-tree/binary-tree.ts +542 -121
  56. package/src/data-structures/binary-tree/bst.ts +346 -37
  57. package/src/data-structures/binary-tree/red-black-tree.ts +309 -96
  58. package/src/data-structures/binary-tree/segment-tree.ts +372 -248
  59. package/src/data-structures/binary-tree/tree-map.ts +1292 -13
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +1098 -215
  61. package/src/data-structures/binary-tree/tree-multi-set.ts +863 -69
  62. package/src/data-structures/binary-tree/tree-set.ts +1143 -15
  63. package/src/data-structures/graph/abstract-graph.ts +106 -1
  64. package/src/data-structures/graph/directed-graph.ts +223 -47
  65. package/src/data-structures/graph/map-graph.ts +59 -1
  66. package/src/data-structures/graph/undirected-graph.ts +299 -59
  67. package/src/data-structures/hash/hash-map.ts +243 -79
  68. package/src/data-structures/heap/heap.ts +291 -102
  69. package/src/data-structures/heap/max-heap.ts +48 -3
  70. package/src/data-structures/heap/min-heap.ts +59 -0
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
  72. package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
  73. package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
  74. package/src/data-structures/matrix/matrix.ts +425 -22
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +59 -3
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  77. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  78. package/src/data-structures/queue/deque.ts +343 -68
  79. package/src/data-structures/queue/queue.ts +211 -42
  80. package/src/data-structures/stack/stack.ts +174 -32
  81. package/src/data-structures/trie/trie.ts +215 -44
  82. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  83. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  84. package/src/types/data-structures/queue/deque.ts +7 -0
  85. package/src/utils/utils.ts +4 -2
@@ -19,83 +19,6 @@ import { IterableEntryBase } from '../base';
19
19
  * If you try to insert another entry with the same key, the new one will replace the old entry.
20
20
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
21
21
  * @example
22
- * // should maintain insertion order
23
- * const linkedHashMap = new LinkedHashMap<number, string>();
24
- * linkedHashMap.set(1, 'A');
25
- * linkedHashMap.set(2, 'B');
26
- * linkedHashMap.set(3, 'C');
27
- *
28
- * const result = Array.from(linkedHashMap);
29
- * console.log(result); // [
30
- * // [1, 'A'],
31
- * // [2, 'B'],
32
- * // [3, 'C']
33
- * // ];
34
- * @example
35
- * // basic HashMap creation and set operation
36
- * // Create a simple HashMap with key-value pairs
37
- * const map = new HashMap<number, string>([
38
- * [1, 'one'],
39
- * [2, 'two'],
40
- * [3, 'three']
41
- * ]);
42
- *
43
- * // Verify size
44
- * console.log(map.size); // 3;
45
- *
46
- * // Set a new key-value pair
47
- * map.set(4, 'four');
48
- * console.log(map.size); // 4;
49
- *
50
- * // Verify entries
51
- * console.log([...map.entries()]); // length: 4;
52
- * @example
53
- * // HashMap get and has operations
54
- * const map = new HashMap<string, number>([
55
- * ['apple', 1],
56
- * ['banana', 2],
57
- * ['cherry', 3]
58
- * ]);
59
- *
60
- * // Check if key exists
61
- * console.log(map.has('apple')); // true;
62
- * console.log(map.has('date')); // false;
63
- *
64
- * // Get value by key
65
- * console.log(map.get('banana')); // 2;
66
- * console.log(map.get('grape')); // undefined;
67
- *
68
- * // Get all keys and values
69
- * const keys = [...map.keys()];
70
- * const values = [...map.values()];
71
- * console.log(keys); // contains 'apple';
72
- * console.log(values); // contains 3;
73
- * @example
74
- * // HashMap iteration and filter operations
75
- * const map = new HashMap<number, string>([
76
- * [1, 'Alice'],
77
- * [2, 'Bob'],
78
- * [3, 'Charlie'],
79
- * [4, 'Diana'],
80
- * [5, 'Eve']
81
- * ]);
82
- *
83
- * // Iterate through entries
84
- * const entries: [number, string][] = [];
85
- * for (const [key, value] of map) {
86
- * entries.push([key, value]);
87
- * }
88
- * console.log(entries); // length: 5;
89
- *
90
- * // Filter operation (for iteration with collection methods)
91
- * const filtered = [...map].filter(([key]) => key > 2);
92
- * console.log(filtered.length); // 3;
93
- *
94
- * // Map operation
95
- * const values = [...map.values()].map(v => v.length);
96
- * console.log(values); // contains 3; // 'Bob', 'Eve'
97
- * console.log(values); // contains 7;
98
- * @example
99
22
  * // HashMap for user session caching O(1) performance
100
23
  * interface UserSession {
101
24
  * userId: number;
@@ -147,6 +70,19 @@ import { IterableEntryBase } from '../base';
147
70
  * // Get all active sessions
148
71
  * const activeCount = [...sessionCache.values()].length;
149
72
  * console.log(activeCount); // 2;
73
+ * @example
74
+ * // Aggregate values
75
+ * const counts = new HashMap<string, number>([['a', 5], ['b', 3], ['c', 8]]);
76
+ *
77
+ * const total = counts.reduce((sum, v) => sum + (v ?? 0), 0);
78
+ * console.log(total); // 16;
79
+ * @example
80
+ * // Iterate over entries
81
+ * const map = new HashMap<string, number>([['x', 1], ['y', 2]]);
82
+ * const keys: string[] = [];
83
+ *
84
+ * map.forEach((v, k) => keys.push(k));
85
+ * console.log(keys.sort()); // ['x', 'y'];
150
86
  */
151
87
  export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
152
88
  /**
@@ -200,12 +136,39 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
200
136
  * Check whether the map is empty.
201
137
  * @remarks Time O(1), Space O(1)
202
138
  * @returns True if size is 0.
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ * @example
149
+ * // Check if empty
150
+ * const map = new HashMap();
151
+ * console.log(map.isEmpty()); // true;
203
152
  */
204
153
  isEmpty(): boolean;
205
154
  /**
206
155
  * Remove all entries and reset counters.
207
156
  * @remarks Time O(N), Space O(1)
208
157
  * @returns void
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+ * @example
168
+ * // Remove all entries
169
+ * const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
170
+ * map.clear();
171
+ * console.log(map.isEmpty()); // true;
209
172
  */
210
173
  clear(): void;
211
174
  /**
@@ -220,6 +183,46 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
220
183
  * @param key - Key.
221
184
  * @param value - Value.
222
185
  * @returns True when the operation succeeds.
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+ * @example
209
+ * // basic HashMap creation and set operation
210
+ * // Create a simple HashMap with key-value pairs
211
+ * const map = new HashMap<number, string>([
212
+ * [1, 'one'],
213
+ * [2, 'two'],
214
+ * [3, 'three']
215
+ * ]);
216
+ *
217
+ * // Verify size
218
+ * console.log(map.size); // 3;
219
+ *
220
+ * // Set a new key-value pair
221
+ * map.set(4, 'four');
222
+ * console.log(map.size); // 4;
223
+ *
224
+ * // Verify entries
225
+ * console.log([...map.entries()]); // length: 4;
223
226
  */
224
227
  set(key: K, value: V): boolean;
225
228
  /**
@@ -227,6 +230,20 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
227
230
  * @remarks Time O(N), Space O(N)
228
231
  * @param entryOrRawElements - Iterable of entries or raw elements to insert.
229
232
  * @returns Array of per-entry results.
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+ * @example
243
+ * // Add multiple entries
244
+ * const map = new HashMap<string, number>();
245
+ * map.setMany([['a', 1], ['b', 2], ['c', 3]]);
246
+ * console.log(map.size); // 3;
230
247
  */
231
248
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
232
249
  /**
@@ -234,6 +251,38 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
234
251
  * @remarks Time O(1), Space O(1)
235
252
  * @param key - Key to look up.
236
253
  * @returns Value or undefined.
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+ * @example
266
+ * // HashMap get and has operations
267
+ * const map = new HashMap<string, number>([
268
+ * ['apple', 1],
269
+ * ['banana', 2],
270
+ * ['cherry', 3]
271
+ * ]);
272
+ *
273
+ * // Check if key exists
274
+ * console.log(map.has('apple')); // true;
275
+ * console.log(map.has('date')); // false;
276
+ *
277
+ * // Get value by key
278
+ * console.log(map.get('banana')); // 2;
279
+ * console.log(map.get('grape')); // undefined;
280
+ *
281
+ * // Get all keys and values
282
+ * const keys = [...map.keys()];
283
+ * const values = [...map.values()];
284
+ * console.log(keys); // contains 'apple';
285
+ * console.log(values); // contains 3;
237
286
  */
238
287
  get(key: K): V | undefined;
239
288
  /**
@@ -241,6 +290,23 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
241
290
  * @remarks Time O(1), Space O(1)
242
291
  * @param key - Key to test.
243
292
  * @returns True if present.
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+ * @example
305
+ * // Check key existence
306
+ * const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
307
+ *
308
+ * console.log(map.has('a')); // true;
309
+ * console.log(map.has('z')); // false;
244
310
  */
245
311
  has(key: K): boolean;
246
312
  /**
@@ -248,6 +314,24 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
248
314
  * @remarks Time O(1), Space O(1)
249
315
  * @param key - Key to delete.
250
316
  * @returns True if the key was found and removed.
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+ * @example
329
+ * // Remove entries by key
330
+ * const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
331
+ *
332
+ * console.log(map.delete('y')); // true;
333
+ * console.log(map.has('y')); // false;
334
+ * console.log(map.size); // 2;
251
335
  */
252
336
  delete(key: K): boolean;
253
337
  /**
@@ -261,6 +345,21 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
261
345
  * Deep clone this map, preserving hashing behavior.
262
346
  * @remarks Time O(N), Space O(N)
263
347
  * @returns A new map with the same content.
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+ * @example
358
+ * // Create independent copy
359
+ * const map = new HashMap<string, number>([['a', 1]]);
360
+ * const copy = map.clone();
361
+ * copy.set('a', 99);
362
+ * console.log(map.get('a')); // 1;
264
363
  */
265
364
  clone(): this;
266
365
  /**
@@ -270,6 +369,24 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
270
369
  * @param callbackfn - Mapping function (key, value, index, map) → newValue.
271
370
  * @param [thisArg] - Value for `this` inside the callback.
272
371
  * @returns A new map with transformed values.
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+ * @example
384
+ * // Transform all values
385
+ * const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
386
+ *
387
+ * const doubled = prices.map(v => (v ?? 0) * 2);
388
+ * console.log(doubled.get('apple')); // 2;
389
+ * console.log(doubled.get('banana')); // 4;
273
390
  */
274
391
  map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): any;
275
392
  /**
@@ -278,6 +395,42 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
278
395
  * @param predicate - Predicate (key, value, index, map) → boolean.
279
396
  * @param [thisArg] - Value for `this` inside the predicate.
280
397
  * @returns A new map containing entries that satisfied the predicate.
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+ * @example
410
+ * // HashMap iteration and filter operations
411
+ * const map = new HashMap<number, string>([
412
+ * [1, 'Alice'],
413
+ * [2, 'Bob'],
414
+ * [3, 'Charlie'],
415
+ * [4, 'Diana'],
416
+ * [5, 'Eve']
417
+ * ]);
418
+ *
419
+ * // Iterate through entries
420
+ * const entries: [number, string][] = [];
421
+ * for (const [key, value] of map) {
422
+ * entries.push([key, value]);
423
+ * }
424
+ * console.log(entries); // length: 5;
425
+ *
426
+ * // Filter operation (for iteration with collection methods)
427
+ * const filtered = [...map].filter(([key]) => key > 2);
428
+ * console.log(filtered.length); // 3;
429
+ *
430
+ * // Map operation
431
+ * const values = [...map.values()].map(v => v.length);
432
+ * console.log(values); // contains 3; // 'Bob', 'Eve'
433
+ * console.log(values); // contains 7;
281
434
  */
282
435
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): any;
283
436
  /**