heap-typed 1.48.9 → 1.49.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 (82) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +16 -11
  2. package/dist/data-structures/binary-tree/avl-tree.js +12 -4
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +70 -61
  4. package/dist/data-structures/binary-tree/binary-tree.js +25 -21
  5. package/dist/data-structures/binary-tree/bst.d.ts +20 -13
  6. package/dist/data-structures/binary-tree/bst.js +12 -3
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -25
  8. package/dist/data-structures/binary-tree/rb-tree.js +21 -35
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +20 -13
  10. package/dist/data-structures/binary-tree/tree-multimap.js +12 -3
  11. package/dist/data-structures/graph/abstract-graph.d.ts +9 -3
  12. package/dist/data-structures/graph/abstract-graph.js +27 -31
  13. package/dist/data-structures/graph/directed-graph.d.ts +8 -1
  14. package/dist/data-structures/graph/directed-graph.js +1 -8
  15. package/dist/data-structures/graph/map-graph.d.ts +1 -1
  16. package/dist/data-structures/graph/undirected-graph.d.ts +8 -1
  17. package/dist/data-structures/graph/undirected-graph.js +1 -8
  18. package/dist/data-structures/hash/hash-map.d.ts +14 -2
  19. package/dist/data-structures/hash/hash-map.js +19 -8
  20. package/dist/data-structures/hash/hash-table.d.ts +2 -2
  21. package/dist/data-structures/heap/heap.d.ts +14 -3
  22. package/dist/data-structures/heap/heap.js +12 -0
  23. package/dist/data-structures/heap/max-heap.d.ts +11 -1
  24. package/dist/data-structures/heap/max-heap.js +10 -7
  25. package/dist/data-structures/heap/min-heap.d.ts +11 -1
  26. package/dist/data-structures/heap/min-heap.js +10 -7
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +6 -7
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  30. package/dist/data-structures/linked-list/singly-linked-list.js +0 -7
  31. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  32. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -7
  33. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  34. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -7
  35. package/dist/data-structures/priority-queue/priority-queue.d.ts +9 -1
  36. package/dist/data-structures/priority-queue/priority-queue.js +8 -7
  37. package/dist/data-structures/queue/deque.d.ts +6 -5
  38. package/dist/data-structures/queue/deque.js +6 -12
  39. package/dist/data-structures/queue/queue.d.ts +18 -3
  40. package/dist/data-structures/queue/queue.js +16 -6
  41. package/dist/data-structures/stack/stack.d.ts +15 -5
  42. package/dist/data-structures/stack/stack.js +7 -4
  43. package/dist/data-structures/trie/trie.d.ts +13 -3
  44. package/dist/data-structures/trie/trie.js +11 -8
  45. package/dist/interfaces/binary-tree.d.ts +4 -4
  46. package/dist/types/common.d.ts +32 -8
  47. package/dist/types/common.js +22 -1
  48. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  49. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -22
  50. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  51. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  52. package/package.json +2 -2
  53. package/src/data-structures/binary-tree/avl-tree.ts +23 -13
  54. package/src/data-structures/binary-tree/binary-tree.ts +93 -97
  55. package/src/data-structures/binary-tree/bst.ts +26 -15
  56. package/src/data-structures/binary-tree/rb-tree.ts +33 -48
  57. package/src/data-structures/binary-tree/tree-multimap.ts +32 -14
  58. package/src/data-structures/graph/abstract-graph.ts +35 -25
  59. package/src/data-structures/graph/directed-graph.ts +2 -2
  60. package/src/data-structures/graph/map-graph.ts +1 -1
  61. package/src/data-structures/graph/undirected-graph.ts +2 -2
  62. package/src/data-structures/hash/hash-map.ts +20 -3
  63. package/src/data-structures/hash/hash-table.ts +3 -3
  64. package/src/data-structures/heap/heap.ts +14 -3
  65. package/src/data-structures/heap/max-heap.ts +11 -2
  66. package/src/data-structures/heap/min-heap.ts +11 -2
  67. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -3
  68. package/src/data-structures/linked-list/singly-linked-list.ts +3 -3
  69. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  70. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  71. package/src/data-structures/priority-queue/priority-queue.ts +9 -2
  72. package/src/data-structures/queue/deque.ts +7 -9
  73. package/src/data-structures/queue/queue.ts +18 -3
  74. package/src/data-structures/stack/stack.ts +16 -6
  75. package/src/data-structures/trie/trie.ts +13 -4
  76. package/src/interfaces/binary-tree.ts +5 -5
  77. package/src/types/common.ts +37 -12
  78. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
  79. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
  80. package/src/types/data-structures/binary-tree/bst.ts +0 -1
  81. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  82. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
@@ -1,5 +1,12 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
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
+ */
2
8
  import type { VertexKey } from '../../types';
9
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
3
10
  import { IGraph } from '../../interfaces';
4
11
  export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
5
12
  /**
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Tyler Zeng
8
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
- * @license MIT License
10
- */
11
- const utils_1 = require("../../utils");
12
4
  const abstract_graph_1 = require("./abstract-graph");
5
+ const utils_1 = require("../../utils");
13
6
  class DirectedVertex extends abstract_graph_1.AbstractVertex {
14
7
  /**
15
8
  * The constructor function initializes a vertex with an optional value.
@@ -1,4 +1,4 @@
1
- import { MapGraphCoordinate, VertexKey } from '../../types';
1
+ import type { MapGraphCoordinate, VertexKey } from '../../types';
2
2
  import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
3
  export declare class MapVertex<V = any> extends DirectedVertex<V> {
4
4
  lat: number;
@@ -1,6 +1,13 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
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
+ */
2
8
  import type { VertexKey } from '../../types';
3
9
  import { IGraph } from '../../interfaces';
10
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
4
11
  export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
5
12
  /**
6
13
  * The constructor function initializes a vertex with an optional value.
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Tyler Zeng
8
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
- * @license MIT License
10
- */
11
- const utils_1 = require("../../utils");
12
4
  const abstract_graph_1 = require("./abstract-graph");
5
+ const utils_1 = require("../../utils");
13
6
  class UndirectedVertex extends abstract_graph_1.AbstractVertex {
14
7
  /**
15
8
  * The constructor function initializes a vertex with an optional value.
@@ -5,8 +5,14 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
9
- import { IterableEntryBase } from "../base";
8
+ import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
9
+ import { IterableEntryBase } from '../base';
10
+ /**
11
+ * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
12
+ * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete elements based on a key.
13
+ * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
14
+ * 4. Unordered Collection: HashMap does not guarantee the order of elements, and the order may change over time.
15
+ */
10
16
  export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
11
17
  protected _store: {
12
18
  [key: string]: HashMapStoreItem<K, V>;
@@ -117,6 +123,11 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
117
123
  protected _isObjKey(key: any): key is (object | ((...args: any[]) => any));
118
124
  protected _getNoObjKey(key: K): string;
119
125
  }
126
+ /**
127
+ * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which elements are inserted. Therefore, when you traverse it, elements will be returned in the order they were inserted into the map.
128
+ * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of elements through the linked list.
129
+ * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
130
+ */
120
131
  export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
121
132
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
122
133
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
@@ -169,6 +180,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
169
180
  */
170
181
  set(key: K, value?: V): number;
171
182
  has(key: K): boolean;
183
+ hasValue(value: V): boolean;
172
184
  setMany(entries: Iterable<[K, V]>): void;
173
185
  /**
174
186
  * Time Complexity: O(1)
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.LinkedHashMap = exports.HashMap = void 0;
11
- const utils_1 = require("../../utils");
12
4
  const base_1 = require("../base");
5
+ const utils_1 = require("../../utils");
6
+ /**
7
+ * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
8
+ * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete elements based on a key.
9
+ * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
10
+ * 4. Unordered Collection: HashMap does not guarantee the order of elements, and the order may change over time.
11
+ */
13
12
  class HashMap extends base_1.IterableEntryBase {
14
13
  /**
15
14
  * The constructor function initializes a new instance of a class with optional elements and options.
@@ -230,6 +229,11 @@ class HashMap extends base_1.IterableEntryBase {
230
229
  }
231
230
  }
232
231
  exports.HashMap = HashMap;
232
+ /**
233
+ * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which elements are inserted. Therefore, when you traverse it, elements will be returned in the order they were inserted into the map.
234
+ * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of elements through the linked list.
235
+ * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
236
+ */
233
237
  class LinkedHashMap extends base_1.IterableEntryBase {
234
238
  constructor(elements, options = {
235
239
  hashFn: (key) => String(key),
@@ -365,6 +369,13 @@ class LinkedHashMap extends base_1.IterableEntryBase {
365
369
  return hash in this._noObjMap;
366
370
  }
367
371
  }
372
+ hasValue(value) {
373
+ for (const [, elementValue] of this) {
374
+ if (elementValue === value)
375
+ return true;
376
+ }
377
+ return false;
378
+ }
368
379
  setMany(entries) {
369
380
  for (const entry of entries) {
370
381
  const [key, value] = entry;
@@ -5,13 +5,13 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- export declare class HashTableNode<K, V> {
8
+ import type { HashFunction } from '../../types';
9
+ export declare class HashTableNode<K = any, V = any> {
9
10
  key: K;
10
11
  value: V;
11
12
  next: HashTableNode<K, V> | undefined;
12
13
  constructor(key: K, value: V);
13
14
  }
14
- import { HashFunction } from '../../types';
15
15
  export declare class HashTable<K = any, V = any> {
16
16
  protected static readonly DEFAULT_CAPACITY = 16;
17
17
  protected static readonly LOAD_FACTOR = 0.75;
@@ -4,9 +4,20 @@
4
4
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
5
5
  * @license MIT License
6
6
  */
7
- import type { Comparator, DFSOrderPattern, ElementCallback } from '../../types';
8
- import { HeapOptions } from "../../types";
9
- import { IterableElementBase } from "../base";
7
+ import type { Comparator, DFSOrderPattern, ElementCallback, HeapOptions } from '../../types';
8
+ import { IterableElementBase } from '../base';
9
+ /**
10
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
11
+ * 2. Heap Properties: Each node in a heap follows a specific order property, which varies depending on the type of heap:
12
+ * Max Heap: The value of each parent node is greater than or equal to the value of its children.
13
+ * Min Heap: The value of each parent node is less than or equal to the value of its children.
14
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
15
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
16
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
17
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
18
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
19
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
20
+ */
10
21
  export declare class Heap<E = any> extends IterableElementBase<E> {
11
22
  options: HeapOptions<E>;
12
23
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
@@ -8,6 +8,18 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
10
10
  const base_1 = require("../base");
11
+ /**
12
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
13
+ * 2. Heap Properties: Each node in a heap follows a specific order property, which varies depending on the type of heap:
14
+ * Max Heap: The value of each parent node is greater than or equal to the value of its children.
15
+ * Min Heap: The value of each parent node is less than or equal to the value of its children.
16
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
17
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
18
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
19
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
20
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
21
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
22
+ */
11
23
  class Heap extends base_1.IterableElementBase {
12
24
  constructor(elements, options) {
13
25
  super();
@@ -5,8 +5,18 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { Heap } from './heap';
9
8
  import type { HeapOptions } from '../../types';
9
+ import { Heap } from './heap';
10
+ /**
11
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
12
+ * 2. Heap Properties: The value of each parent node is greater than or equal to the value of its children.
13
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
14
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
15
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
16
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
17
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
18
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
19
+ */
10
20
  export declare class MaxHeap<E = any> extends Heap<E> {
11
21
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
12
22
  }
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Kirk Qi
6
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.MaxHeap = void 0;
11
4
  const heap_1 = require("./heap");
5
+ /**
6
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
7
+ * 2. Heap Properties: The value of each parent node is greater than or equal to the value of its children.
8
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
9
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
10
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
11
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
12
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
13
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
14
+ */
12
15
  class MaxHeap extends heap_1.Heap {
13
16
  constructor(elements, options = {
14
17
  comparator: (a, b) => {
@@ -5,8 +5,18 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { Heap } from './heap';
9
8
  import type { HeapOptions } from '../../types';
9
+ import { Heap } from './heap';
10
+ /**
11
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
12
+ * 2. Heap Properties: The value of each parent node is less than or equal to the value of its children.
13
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
14
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
15
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
16
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
17
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
18
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
19
+ */
10
20
  export declare class MinHeap<E = any> extends Heap<E> {
11
21
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
12
22
  }
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Kirk Qi
6
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.MinHeap = void 0;
11
4
  const heap_1 = require("./heap");
5
+ /**
6
+ * 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
7
+ * 2. Heap Properties: The value of each parent node is less than or equal to the value of its children.
8
+ * 3. Root Node Access: In a heap, the largest element (in a max heap) or the smallest element (in a min heap) is always at the root of the tree.
9
+ * 4. Efficient Insertion and Deletion: Due to its structure, a heap allows for insertion and deletion operations in logarithmic time (O(log n)).
10
+ * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
11
+ * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
12
+ * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
13
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
14
+ */
12
15
  class MinHeap extends heap_1.Heap {
13
16
  constructor(elements, options = {
14
17
  comparator: (a, b) => {
@@ -1,5 +1,3 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
3
1
  /**
4
2
  * data-structure-typed
5
3
  *
@@ -7,6 +5,8 @@ import { ElementCallback } from "../../types";
7
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
8
6
  * @license MIT License
9
7
  */
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
10
  export declare class DoublyLinkedListNode<E = any> {
11
11
  value: E;
12
12
  next: DoublyLinkedListNode<E> | undefined;
@@ -18,6 +18,12 @@ export declare class DoublyLinkedListNode<E = any> {
18
18
  */
19
19
  constructor(value: E);
20
20
  }
21
+ /**
22
+ * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
23
+ * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
24
+ * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
25
+ * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
26
+ */
21
27
  export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
22
28
  /**
23
29
  * The constructor initializes the linked list with an empty head, tail, and length.
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
4
4
  const base_1 = require("../base");
5
- /**
6
- * data-structure-typed
7
- *
8
- * @author Tyler Zeng
9
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
10
- * @license MIT License
11
- */
12
5
  class DoublyLinkedListNode {
13
6
  /**
14
7
  * The constructor function initializes the value, next, and previous properties of an object.
@@ -22,6 +15,12 @@ class DoublyLinkedListNode {
22
15
  }
23
16
  }
24
17
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
18
+ /**
19
+ * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
20
+ * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
21
+ * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
22
+ * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
23
+ */
25
24
  class DoublyLinkedList extends base_1.IterableElementBase {
26
25
  /**
27
26
  * The constructor initializes the linked list with an empty head, tail, and length.
@@ -1,5 +1,3 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
3
1
  /**
4
2
  * data-structure-typed
5
3
  *
@@ -7,6 +5,8 @@ import { ElementCallback } from "../../types";
7
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
8
6
  * @license MIT License
9
7
  */
8
+ import type { ElementCallback } from "../../types";
9
+ import { IterableElementBase } from "../base";
10
10
  export declare class SinglyLinkedListNode<E = any> {
11
11
  value: E;
12
12
  next: SinglyLinkedListNode<E> | undefined;
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
4
4
  const base_1 = require("../base");
5
- /**
6
- * data-structure-typed
7
- *
8
- * @author Tyler Zeng
9
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
10
- * @license MIT License
11
- */
12
5
  class SinglyLinkedListNode {
13
6
  /**
14
7
  * The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { PriorityQueue } from './priority-queue';
9
8
  import type { PriorityQueueOptions } from '../../types';
9
+ import { PriorityQueue } from './priority-queue';
10
10
  export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
11
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
12
12
  }
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MaxPriorityQueue = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Kirk Qi
8
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
9
- * @license MIT License
10
- */
11
4
  const priority_queue_1 = require("./priority-queue");
12
5
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
6
  constructor(elements, options = {
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { PriorityQueue } from './priority-queue';
9
8
  import type { PriorityQueueOptions } from '../../types';
9
+ import { PriorityQueue } from './priority-queue';
10
10
  export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
11
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
12
12
  }
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MinPriorityQueue = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Kirk Qi
8
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
9
- * @license MIT License
10
- */
11
4
  const priority_queue_1 = require("./priority-queue");
12
5
  class MinPriorityQueue extends priority_queue_1.PriorityQueue {
13
6
  constructor(elements, options = {
@@ -5,8 +5,16 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
+ import type { PriorityQueueOptions } from '../../types';
8
9
  import { Heap } from '../heap';
9
- import { PriorityQueueOptions } from '../../types';
10
+ /**
11
+ * 1. Element Priority: In a PriorityQueue, elements are sorted according to their priority. Each dequeue (element removal) operation removes the element with the highest priority. The priority can be determined based on the natural ordering of the elements or through a provided comparator (Comparator).
12
+ * 2. Heap-Based Implementation: PriorityQueue is typically implemented using a binary heap, allowing both insertion and removal operations to be completed in O(log n) time, where n is the number of elements in the queue.
13
+ * 3. Task Scheduling: In systems where tasks need to be processed based on the urgency of tasks rather than the order of arrival.
14
+ * 4. Dijkstra's Algorithm: In shortest path algorithms for graphs, used to select the next shortest edge to visit.
15
+ * 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
16
+ * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
17
+ */
10
18
  export declare class PriorityQueue<E = any> extends Heap<E> {
11
19
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
12
20
  }
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Kirk Qi
6
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.PriorityQueue = void 0;
11
4
  const heap_1 = require("../heap");
5
+ /**
6
+ * 1. Element Priority: In a PriorityQueue, elements are sorted according to their priority. Each dequeue (element removal) operation removes the element with the highest priority. The priority can be determined based on the natural ordering of the elements or through a provided comparator (Comparator).
7
+ * 2. Heap-Based Implementation: PriorityQueue is typically implemented using a binary heap, allowing both insertion and removal operations to be completed in O(log n) time, where n is the number of elements in the queue.
8
+ * 3. Task Scheduling: In systems where tasks need to be processed based on the urgency of tasks rather than the order of arrival.
9
+ * 4. Dijkstra's Algorithm: In shortest path algorithms for graphs, used to select the next shortest edge to visit.
10
+ * 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
11
+ * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
12
+ */
12
13
  class PriorityQueue extends heap_1.Heap {
13
14
  constructor(elements, options) {
14
15
  super(elements, options);
@@ -5,13 +5,14 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { ElementCallback, IterableWithSizeOrLength } from "../../types";
8
+ import type { ElementCallback, IterableWithSizeOrLength } from "../../types";
9
9
  import { IterableElementBase } from "../base";
10
10
  /**
11
- * Deque can provide random access with O(1) time complexity
12
- * Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
13
- * Deque may experience performance jitter, but DoublyLinkedList will not
14
- * Deque is implemented using a dynamic array. Inserting or deleting beyond both ends of the array may require moving elements or reallocating space.
11
+ * 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
12
+ * 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
13
+ * 3. Continuous Memory Allocation: Since it is based on an array, all elements are stored contiguously in memory, which can bring cache friendliness and efficient memory access.
14
+ * 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
15
+ * 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
15
16
  */
16
17
  export declare class Deque<E> extends IterableElementBase<E> {
17
18
  protected _bucketFirst: number;
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.Deque = void 0;
11
- const utils_1 = require("../../utils");
12
4
  const base_1 = require("../base");
5
+ const utils_1 = require("../../utils");
13
6
  /**
14
- * Deque can provide random access with O(1) time complexity
15
- * Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
16
- * Deque may experience performance jitter, but DoublyLinkedList will not
17
- * Deque is implemented using a dynamic array. Inserting or deleting beyond both ends of the array may require moving elements or reallocating space.
7
+ * 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
8
+ * 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
9
+ * 3. Continuous Memory Allocation: Since it is based on an array, all elements are stored contiguously in memory, which can bring cache friendliness and efficient memory access.
10
+ * 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
11
+ * 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
18
12
  */
19
13
  class Deque extends base_1.IterableElementBase {
20
14
  /**
@@ -3,9 +3,18 @@
3
3
  * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
- import { SinglyLinkedList } from '../linked-list';
6
+ import type { ElementCallback } from '../../types';
7
7
  import { IterableElementBase } from "../base";
8
- import { ElementCallback } from "../../types";
8
+ import { SinglyLinkedList } from '../linked-list';
9
+ /**
10
+ * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
11
+ * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
12
+ * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
13
+ * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
14
+ * 5. Data Buffering: Acting as a buffer for data packets in network communication.
15
+ * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store nodes that are to be visited.
16
+ * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
17
+ */
9
18
  export declare class Queue<E = any> extends IterableElementBase<E> {
10
19
  /**
11
20
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -121,7 +130,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
121
130
  * The enqueue function adds a value to the end of a queue.
122
131
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
123
132
  */
124
- enqueue(value: E): void;
133
+ enqueue(value: E): Queue<E>;
125
134
  /**
126
135
  * Time Complexity: O(n) - same as shift().
127
136
  * Space Complexity: O(1) - same as shift().
@@ -232,6 +241,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
232
241
  */
233
242
  protected _getIterator(): Generator<E, void, unknown>;
234
243
  }
244
+ /**
245
+ * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
246
+ * 2. Based on Linked List: LinkedListQueue uses a linked list to store elements. Each node in the linked list contains data and a pointer to the next node.
247
+ * 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
248
+ * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
249
+ */
235
250
  export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
236
251
  /**
237
252
  * The enqueue function adds a value to the end of an array.