deque-typed 1.49.0 → 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 +10 -12
  2. package/dist/data-structures/binary-tree/avl-tree.js +3 -4
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -58
  4. package/dist/data-structures/binary-tree/binary-tree.js +6 -6
  5. package/dist/data-structures/binary-tree/bst.d.ts +15 -15
  6. package/dist/data-structures/binary-tree/bst.js +3 -3
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -11
  8. package/dist/data-structures/binary-tree/rb-tree.js +5 -6
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  10. package/dist/data-structures/binary-tree/tree-multimap.js +3 -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 +14 -14
  54. package/src/data-structures/binary-tree/binary-tree.ts +74 -77
  55. package/src/data-structures/binary-tree/bst.ts +18 -17
  56. package/src/data-structures/binary-tree/rb-tree.ts +17 -18
  57. package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
  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
@@ -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.
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkedListQueue = exports.Queue = void 0;
4
+ const base_1 = require("../base");
5
+ const linked_list_1 = require("../linked-list");
4
6
  /**
5
- * @license MIT
6
- * @copyright Tyler Zeng <zrwusa@gmail.com>
7
- * @class
7
+ * 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.
8
+ * 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).
9
+ * 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.
10
+ * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
11
+ * 5. Data Buffering: Acting as a buffer for data packets in network communication.
12
+ * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store nodes that are to be visited.
13
+ * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
8
14
  */
9
- const linked_list_1 = require("../linked-list");
10
- const base_1 = require("../base");
11
15
  class Queue extends base_1.IterableElementBase {
12
16
  /**
13
17
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -157,7 +161,7 @@ class Queue extends base_1.IterableElementBase {
157
161
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
158
162
  */
159
163
  enqueue(value) {
160
- this.push(value);
164
+ return this.push(value);
161
165
  }
162
166
  /**
163
167
  * Time Complexity: O(n) - same as shift().
@@ -307,6 +311,12 @@ class Queue extends base_1.IterableElementBase {
307
311
  }
308
312
  }
309
313
  exports.Queue = Queue;
314
+ /**
315
+ * 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.
316
+ * 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.
317
+ * 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.
318
+ * 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.
319
+ */
310
320
  class LinkedListQueue extends linked_list_1.SinglyLinkedList {
311
321
  /**
312
322
  * The enqueue function adds a value to the end of an array.
@@ -1,9 +1,19 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
3
1
  /**
4
- * @license MIT
5
- * @copyright Tyler Zeng <zrwusa@gmail.com>
6
- * @class
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
+ /**
11
+ * 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
12
+ * 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
13
+ * 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
14
+ * 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
15
+ * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
16
+ * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
7
17
  */
8
18
  export declare class Stack<E = any> extends IterableElementBase<E> {
9
19
  /**
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stack = void 0;
4
4
  const base_1 = require("../base");
5
5
  /**
6
- * @license MIT
7
- * @copyright Tyler Zeng <zrwusa@gmail.com>
8
- * @class
6
+ * 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
7
+ * 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
8
+ * 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
9
+ * 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
10
+ * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
11
+ * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
9
12
  */
10
13
  class Stack extends base_1.IterableElementBase {
11
14
  /**
@@ -103,7 +106,7 @@ class Stack extends base_1.IterableElementBase {
103
106
  pop() {
104
107
  if (this.isEmpty())
105
108
  return undefined;
106
- return this.elements.pop() || undefined;
109
+ return this.elements.pop();
107
110
  }
108
111
  /**
109
112
  * Time Complexity: O(n)
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { IterableElementBase } from "../base";
9
- import { ElementCallback } from "../../types";
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
10
  /**
11
11
  * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
12
12
  * and a flag indicating whether it's the end of a word.
@@ -18,7 +18,17 @@ export declare class TrieNode {
18
18
  constructor(key: string);
19
19
  }
20
20
  /**
21
- * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
21
+ * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
22
+ * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
23
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
24
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
25
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
26
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
27
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
28
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
29
+ * 9. Spell Check: Checking the spelling of words.
30
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
31
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
22
32
  */
23
33
  export declare class Trie extends IterableElementBase<string> {
24
34
  constructor(words?: string[], caseSensitive?: boolean);
@@ -1,11 +1,4 @@
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.Trie = exports.TrieNode = void 0;
11
4
  const base_1 = require("../base");
@@ -22,7 +15,17 @@ class TrieNode {
22
15
  }
23
16
  exports.TrieNode = TrieNode;
24
17
  /**
25
- * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
18
+ * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
19
+ * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
20
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
21
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
22
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
23
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
24
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
25
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
26
+ * 9. Spell Check: Checking the spelling of words.
27
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
28
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
26
29
  */
27
30
  class Trie extends base_1.IterableElementBase {
28
31
  constructor(words, caseSensitive = true) {
@@ -1,9 +1,9 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNodeExemplar } from '../types';
2
+ import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNExemplar } from '../types';
3
3
  export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
4
4
  createNode(key: K, value?: N['value']): N;
5
5
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
6
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
7
- addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
8
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
6
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
7
+ addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
8
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
9
9
  }
@@ -1,15 +1,35 @@
1
- export type Comparator<K> = (a: K, b: K) => number;
2
1
  export declare enum BSTVariant {
3
2
  MIN = "MIN",
4
3
  MAX = "MAX"
5
4
  }
6
- export type DFSOrderPattern = 'pre' | 'in' | 'post';
7
- export type BTNCallback<N, D = any> = (node: N) => D;
8
5
  export declare enum CP {
9
6
  lt = "lt",
10
7
  eq = "eq",
11
8
  gt = "gt"
12
9
  }
10
+ /**
11
+ * Enum representing different loop types.
12
+ *
13
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
14
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
15
+ */
16
+ export declare enum IterationType {
17
+ ITERATIVE = "ITERATIVE",
18
+ RECURSIVE = "RECURSIVE"
19
+ }
20
+ export declare enum FamilyPosition {
21
+ ROOT = "ROOT",
22
+ LEFT = "LEFT",
23
+ RIGHT = "RIGHT",
24
+ ROOT_LEFT = "ROOT_LEFT",
25
+ ROOT_RIGHT = "ROOT_RIGHT",
26
+ ISOLATED = "ISOLATED",
27
+ MAL_NODE = "MAL_NODE"
28
+ }
29
+ export type Comparator<K> = (a: K, b: K) => number;
30
+ export type DFSOrderPattern = 'pre' | 'in' | 'post';
31
+ export type NodeDisplayLayout = [string[], number, number, number];
32
+ export type BTNCallback<N, D = any> = (node: N) => D;
13
33
  export interface IterableWithSize<T> extends Iterable<T> {
14
34
  size: number | ((...args: any[]) => number);
15
35
  }
@@ -22,9 +42,13 @@ export type BinaryTreePrintOptions = {
22
42
  isShowNull?: boolean;
23
43
  isShowRedBlackNIL?: boolean;
24
44
  };
25
- export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
26
- export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
27
- export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>;
28
- export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
45
+ export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
46
+ export type BTNKeyOrNode<K, N> = K | null | undefined | N;
47
+ export type BTNExemplar<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
29
48
  export type BTNodePureKeyOrNode<K, N> = K | N;
30
- export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
49
+ export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
50
+ export type BSTNKeyOrNode<K, N> = K | undefined | N;
51
+ export type BinaryTreeDeleteResult<N> = {
52
+ deleted: N | null | undefined;
53
+ needBalanced: N | null | undefined;
54
+ };