linked-list-typed 1.38.0 → 1.38.2
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 +100 -0
- package/dist/data-structures/binary-tree/avl-tree.js +341 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +144 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +261 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +409 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1065 -0
- package/dist/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/data-structures/binary-tree/bst.js +512 -0
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +23 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/rb-tree.js +27 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +228 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +122 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +351 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +923 -0
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +422 -0
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/index.js +20 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +111 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +252 -0
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +65 -0
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +55 -0
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +171 -0
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +245 -0
- package/dist/data-structures/hash/index.d.ts +6 -0
- package/dist/data-structures/hash/index.js +22 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.js +6 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.js +6 -0
- package/dist/data-structures/heap/heap.d.ts +224 -0
- package/dist/data-structures/heap/heap.js +497 -0
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.d.ts +12 -0
- package/dist/data-structures/heap/max-heap.js +24 -0
- package/dist/data-structures/heap/min-heap.d.ts +12 -0
- package/dist/data-structures/heap/min-heap.js +24 -0
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/index.js +27 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +583 -0
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/index.js +19 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +448 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +142 -0
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/index.js +20 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +28 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +203 -0
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +106 -0
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +291 -0
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +24 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +24 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +276 -0
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/index.js +18 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +170 -0
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +91 -0
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +58 -0
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.d.ts +84 -0
- package/dist/data-structures/trie/trie.js +268 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/interfaces/binary-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/graph.d.ts +5 -0
- package/dist/interfaces/graph.js +2 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/index.js +22 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/graph/directed-graph.js +9 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/index.js +19 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/map-graph.js +2 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-map.js +2 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-table.js +2 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/hash/index.js +2 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.js +2 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.js +2 -0
- package/dist/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.js +2 -0
- package/dist/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/data-structures/heap/index.js +17 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/max-heap.js +2 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/min-heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +11 -0
- package/dist/types/data-structures/index.js +27 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/index.js +18 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +17 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix.js +2 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/data-structures/matrix/navigator.js +2 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/index.js +19 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/types/data-structures/queue/deque.js +2 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/index.js +18 -0
- package/dist/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.js +2 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/index.js +17 -0
- package/dist/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.js +2 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/index.js +17 -0
- package/dist/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.js +2 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/index.js +17 -0
- package/dist/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.js +2 -0
- package/dist/types/helpers.d.ts +9 -0
- package/dist/types/helpers.js +9 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +73 -0
- package/package.json +1 -4
- package/src/data-structures/binary-tree/avl-tree.ts +342 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +298 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1141 -0
- package/src/data-structures/binary-tree/bst.ts +529 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +366 -0
- package/src/data-structures/binary-tree/segment-tree.ts +257 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +374 -0
- package/src/data-structures/graph/abstract-graph.ts +1043 -0
- package/src/data-structures/graph/directed-graph.ts +469 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +134 -0
- package/src/data-structures/graph/undirected-graph.ts +273 -0
- package/src/data-structures/hash/coordinate-map.ts +67 -0
- package/src/data-structures/hash/coordinate-set.ts +56 -0
- package/src/data-structures/hash/hash-map.ts +209 -0
- package/src/data-structures/hash/hash-table.ts +280 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/tree-map.ts +2 -0
- package/src/data-structures/hash/tree-set.ts +2 -0
- package/src/data-structures/heap/heap.ts +561 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +24 -0
- package/src/data-structures/heap/min-heap.ts +24 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +213 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +317 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +23 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +23 -0
- package/src/data-structures/priority-queue/priority-queue.ts +16 -0
- package/src/data-structures/queue/deque.ts +298 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +191 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +98 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +67 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +286 -0
- package/src/index.ts +3 -3
- package/src/interfaces/binary-tree.ts +10 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +8 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +11 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/helpers.ts +13 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +86 -0
|
@@ -0,0 +1,100 @@
|
|
|
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 { BST, BSTNode } from './bst';
|
|
9
|
+
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
|
|
10
|
+
import { IBinaryTree } from '../../interfaces';
|
|
11
|
+
export declare class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTreeNodeNested<V>> extends BSTNode<V, FAMILY> {
|
|
12
|
+
height: number;
|
|
13
|
+
constructor(key: BinaryTreeNodeKey, val?: V);
|
|
14
|
+
}
|
|
15
|
+
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IBinaryTree<N> {
|
|
16
|
+
/**
|
|
17
|
+
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
18
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
19
|
+
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
20
|
+
* options.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options?: AVLTreeOptions);
|
|
23
|
+
/**
|
|
24
|
+
* The function creates a new AVL tree node with the specified key and value.
|
|
25
|
+
* @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
|
|
26
|
+
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
27
|
+
* @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
|
|
28
|
+
* type `N['val']`, which means it can be any value that is assignable to the `val` property of the
|
|
29
|
+
* node type `N`.
|
|
30
|
+
* @returns a new AVLTreeNode object with the specified key and value.
|
|
31
|
+
*/
|
|
32
|
+
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
|
|
33
|
+
/**
|
|
34
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
35
|
+
* a new node.
|
|
36
|
+
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
37
|
+
* `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
38
|
+
* @param [val] - The `val` parameter is the value that you want to assign to the new node that you
|
|
39
|
+
* are adding to the binary search tree.
|
|
40
|
+
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
45
|
+
* node if necessary.
|
|
46
|
+
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
|
|
47
|
+
* (`N`) or a key value (`BinaryTreeNodeKey`).
|
|
48
|
+
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
49
|
+
*/
|
|
50
|
+
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
|
|
51
|
+
/**
|
|
52
|
+
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
53
|
+
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
54
|
+
* with the `destNode`.
|
|
55
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
56
|
+
* from the source node (`srcNode`) will be swapped to.
|
|
57
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
58
|
+
*/
|
|
59
|
+
protected _swap(srcNode: N, destNode: N): N;
|
|
60
|
+
/**
|
|
61
|
+
* The function calculates the balance factor of a node in a binary tree.
|
|
62
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
63
|
+
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
64
|
+
* height of the left subtree from the height of the right subtree.
|
|
65
|
+
*/
|
|
66
|
+
protected _balanceFactor(node: N): number;
|
|
67
|
+
/**
|
|
68
|
+
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
69
|
+
* right children.
|
|
70
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
71
|
+
*/
|
|
72
|
+
protected _updateHeight(node: N): void;
|
|
73
|
+
/**
|
|
74
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
75
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
76
|
+
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
77
|
+
* AVL tree that needs to be balanced.
|
|
78
|
+
*/
|
|
79
|
+
protected _balancePath(node: N): void;
|
|
80
|
+
/**
|
|
81
|
+
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
82
|
+
* @param {N} A - A is a node in a binary tree.
|
|
83
|
+
*/
|
|
84
|
+
protected _balanceLL(A: N): void;
|
|
85
|
+
/**
|
|
86
|
+
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
87
|
+
* @param {N} A - A is a node in a binary tree.
|
|
88
|
+
*/
|
|
89
|
+
protected _balanceLR(A: N): void;
|
|
90
|
+
/**
|
|
91
|
+
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
92
|
+
* @param {N} A - A is a node in a binary tree.
|
|
93
|
+
*/
|
|
94
|
+
protected _balanceRR(A: N): void;
|
|
95
|
+
/**
|
|
96
|
+
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
97
|
+
* @param {N} A - A is a node in a binary tree.
|
|
98
|
+
*/
|
|
99
|
+
protected _balanceRL(A: N): void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVLTree = exports.AVLTreeNode = 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 bst_1 = require("./bst");
|
|
12
|
+
class AVLTreeNode extends bst_1.BSTNode {
|
|
13
|
+
constructor(key, val) {
|
|
14
|
+
super(key, val);
|
|
15
|
+
this.height = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AVLTreeNode = AVLTreeNode;
|
|
19
|
+
class AVLTree extends bst_1.BST {
|
|
20
|
+
/**
|
|
21
|
+
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
22
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
23
|
+
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
24
|
+
* options.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super(options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The function creates a new AVL tree node with the specified key and value.
|
|
31
|
+
* @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
|
|
32
|
+
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
33
|
+
* @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
|
|
34
|
+
* type `N['val']`, which means it can be any value that is assignable to the `val` property of the
|
|
35
|
+
* node type `N`.
|
|
36
|
+
* @returns a new AVLTreeNode object with the specified key and value.
|
|
37
|
+
*/
|
|
38
|
+
createNode(key, val) {
|
|
39
|
+
return new AVLTreeNode(key, val);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
43
|
+
* a new node.
|
|
44
|
+
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
45
|
+
* `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
46
|
+
* @param [val] - The `val` parameter is the value that you want to assign to the new node that you
|
|
47
|
+
* are adding to the binary search tree.
|
|
48
|
+
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
add(keyOrNode, val) {
|
|
51
|
+
// TODO support node as a param
|
|
52
|
+
const inserted = super.add(keyOrNode, val);
|
|
53
|
+
if (inserted)
|
|
54
|
+
this._balancePath(inserted);
|
|
55
|
+
return inserted;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
59
|
+
* node if necessary.
|
|
60
|
+
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
|
|
61
|
+
* (`N`) or a key value (`BinaryTreeNodeKey`).
|
|
62
|
+
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
63
|
+
*/
|
|
64
|
+
delete(nodeOrKey) {
|
|
65
|
+
const deletedResults = super.delete(nodeOrKey);
|
|
66
|
+
for (const { needBalanced } of deletedResults) {
|
|
67
|
+
if (needBalanced) {
|
|
68
|
+
this._balancePath(needBalanced);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return deletedResults;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
75
|
+
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
76
|
+
* with the `destNode`.
|
|
77
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values
|
|
78
|
+
* from the source node (`srcNode`) will be swapped to.
|
|
79
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
80
|
+
*/
|
|
81
|
+
_swap(srcNode, destNode) {
|
|
82
|
+
const { key, val, height } = destNode;
|
|
83
|
+
const tempNode = this.createNode(key, val);
|
|
84
|
+
if (tempNode) {
|
|
85
|
+
tempNode.height = height;
|
|
86
|
+
destNode.key = srcNode.key;
|
|
87
|
+
destNode.val = srcNode.val;
|
|
88
|
+
destNode.height = srcNode.height;
|
|
89
|
+
srcNode.key = tempNode.key;
|
|
90
|
+
srcNode.val = tempNode.val;
|
|
91
|
+
srcNode.height = tempNode.height;
|
|
92
|
+
}
|
|
93
|
+
return destNode;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The function calculates the balance factor of a node in a binary tree.
|
|
97
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
98
|
+
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
99
|
+
* height of the left subtree from the height of the right subtree.
|
|
100
|
+
*/
|
|
101
|
+
_balanceFactor(node) {
|
|
102
|
+
if (!node.right)
|
|
103
|
+
// node has no right subtree
|
|
104
|
+
return -node.height;
|
|
105
|
+
else if (!node.left)
|
|
106
|
+
// node has no left subtree
|
|
107
|
+
return +node.height;
|
|
108
|
+
else
|
|
109
|
+
return node.right.height - node.left.height;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
113
|
+
* right children.
|
|
114
|
+
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
115
|
+
*/
|
|
116
|
+
_updateHeight(node) {
|
|
117
|
+
if (!node.left && !node.right)
|
|
118
|
+
node.height = 0;
|
|
119
|
+
else if (!node.left) {
|
|
120
|
+
const rightHeight = node.right ? node.right.height : 0;
|
|
121
|
+
node.height = 1 + rightHeight;
|
|
122
|
+
}
|
|
123
|
+
else if (!node.right)
|
|
124
|
+
node.height = 1 + node.left.height;
|
|
125
|
+
else
|
|
126
|
+
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
130
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
131
|
+
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
132
|
+
* AVL tree that needs to be balanced.
|
|
133
|
+
*/
|
|
134
|
+
_balancePath(node) {
|
|
135
|
+
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
136
|
+
for (let i = 0; i < path.length; i++) {
|
|
137
|
+
// second O(log n)
|
|
138
|
+
const A = path[i];
|
|
139
|
+
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
|
|
140
|
+
this._updateHeight(A); // first O(1)
|
|
141
|
+
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
|
|
142
|
+
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
143
|
+
switch (this._balanceFactor(A) // second O(1)
|
|
144
|
+
) {
|
|
145
|
+
case -2:
|
|
146
|
+
if (A && A.left) {
|
|
147
|
+
if (this._balanceFactor(A.left) <= 0) {
|
|
148
|
+
// second O(1)
|
|
149
|
+
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
|
|
150
|
+
this._balanceLL(A);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
|
|
154
|
+
this._balanceLR(A);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case +2:
|
|
159
|
+
if (A && A.right) {
|
|
160
|
+
if (this._balanceFactor(A.right) >= 0) {
|
|
161
|
+
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
|
|
162
|
+
this._balanceRR(A);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
|
|
166
|
+
this._balanceRL(A);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
175
|
+
* @param {N} A - A is a node in a binary tree.
|
|
176
|
+
*/
|
|
177
|
+
_balanceLL(A) {
|
|
178
|
+
const parentOfA = A.parent;
|
|
179
|
+
const B = A.left;
|
|
180
|
+
A.parent = B;
|
|
181
|
+
if (B && B.right) {
|
|
182
|
+
B.right.parent = A;
|
|
183
|
+
}
|
|
184
|
+
if (B)
|
|
185
|
+
B.parent = parentOfA;
|
|
186
|
+
if (A === this.root) {
|
|
187
|
+
if (B)
|
|
188
|
+
this._setRoot(B);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if ((parentOfA === null || parentOfA === void 0 ? void 0 : parentOfA.left) === A) {
|
|
192
|
+
parentOfA.left = B;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (parentOfA)
|
|
196
|
+
parentOfA.right = B;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (B) {
|
|
200
|
+
A.left = B.right;
|
|
201
|
+
B.right = A;
|
|
202
|
+
}
|
|
203
|
+
this._updateHeight(A);
|
|
204
|
+
if (B)
|
|
205
|
+
this._updateHeight(B);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
209
|
+
* @param {N} A - A is a node in a binary tree.
|
|
210
|
+
*/
|
|
211
|
+
_balanceLR(A) {
|
|
212
|
+
const parentOfA = A.parent;
|
|
213
|
+
const B = A.left;
|
|
214
|
+
let C = null;
|
|
215
|
+
if (B) {
|
|
216
|
+
C = B.right;
|
|
217
|
+
}
|
|
218
|
+
if (A)
|
|
219
|
+
A.parent = C;
|
|
220
|
+
if (B)
|
|
221
|
+
B.parent = C;
|
|
222
|
+
if (C) {
|
|
223
|
+
if (C.left) {
|
|
224
|
+
C.left.parent = B;
|
|
225
|
+
}
|
|
226
|
+
if (C.right) {
|
|
227
|
+
C.right.parent = A;
|
|
228
|
+
}
|
|
229
|
+
C.parent = parentOfA;
|
|
230
|
+
}
|
|
231
|
+
if (A === this.root) {
|
|
232
|
+
if (C)
|
|
233
|
+
this._setRoot(C);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
if (parentOfA) {
|
|
237
|
+
if (parentOfA.left === A) {
|
|
238
|
+
parentOfA.left = C;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
parentOfA.right = C;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (C) {
|
|
246
|
+
A.left = C.right;
|
|
247
|
+
if (B)
|
|
248
|
+
B.right = C.left;
|
|
249
|
+
C.left = B;
|
|
250
|
+
C.right = A;
|
|
251
|
+
}
|
|
252
|
+
this._updateHeight(A);
|
|
253
|
+
B && this._updateHeight(B);
|
|
254
|
+
C && this._updateHeight(C);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
258
|
+
* @param {N} A - A is a node in a binary tree.
|
|
259
|
+
*/
|
|
260
|
+
_balanceRR(A) {
|
|
261
|
+
const parentOfA = A.parent;
|
|
262
|
+
const B = A.right;
|
|
263
|
+
A.parent = B;
|
|
264
|
+
if (B) {
|
|
265
|
+
if (B.left) {
|
|
266
|
+
B.left.parent = A;
|
|
267
|
+
}
|
|
268
|
+
B.parent = parentOfA;
|
|
269
|
+
}
|
|
270
|
+
if (A === this.root) {
|
|
271
|
+
if (B)
|
|
272
|
+
this._setRoot(B);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (parentOfA) {
|
|
276
|
+
if (parentOfA.left === A) {
|
|
277
|
+
parentOfA.left = B;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
parentOfA.right = B;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (B) {
|
|
285
|
+
A.right = B.left;
|
|
286
|
+
B.left = A;
|
|
287
|
+
}
|
|
288
|
+
this._updateHeight(A);
|
|
289
|
+
B && this._updateHeight(B);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
293
|
+
* @param {N} A - A is a node in a binary tree.
|
|
294
|
+
*/
|
|
295
|
+
_balanceRL(A) {
|
|
296
|
+
const parentOfA = A.parent;
|
|
297
|
+
const B = A.right;
|
|
298
|
+
let C = null;
|
|
299
|
+
if (B) {
|
|
300
|
+
C = B.left;
|
|
301
|
+
}
|
|
302
|
+
A.parent = C;
|
|
303
|
+
if (B)
|
|
304
|
+
B.parent = C;
|
|
305
|
+
if (C) {
|
|
306
|
+
if (C.left) {
|
|
307
|
+
C.left.parent = A;
|
|
308
|
+
}
|
|
309
|
+
if (C.right) {
|
|
310
|
+
C.right.parent = B;
|
|
311
|
+
}
|
|
312
|
+
C.parent = parentOfA;
|
|
313
|
+
}
|
|
314
|
+
if (A === this.root) {
|
|
315
|
+
if (C)
|
|
316
|
+
this._setRoot(C);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (parentOfA) {
|
|
320
|
+
if (parentOfA.left === A) {
|
|
321
|
+
parentOfA.left = C;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
parentOfA.right = C;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (C)
|
|
329
|
+
A.right = C.left;
|
|
330
|
+
if (B && C)
|
|
331
|
+
B.left = C.right;
|
|
332
|
+
if (C)
|
|
333
|
+
C.left = A;
|
|
334
|
+
if (C)
|
|
335
|
+
C.right = B;
|
|
336
|
+
this._updateHeight(A);
|
|
337
|
+
B && this._updateHeight(B);
|
|
338
|
+
C && this._updateHeight(C);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
exports.AVLTree = AVLTree;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export declare class BinaryIndexedTree {
|
|
2
|
+
protected readonly _freq: number;
|
|
3
|
+
protected readonly _max: number;
|
|
4
|
+
/**
|
|
5
|
+
* The constructor initializes the properties of an object, including default frequency, maximum
|
|
6
|
+
* value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
|
|
7
|
+
* @param - - `frequency`: The default frequency value. It is optional and has a default
|
|
8
|
+
* value of 0.
|
|
9
|
+
*/
|
|
10
|
+
constructor({ frequency, max }: {
|
|
11
|
+
frequency?: number;
|
|
12
|
+
max: number;
|
|
13
|
+
});
|
|
14
|
+
protected _freqMap: Record<number, number>;
|
|
15
|
+
get freqMap(): Record<number, number>;
|
|
16
|
+
set freqMap(value: Record<number, number>);
|
|
17
|
+
protected _msb: number;
|
|
18
|
+
get msb(): number;
|
|
19
|
+
set msb(value: number);
|
|
20
|
+
protected _negativeCount: number;
|
|
21
|
+
get negativeCount(): number;
|
|
22
|
+
set negativeCount(value: number);
|
|
23
|
+
get freq(): number;
|
|
24
|
+
get max(): number;
|
|
25
|
+
/**
|
|
26
|
+
* The function "readSingle" reads a single number from a specified index.
|
|
27
|
+
* @param {number} index - The `index` parameter is a number that represents the index of an element in a
|
|
28
|
+
* collection or array.
|
|
29
|
+
* @returns a number.
|
|
30
|
+
*/
|
|
31
|
+
readSingle(index: number): number;
|
|
32
|
+
/**
|
|
33
|
+
* The "update" function updates the value at a given index by adding a delta and triggers a callback
|
|
34
|
+
* to notify of the change.
|
|
35
|
+
* @param {number} position - The `index` parameter represents the index of the element that needs to be
|
|
36
|
+
* updated in the data structure.
|
|
37
|
+
* @param {number} change - The "delta" parameter represents the change in value that needs to be
|
|
38
|
+
* applied to the frequency at the specified index.
|
|
39
|
+
*/
|
|
40
|
+
update(position: number, change: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* The function "writeSingle" checks the index and writes a single value with a given frequency.
|
|
43
|
+
* @param {number} index - The `index` parameter is a number that represents the index of an element. It
|
|
44
|
+
* is used to identify the specific element that needs to be written.
|
|
45
|
+
* @param {number} freq - The `freq` parameter represents the frequency value that needs to be
|
|
46
|
+
* written.
|
|
47
|
+
*/
|
|
48
|
+
writeSingle(index: number, freq: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* The read function takes a count parameter, checks if it is an integer, and returns the result of
|
|
51
|
+
* calling the _read function with the count parameter clamped between 0 and the maximum value.
|
|
52
|
+
* @param {number} count - The `count` parameter is a number that represents the number of items to
|
|
53
|
+
* read.
|
|
54
|
+
* @returns a number.
|
|
55
|
+
*/
|
|
56
|
+
read(count: number): number;
|
|
57
|
+
/**
|
|
58
|
+
* The function returns the lower bound of a non-descending sequence that sums up to a given number.
|
|
59
|
+
* @param {number} sum - The `sum` parameter is a number that represents the target sum that we want
|
|
60
|
+
* to find in the sequence.
|
|
61
|
+
* @returns The lowerBound function is returning a number.
|
|
62
|
+
*/
|
|
63
|
+
lowerBound(sum: number): number;
|
|
64
|
+
/**
|
|
65
|
+
* The upperBound function returns the index of the first element in a sequence that is greater than
|
|
66
|
+
* or equal to a given sum.
|
|
67
|
+
* @param {number} sum - The "sum" parameter is a number that represents the target sum that we want
|
|
68
|
+
* to find in the sequence.
|
|
69
|
+
* @returns The upperBound function is returning a number.
|
|
70
|
+
*/
|
|
71
|
+
upperBound(sum: number): number;
|
|
72
|
+
/**
|
|
73
|
+
* The function returns the value of a specific index in a freqMap data structure, or a default value if
|
|
74
|
+
* the index is not found.
|
|
75
|
+
* @param {number} index - The `index` parameter is a number that represents the index of a node in a
|
|
76
|
+
* freqMap data structure.
|
|
77
|
+
* @returns a number.
|
|
78
|
+
*/
|
|
79
|
+
protected _getFrequency(index: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array.
|
|
82
|
+
* @param {number} index - The index parameter is a number that represents the index of the freqMap
|
|
83
|
+
* element that needs to be updated.
|
|
84
|
+
* @param {number} delta - The `delta` parameter represents the change in value that needs to be
|
|
85
|
+
* added to the freqMap at the specified `index`.
|
|
86
|
+
*/
|
|
87
|
+
protected _updateFrequency(index: number, delta: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* The function checks if the given index is valid and within the range.
|
|
90
|
+
* @param {number} index - The parameter "index" is of type number and represents the index value
|
|
91
|
+
* that needs to be checked.
|
|
92
|
+
*/
|
|
93
|
+
protected _checkIndex(index: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* The function calculates the sum of elements in an array up to a given index using a binary indexed
|
|
96
|
+
* freqMap.
|
|
97
|
+
* @param {number} index - The `index` parameter is a number that represents the index of an element in a
|
|
98
|
+
* data structure.
|
|
99
|
+
* @returns a number.
|
|
100
|
+
*/
|
|
101
|
+
protected _readSingle(index: number): number;
|
|
102
|
+
/**
|
|
103
|
+
* The function `_updateNegativeCount` updates a counter based on changes in frequency values.
|
|
104
|
+
* @param {number} freqCur - The current frequency value.
|
|
105
|
+
* @param {number} freqNew - The freqNew parameter represents the new frequency value.
|
|
106
|
+
*/
|
|
107
|
+
protected _updateNegativeCount(freqCur: number, freqNew: number): void;
|
|
108
|
+
/**
|
|
109
|
+
* The `_update` function updates the values in a binary indexed freqMap starting from a given index and
|
|
110
|
+
* propagating the changes to its parent nodes.
|
|
111
|
+
* @param {number} index - The `index` parameter is a number that represents the index of the element in
|
|
112
|
+
* the data structure that needs to be updated.
|
|
113
|
+
* @param {number} delta - The `delta` parameter represents the change in value that needs to be
|
|
114
|
+
* applied to the elements in the data structure.
|
|
115
|
+
*/
|
|
116
|
+
protected _update(index: number, delta: number): void;
|
|
117
|
+
/**
|
|
118
|
+
* The `_writeSingle` function updates the frequency at a specific index and triggers a callback if
|
|
119
|
+
* the frequency has changed.
|
|
120
|
+
* @param {number} index - The `index` parameter is a number that represents the index of the element
|
|
121
|
+
* being modified or accessed.
|
|
122
|
+
* @param {number} freq - The `freq` parameter represents the new frequency value that needs to be
|
|
123
|
+
* written to the specified index `index`.
|
|
124
|
+
*/
|
|
125
|
+
protected _writeSingle(index: number, freq: number): void;
|
|
126
|
+
/**
|
|
127
|
+
* The `_read` function calculates the sum of values in a binary freqMap up to a given count.
|
|
128
|
+
* @param {number} count - The `count` parameter is a number that represents the number of elements
|
|
129
|
+
* to read from the freqMap.
|
|
130
|
+
* @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the
|
|
131
|
+
* range from `count` to 1.
|
|
132
|
+
*/
|
|
133
|
+
protected _read(count: number): number;
|
|
134
|
+
/**
|
|
135
|
+
* The function `_binarySearch` performs a binary search to find the largest number that satisfies a given
|
|
136
|
+
* condition.
|
|
137
|
+
* @param {number} sum - The sum parameter is a number that represents the target sum value.
|
|
138
|
+
* @param before - The `before` parameter is a function that takes two numbers `x` and `y` as
|
|
139
|
+
* arguments and returns a boolean value. It is used to determine if `x` is less than or equal to
|
|
140
|
+
* `y`. The purpose of this function is to compare two numbers and determine their order.
|
|
141
|
+
* @returns the value of the variable "left".
|
|
142
|
+
*/
|
|
143
|
+
protected _binarySearch(sum: number, before: (x: number, y: number) => boolean): number;
|
|
144
|
+
}
|