queue-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.
- package/dist/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/data-structures/binary-tree/bst.js +3 -3
- package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/data-structures/graph/abstract-graph.js +27 -31
- package/dist/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/data-structures/graph/directed-graph.js +1 -8
- package/dist/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/data-structures/graph/undirected-graph.js +1 -8
- package/dist/data-structures/hash/hash-map.d.ts +14 -2
- package/dist/data-structures/hash/hash-map.js +19 -8
- package/dist/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +14 -3
- package/dist/data-structures/heap/heap.js +12 -0
- package/dist/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/data-structures/heap/max-heap.js +10 -7
- package/dist/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/data-structures/heap/min-heap.js +10 -7
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +6 -7
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -7
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/data-structures/queue/deque.d.ts +6 -5
- package/dist/data-structures/queue/deque.js +6 -12
- package/dist/data-structures/queue/queue.d.ts +18 -3
- package/dist/data-structures/queue/queue.js +16 -6
- package/dist/data-structures/stack/stack.d.ts +15 -5
- package/dist/data-structures/stack/stack.js +7 -4
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +11 -8
- package/dist/interfaces/binary-tree.d.ts +4 -4
- package/dist/types/common.d.ts +32 -8
- package/dist/types/common.js +22 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +74 -77
- package/src/data-structures/binary-tree/bst.ts +18 -17
- package/src/data-structures/binary-tree/rb-tree.ts +17 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +20 -3
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +14 -3
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +7 -9
- package/src/data-structures/queue/queue.ts +18 -3
- package/src/data-structures/stack/stack.ts +16 -6
- package/src/data-structures/trie/trie.ts +13 -4
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { IterableElementBase } from "../base";
|
|
2
|
-
import { ElementCallback } from "../../types";
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* data-structure-typed
|
|
6
3
|
*
|
|
@@ -8,6 +5,9 @@ import { ElementCallback } from "../../types";
|
|
|
8
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
6
|
* @license MIT License
|
|
10
7
|
*/
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
10
|
+
|
|
11
11
|
export class DoublyLinkedListNode<E = any> {
|
|
12
12
|
value: E;
|
|
13
13
|
next: DoublyLinkedListNode<E> | undefined;
|
|
@@ -25,6 +25,12 @@ export class DoublyLinkedListNode<E = any> {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* 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.
|
|
30
|
+
* 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.
|
|
31
|
+
* 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.
|
|
32
|
+
* 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.
|
|
33
|
+
*/
|
|
28
34
|
export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
29
35
|
/**
|
|
30
36
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { IterableElementBase } from "../base";
|
|
2
|
-
import { ElementCallback } from "../../types";
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* data-structure-typed
|
|
6
3
|
*
|
|
@@ -8,6 +5,9 @@ import { ElementCallback } from "../../types";
|
|
|
8
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
6
|
* @license MIT License
|
|
10
7
|
*/
|
|
8
|
+
import type { ElementCallback } from "../../types";
|
|
9
|
+
import { IterableElementBase } from "../base";
|
|
10
|
+
|
|
11
11
|
export class SinglyLinkedListNode<E = any> {
|
|
12
12
|
value: E;
|
|
13
13
|
next: SinglyLinkedListNode<E> | 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
|
|
|
11
11
|
export class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
12
|
constructor(
|
|
@@ -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
|
|
|
11
11
|
export class MinPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
12
|
constructor(elements?: Iterable<E>,
|
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
import type { PriorityQueueOptions } from '../../types';
|
|
9
9
|
import { Heap } from '../heap';
|
|
10
|
-
import { PriorityQueueOptions } from '../../types';
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 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).
|
|
13
|
+
* 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.
|
|
14
|
+
* 3. Task Scheduling: In systems where tasks need to be processed based on the urgency of tasks rather than the order of arrival.
|
|
15
|
+
* 4. Dijkstra's Algorithm: In shortest path algorithms for graphs, used to select the next shortest edge to visit.
|
|
16
|
+
* 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
|
|
17
|
+
* 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
|
|
18
|
+
*/
|
|
12
19
|
export class PriorityQueue<E = any> extends Heap<E> {
|
|
13
20
|
constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>) {
|
|
14
21
|
super(elements, options);
|
|
@@ -5,19 +5,17 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { ElementCallback, IterableWithSizeOrLength } from "../../types";
|
|
11
|
-
import { calcMinUnitsRequired, rangeCheck } from "../../utils";
|
|
8
|
+
import type { ElementCallback, IterableWithSizeOrLength } from "../../types";
|
|
12
9
|
import { IterableElementBase } from "../base";
|
|
10
|
+
import { calcMinUnitsRequired, rangeCheck } from "../../utils";
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* 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).
|
|
14
|
+
* 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
|
|
15
|
+
* 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.
|
|
16
|
+
* 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).
|
|
17
|
+
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
19
|
export class Deque<E> extends IterableElementBase<E> {
|
|
22
20
|
protected _bucketFirst = 0;
|
|
23
21
|
protected _firstInBucket = 0;
|
|
@@ -3,10 +3,19 @@
|
|
|
3
3
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import type { ElementCallback } from '../../types';
|
|
7
7
|
import { IterableElementBase } from "../base";
|
|
8
|
-
import {
|
|
8
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 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.
|
|
12
|
+
* 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).
|
|
13
|
+
* 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.
|
|
14
|
+
* 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
|
|
15
|
+
* 5. Data Buffering: Acting as a buffer for data packets in network communication.
|
|
16
|
+
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store nodes that are to be visited.
|
|
17
|
+
* 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
18
|
+
*/
|
|
10
19
|
export class Queue<E = any> extends IterableElementBase<E> {
|
|
11
20
|
/**
|
|
12
21
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
@@ -179,7 +188,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
179
188
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
180
189
|
*/
|
|
181
190
|
enqueue(value: E) {
|
|
182
|
-
this.push(value);
|
|
191
|
+
return this.push(value);
|
|
183
192
|
}
|
|
184
193
|
|
|
185
194
|
/**
|
|
@@ -346,6 +355,12 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
346
355
|
}
|
|
347
356
|
}
|
|
348
357
|
|
|
358
|
+
/**
|
|
359
|
+
* 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.
|
|
360
|
+
* 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.
|
|
361
|
+
* 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.
|
|
362
|
+
* 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.
|
|
363
|
+
*/
|
|
349
364
|
export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
350
365
|
/**
|
|
351
366
|
* The enqueue function adds a value to the end of an array.
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
*/
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
3
10
|
|
|
4
11
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
12
|
+
* 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.
|
|
13
|
+
* 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.
|
|
14
|
+
* 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.
|
|
15
|
+
* 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.
|
|
16
|
+
* 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
|
|
17
|
+
* 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.
|
|
8
18
|
*/
|
|
9
19
|
export class Stack<E = any> extends IterableElementBase<E> {
|
|
10
20
|
/**
|
|
@@ -115,7 +125,7 @@ export class Stack<E = any> extends IterableElementBase<E> {
|
|
|
115
125
|
pop(): E | undefined {
|
|
116
126
|
if (this.isEmpty()) return undefined;
|
|
117
127
|
|
|
118
|
-
return this.elements.pop()
|
|
128
|
+
return this.elements.pop();
|
|
119
129
|
}
|
|
120
130
|
|
|
121
131
|
/**
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
import { IterableElementBase } from
|
|
10
|
-
import { ElementCallback } from "../../types";
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
@@ -26,7 +25,17 @@ export class TrieNode {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
* Trie represents a
|
|
28
|
+
* 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.
|
|
29
|
+
* 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'.
|
|
30
|
+
* 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
|
|
31
|
+
* 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
|
|
32
|
+
* 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.
|
|
33
|
+
* 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
|
|
34
|
+
* 7. String Retrieval: For example, searching for a specific string in a large set of strings.
|
|
35
|
+
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
36
|
+
* 9. Spell Check: Checking the spelling of words.
|
|
37
|
+
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
38
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
30
39
|
*/
|
|
31
40
|
export class Trie extends IterableElementBase<string> {
|
|
32
41
|
constructor(words?: string[], caseSensitive = true) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
2
|
import {
|
|
3
|
+
BinaryTreeDeleteResult,
|
|
3
4
|
BinaryTreeNested,
|
|
4
5
|
BinaryTreeNodeNested,
|
|
5
6
|
BinaryTreeOptions,
|
|
6
|
-
BiTreeDeleteResult,
|
|
7
7
|
BTNCallback,
|
|
8
|
-
|
|
8
|
+
BTNExemplar,
|
|
9
9
|
} from '../types';
|
|
10
10
|
|
|
11
11
|
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>> {
|
|
@@ -13,9 +13,9 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
|
|
|
13
13
|
|
|
14
14
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
15
15
|
|
|
16
|
-
add(keyOrNodeOrEntry:
|
|
16
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
17
17
|
|
|
18
|
-
addMany(nodes: Iterable<
|
|
18
|
+
addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
19
19
|
|
|
20
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C):
|
|
20
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
|
|
21
21
|
}
|
package/src/types/common.ts
CHANGED
|
@@ -1,20 +1,43 @@
|
|
|
1
|
-
export type Comparator<K> = (a: K, b: K) => number;
|
|
2
|
-
|
|
3
1
|
export enum BSTVariant {
|
|
4
2
|
MIN = 'MIN',
|
|
5
3
|
MAX = 'MAX',
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
9
|
-
|
|
10
|
-
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
11
|
-
|
|
12
6
|
export enum CP {
|
|
13
7
|
lt = 'lt',
|
|
14
8
|
eq = 'eq',
|
|
15
9
|
gt = 'gt'
|
|
16
10
|
}
|
|
17
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Enum representing different loop types.
|
|
14
|
+
*
|
|
15
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
16
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
17
|
+
*/
|
|
18
|
+
export enum IterationType {
|
|
19
|
+
ITERATIVE = 'ITERATIVE',
|
|
20
|
+
RECURSIVE = 'RECURSIVE'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum FamilyPosition {
|
|
24
|
+
ROOT = 'ROOT',
|
|
25
|
+
LEFT = 'LEFT',
|
|
26
|
+
RIGHT = 'RIGHT',
|
|
27
|
+
ROOT_LEFT = 'ROOT_LEFT',
|
|
28
|
+
ROOT_RIGHT = 'ROOT_RIGHT',
|
|
29
|
+
ISOLATED = 'ISOLATED',
|
|
30
|
+
MAL_NODE = 'MAL_NODE'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type Comparator<K> = (a: K, b: K) => number;
|
|
34
|
+
|
|
35
|
+
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
36
|
+
|
|
37
|
+
export type NodeDisplayLayout = [string[], number, number, number];
|
|
38
|
+
|
|
39
|
+
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
40
|
+
|
|
18
41
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
19
42
|
size: number | ((...args: any[]) => number);
|
|
20
43
|
}
|
|
@@ -27,14 +50,16 @@ export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLeng
|
|
|
27
50
|
|
|
28
51
|
export type BinaryTreePrintOptions = { isShowUndefined?: boolean, isShowNull?: boolean, isShowRedBlackNIL?: boolean }
|
|
29
52
|
|
|
30
|
-
export type
|
|
31
|
-
|
|
32
|
-
export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
|
|
53
|
+
export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
33
54
|
|
|
34
|
-
export type
|
|
55
|
+
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
35
56
|
|
|
36
|
-
export type
|
|
57
|
+
export type BTNExemplar<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>
|
|
37
58
|
|
|
38
59
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
39
60
|
|
|
40
|
-
export type
|
|
61
|
+
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
62
|
+
|
|
63
|
+
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
|
64
|
+
|
|
65
|
+
export type BinaryTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
|
|
@@ -5,5 +5,4 @@ export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTre
|
|
|
5
5
|
|
|
6
6
|
export type AVLTreeNested<K, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Enum representing different loop types.
|
|
5
|
-
*
|
|
6
|
-
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
7
|
-
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export enum IterationType {
|
|
11
|
-
ITERATIVE = 'ITERATIVE',
|
|
12
|
-
RECURSIVE = 'RECURSIVE'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export enum FamilyPosition {
|
|
16
|
-
ROOT = 'ROOT',
|
|
17
|
-
LEFT = 'LEFT',
|
|
18
|
-
RIGHT = 'RIGHT',
|
|
19
|
-
ROOT_LEFT = 'ROOT_LEFT',
|
|
20
|
-
ROOT_RIGHT = 'ROOT_RIGHT',
|
|
21
|
-
ISOLATED = 'ISOLATED',
|
|
22
|
-
MAL_NODE = 'MAL_NODE'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type BiTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
|
|
2
|
+
import { IterationType } from "../../common";
|
|
26
3
|
|
|
27
4
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
28
5
|
|
|
@@ -32,5 +9,3 @@ export type BinaryTreeOptions<K> = {
|
|
|
32
9
|
iterationType: IterationType,
|
|
33
10
|
extractor: (key: K) => number
|
|
34
11
|
}
|
|
35
|
-
|
|
36
|
-
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -2,7 +2,6 @@ import { BST, BSTNode } from '../../../data-structures';
|
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
3
|
import { BSTVariant } from "../../common";
|
|
4
4
|
|
|
5
|
-
// prettier-ignore
|
|
6
5
|
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
6
|
|
|
8
7
|
export type BSTNested<K, V, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
|
-
import { AVLTreeOptions } from './avl-tree';
|
|
2
|
+
import type { AVLTreeOptions } from './avl-tree';
|
|
3
3
|
|
|
4
4
|
export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
|