data-structure-typed 1.49.5 → 1.49.7
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/CHANGELOG.md +1 -1
- package/README.md +17 -23
- package/README_zh-CN.md +2 -0
- package/benchmark/report.html +14 -23
- package/benchmark/report.json +158 -251
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +194 -153
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/cjs/data-structures/binary-tree/bst.js +114 -91
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +24 -27
- package/dist/cjs/data-structures/hash/hash-map.js +35 -35
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/index.d.ts +0 -1
- package/dist/cjs/data-structures/hash/index.js +0 -1
- package/dist/cjs/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +2 -1
- package/dist/cjs/data-structures/heap/heap.js +13 -13
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +1 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +15 -18
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -7
- package/dist/cjs/data-structures/matrix/matrix.js +0 -7
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -11
- package/dist/cjs/data-structures/queue/deque.js +9 -13
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +29 -25
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.js +2 -3
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.js +9 -5
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +3 -3
- package/dist/cjs/types/common.js +2 -2
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -2
- package/dist/cjs/types/data-structures/hash/index.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/index.js +0 -1
- package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/types/data-structures/linked-list/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/linked-list/index.js +1 -0
- package/dist/cjs/types/data-structures/linked-list/index.js.map +1 -1
- package/dist/cjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
- package/dist/cjs/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/matrix/index.js +1 -0
- package/dist/cjs/types/data-structures/matrix/index.js.map +1 -1
- package/dist/cjs/types/data-structures/matrix/matrix.d.ts +7 -1
- package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -1
- package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +194 -153
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/mjs/data-structures/binary-tree/bst.js +114 -91
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/mjs/data-structures/hash/hash-map.d.ts +24 -27
- package/dist/mjs/data-structures/hash/hash-map.js +35 -37
- package/dist/mjs/data-structures/hash/index.d.ts +0 -1
- package/dist/mjs/data-structures/hash/index.js +0 -1
- package/dist/mjs/data-structures/heap/heap.d.ts +2 -1
- package/dist/mjs/data-structures/heap/heap.js +19 -20
- package/dist/mjs/data-structures/heap/max-heap.js +1 -1
- package/dist/mjs/data-structures/heap/min-heap.js +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +16 -23
- package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -7
- package/dist/mjs/data-structures/matrix/matrix.js +0 -7
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +1 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +1 -1
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +1 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -11
- package/dist/mjs/data-structures/queue/deque.js +9 -14
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +30 -28
- package/dist/mjs/data-structures/stack/stack.js +3 -5
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.js +10 -9
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +3 -3
- package/dist/mjs/types/common.js +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -2
- package/dist/mjs/types/data-structures/hash/index.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/index.js +0 -1
- package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/types/data-structures/linked-list/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/linked-list/index.js +1 -0
- package/dist/mjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
- package/dist/mjs/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/matrix/index.js +1 -0
- package/dist/mjs/types/data-structures/matrix/matrix.d.ts +7 -1
- package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -1
- package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -1
- package/dist/umd/data-structure-typed.js +620 -823
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +58 -53
- package/src/data-structures/binary-tree/binary-tree.ts +255 -211
- package/src/data-structures/binary-tree/bst.ts +126 -107
- package/src/data-structures/binary-tree/rb-tree.ts +66 -64
- package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
- package/src/data-structures/hash/hash-map.ts +46 -50
- package/src/data-structures/hash/index.ts +0 -1
- package/src/data-structures/heap/heap.ts +20 -19
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
- package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
- package/src/data-structures/matrix/matrix.ts +2 -10
- 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 +1 -1
- package/src/data-structures/queue/deque.ts +11 -15
- package/src/data-structures/queue/queue.ts +29 -28
- package/src/data-structures/stack/stack.ts +3 -6
- package/src/data-structures/trie/trie.ts +10 -11
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +6 -2
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/linked-list/index.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +7 -1
- package/src/types/data-structures/queue/deque.ts +1 -1
- package/src/types/data-structures/trie/trie.ts +1 -1
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
- package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -15
- package/test/performance/data-structures/comparison/comparison.test.ts +13 -36
- package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
- package/test/performance/data-structures/hash/hash-map.test.ts +11 -34
- package/test/performance/data-structures/heap/heap.test.ts +5 -18
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
- package/test/performance/data-structures/queue/queue.test.ts +8 -25
- package/test/performance/data-structures/stack/stack.test.ts +6 -18
- package/test/performance/data-structures/trie/trie.test.ts +2 -6
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -5
- package/test/unit/data-structures/binary-tree/bst.test.ts +17 -1
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +0 -108
- package/dist/cjs/data-structures/hash/hash-table.js +0 -282
- package/dist/cjs/data-structures/hash/hash-table.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/hash-table.js +0 -3
- package/dist/cjs/types/data-structures/hash/hash-table.js.map +0 -1
- package/dist/cjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
- package/dist/cjs/types/data-structures/matrix/matrix2d.js +0 -3
- package/dist/cjs/types/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/cjs/types/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/cjs/types/data-structures/matrix/vector2d.js +0 -3
- package/dist/cjs/types/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/mjs/data-structures/hash/hash-table.d.ts +0 -108
- package/dist/mjs/data-structures/hash/hash-table.js +0 -283
- package/dist/mjs/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/hash-table.js +0 -1
- package/dist/mjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
- package/dist/mjs/types/data-structures/matrix/matrix2d.js +0 -1
- package/dist/mjs/types/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/mjs/types/data-structures/matrix/vector2d.js +0 -1
- package/src/data-structures/hash/hash-table.ts +0 -318
- package/src/types/data-structures/hash/hash-table.ts +0 -1
- package/src/types/data-structures/matrix/matrix2d.ts +0 -1
- package/src/types/data-structures/matrix/vector2d.ts +0 -1
- package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
- package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
- package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +0 -238
|
@@ -1,10 +1,3 @@
|
|
|
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
1
|
export class SkipListNode {
|
|
9
2
|
key;
|
|
10
3
|
value;
|
|
@@ -16,32 +9,32 @@ export class SkipListNode {
|
|
|
16
9
|
}
|
|
17
10
|
}
|
|
18
11
|
export class SkipList {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
constructor(elements = [], options) {
|
|
13
|
+
if (options) {
|
|
14
|
+
const { maxLevel, probability } = options;
|
|
15
|
+
if (typeof maxLevel === 'number')
|
|
16
|
+
this._maxLevel = maxLevel;
|
|
17
|
+
if (typeof probability === 'number')
|
|
18
|
+
this._probability = probability;
|
|
19
|
+
}
|
|
20
|
+
if (elements) {
|
|
21
|
+
for (const [key, value] of elements)
|
|
22
|
+
this.add(key, value);
|
|
23
|
+
}
|
|
31
24
|
}
|
|
32
|
-
_head;
|
|
25
|
+
_head = new SkipListNode(undefined, undefined, this.maxLevel);
|
|
33
26
|
get head() {
|
|
34
27
|
return this._head;
|
|
35
28
|
}
|
|
36
|
-
_level;
|
|
29
|
+
_level = 0;
|
|
37
30
|
get level() {
|
|
38
31
|
return this._level;
|
|
39
32
|
}
|
|
40
|
-
_maxLevel;
|
|
33
|
+
_maxLevel = 16;
|
|
41
34
|
get maxLevel() {
|
|
42
35
|
return this._maxLevel;
|
|
43
36
|
}
|
|
44
|
-
_probability;
|
|
37
|
+
_probability = 0.5;
|
|
45
38
|
get probability() {
|
|
46
39
|
return this._probability;
|
|
47
40
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
+
import type { MatrixOptions } from '../../types';
|
|
8
9
|
export declare class Matrix {
|
|
9
10
|
/**
|
|
10
11
|
* The constructor function initializes a matrix object with the provided data and options, or with
|
|
@@ -13,13 +14,7 @@ export declare class Matrix {
|
|
|
13
14
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
14
15
|
* properties:
|
|
15
16
|
*/
|
|
16
|
-
constructor(data: number[][], options?:
|
|
17
|
-
rows?: number;
|
|
18
|
-
cols?: number;
|
|
19
|
-
addFn?: (a: number, b: number) => any;
|
|
20
|
-
subtractFn?: (a: number, b: number) => any;
|
|
21
|
-
multiplyFn?: (a: number, b: number) => any;
|
|
22
|
-
});
|
|
17
|
+
constructor(data: number[][], options?: MatrixOptions);
|
|
23
18
|
protected _rows: number;
|
|
24
19
|
get rows(): number;
|
|
25
20
|
protected _cols: number;
|
|
@@ -1,10 +1,3 @@
|
|
|
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
1
|
export class Matrix {
|
|
9
2
|
/**
|
|
10
3
|
* The constructor function initializes a matrix object with the provided data and options, or with
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PriorityQueue } from './priority-queue';
|
|
2
2
|
export class MaxPriorityQueue extends PriorityQueue {
|
|
3
|
-
constructor(elements, options = {
|
|
3
|
+
constructor(elements = [], options = {
|
|
4
4
|
comparator: (a, b) => {
|
|
5
5
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
6
6
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PriorityQueue } from './priority-queue';
|
|
2
2
|
export class MinPriorityQueue extends PriorityQueue {
|
|
3
|
-
constructor(elements, options = {
|
|
3
|
+
constructor(elements = [], options = {
|
|
4
4
|
comparator: (a, b) => {
|
|
5
5
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
6
6
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -8,7 +8,7 @@ import { Heap } from '../heap';
|
|
|
8
8
|
* 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
|
|
9
9
|
*/
|
|
10
10
|
export class PriorityQueue extends Heap {
|
|
11
|
-
constructor(elements, options) {
|
|
11
|
+
constructor(elements = [], options) {
|
|
12
12
|
super(elements, options);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElementCallback, IterableWithSizeOrLength } from '../../types';
|
|
8
|
+
import type { DequeOptions, ElementCallback, IterableWithSizeOrLength } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
/**
|
|
11
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).
|
|
@@ -21,16 +21,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
21
21
|
protected _lastInBucket: number;
|
|
22
22
|
protected _bucketCount: number;
|
|
23
23
|
protected readonly _bucketSize: number;
|
|
24
|
-
|
|
25
|
-
* The constructor initializes a data structure with a specified bucket size and populates it with
|
|
26
|
-
* elements from an iterable.
|
|
27
|
-
* @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
|
|
28
|
-
* contains the initial elements to be stored in the data structure. It can also be an object with a
|
|
29
|
-
* `length` property or a `size` property, which represents the number of elements in the iterable.
|
|
30
|
-
* @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
|
|
31
|
-
* stored in each bucket. It determines the size of each bucket in the data structure.
|
|
32
|
-
*/
|
|
33
|
-
constructor(elements?: IterableWithSizeOrLength<E>, bucketSize?: number);
|
|
24
|
+
constructor(elements?: IterableWithSizeOrLength<E>, options?: DequeOptions);
|
|
34
25
|
protected _buckets: E[][];
|
|
35
26
|
get buckets(): E[][];
|
|
36
27
|
protected _size: number;
|
|
@@ -13,18 +13,14 @@ export class Deque extends IterableElementBase {
|
|
|
13
13
|
_bucketLast = 0;
|
|
14
14
|
_lastInBucket = 0;
|
|
15
15
|
_bucketCount = 0;
|
|
16
|
-
_bucketSize;
|
|
17
|
-
|
|
18
|
-
* The constructor initializes a data structure with a specified bucket size and populates it with
|
|
19
|
-
* elements from an iterable.
|
|
20
|
-
* @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
|
|
21
|
-
* contains the initial elements to be stored in the data structure. It can also be an object with a
|
|
22
|
-
* `length` property or a `size` property, which represents the number of elements in the iterable.
|
|
23
|
-
* @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
|
|
24
|
-
* stored in each bucket. It determines the size of each bucket in the data structure.
|
|
25
|
-
*/
|
|
26
|
-
constructor(elements = [], bucketSize = 1 << 12) {
|
|
16
|
+
_bucketSize = 1 << 12;
|
|
17
|
+
constructor(elements = [], options) {
|
|
27
18
|
super();
|
|
19
|
+
if (options) {
|
|
20
|
+
const { bucketSize } = options;
|
|
21
|
+
if (typeof bucketSize === 'number')
|
|
22
|
+
this._bucketSize = bucketSize;
|
|
23
|
+
}
|
|
28
24
|
let _size;
|
|
29
25
|
if ('length' in elements) {
|
|
30
26
|
if (elements.length instanceof Function)
|
|
@@ -38,7 +34,6 @@ export class Deque extends IterableElementBase {
|
|
|
38
34
|
else
|
|
39
35
|
_size = elements.size;
|
|
40
36
|
}
|
|
41
|
-
this._bucketSize = bucketSize;
|
|
42
37
|
this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
|
|
43
38
|
for (let i = 0; i < this._bucketCount; ++i) {
|
|
44
39
|
this._buckets.push(new Array(this._bucketSize));
|
|
@@ -610,7 +605,7 @@ export class Deque extends IterableElementBase {
|
|
|
610
605
|
* satisfy the given predicate function.
|
|
611
606
|
*/
|
|
612
607
|
filter(predicate, thisArg) {
|
|
613
|
-
const newDeque = new Deque([], this._bucketSize);
|
|
608
|
+
const newDeque = new Deque([], { bucketSize: this._bucketSize });
|
|
614
609
|
let index = 0;
|
|
615
610
|
for (const el of this) {
|
|
616
611
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -638,7 +633,7 @@ export class Deque extends IterableElementBase {
|
|
|
638
633
|
* @returns a new Deque object with the mapped values.
|
|
639
634
|
*/
|
|
640
635
|
map(callback, thisArg) {
|
|
641
|
-
const newDeque = new Deque([], this._bucketSize);
|
|
636
|
+
const newDeque = new Deque([], { bucketSize: this._bucketSize });
|
|
642
637
|
let index = 0;
|
|
643
638
|
for (const el of this) {
|
|
644
639
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -12,19 +12,19 @@ import { SinglyLinkedList } from '../linked-list';
|
|
|
12
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
13
|
* 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
|
|
14
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
|
|
15
|
+
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
|
|
16
16
|
* 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
17
17
|
*/
|
|
18
18
|
export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
19
19
|
/**
|
|
20
20
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
21
21
|
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
22
|
-
* will be used to initialize the `
|
|
22
|
+
* will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
|
|
23
23
|
* initialized as an empty array.
|
|
24
24
|
*/
|
|
25
|
-
constructor(elements?: E
|
|
26
|
-
protected
|
|
27
|
-
get
|
|
25
|
+
constructor(elements?: Iterable<E>);
|
|
26
|
+
protected _elements: E[];
|
|
27
|
+
get elements(): E[];
|
|
28
28
|
protected _offset: number;
|
|
29
29
|
get offset(): number;
|
|
30
30
|
/**
|
|
@@ -36,8 +36,8 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
36
36
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
37
37
|
* Space Complexity: O(1) - no additional space is used.
|
|
38
38
|
*
|
|
39
|
-
* The `first` function returns the first element of the array `
|
|
40
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `
|
|
39
|
+
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
40
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
41
41
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
42
42
|
*/
|
|
43
43
|
get first(): E | undefined;
|
|
@@ -50,7 +50,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
50
50
|
* Space Complexity: O(1) - no additional space is used.
|
|
51
51
|
*
|
|
52
52
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
53
|
-
* @returns The method `get last()` returns the last element of the `
|
|
53
|
+
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
54
54
|
* array is empty, it returns `undefined`.
|
|
55
55
|
*/
|
|
56
56
|
get last(): E | undefined;
|
|
@@ -101,8 +101,8 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
101
101
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
102
102
|
* Space Complexity: O(1) - no additional space is used.
|
|
103
103
|
*
|
|
104
|
-
* The `peek` function returns the first element of the array `
|
|
105
|
-
* @returns The `peek()` method returns the first element of the data structure, represented by the `
|
|
104
|
+
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
105
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
106
106
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
107
107
|
*/
|
|
108
108
|
peek(): E | undefined;
|
|
@@ -115,7 +115,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
115
115
|
* Space Complexity: O(1) - no additional space is used.
|
|
116
116
|
*
|
|
117
117
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
118
|
-
* @returns The method `peekLast()` returns the last element of the `
|
|
118
|
+
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
119
119
|
* array is empty, it returns `undefined`.
|
|
120
120
|
*/
|
|
121
121
|
peekLast(): E | undefined;
|
|
@@ -174,12 +174,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
174
174
|
* Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
|
|
175
175
|
* Space Complexity: O(n) - where n is the number of elements in the queue.
|
|
176
176
|
*
|
|
177
|
-
* The toArray() function returns an array of elements from the current offset to the end of the
|
|
177
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
178
178
|
* @returns An array of type E is being returned.
|
|
179
179
|
*/
|
|
180
180
|
toArray(): E[];
|
|
181
181
|
/**
|
|
182
|
-
* The clear function resets the
|
|
182
|
+
* The clear function resets the elements array and offset to their initial values.
|
|
183
183
|
*/
|
|
184
184
|
clear(): void;
|
|
185
185
|
/**
|
|
@@ -6,26 +6,28 @@ import { SinglyLinkedList } from '../linked-list';
|
|
|
6
6
|
* 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.
|
|
7
7
|
* 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
|
|
8
8
|
* 5. Data Buffering: Acting as a buffer for data packets in network communication.
|
|
9
|
-
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store
|
|
9
|
+
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
|
|
10
10
|
* 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
11
11
|
*/
|
|
12
12
|
export class Queue extends IterableElementBase {
|
|
13
13
|
/**
|
|
14
14
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
15
15
|
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
16
|
-
* will be used to initialize the `
|
|
16
|
+
* will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
|
|
17
17
|
* initialized as an empty array.
|
|
18
18
|
*/
|
|
19
|
-
constructor(elements) {
|
|
19
|
+
constructor(elements = []) {
|
|
20
20
|
super();
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (elements) {
|
|
22
|
+
for (const el of elements)
|
|
23
|
+
this.push(el);
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
get
|
|
26
|
-
return this.
|
|
26
|
+
_elements = [];
|
|
27
|
+
get elements() {
|
|
28
|
+
return this._elements;
|
|
27
29
|
}
|
|
28
|
-
_offset;
|
|
30
|
+
_offset = 0;
|
|
29
31
|
get offset() {
|
|
30
32
|
return this._offset;
|
|
31
33
|
}
|
|
@@ -34,18 +36,18 @@ export class Queue extends IterableElementBase {
|
|
|
34
36
|
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
35
37
|
*/
|
|
36
38
|
get size() {
|
|
37
|
-
return this.
|
|
39
|
+
return this.elements.length - this.offset;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
41
43
|
* Space Complexity: O(1) - no additional space is used.
|
|
42
44
|
*
|
|
43
|
-
* The `first` function returns the first element of the array `
|
|
44
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `
|
|
45
|
+
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
46
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
45
47
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
46
48
|
*/
|
|
47
49
|
get first() {
|
|
48
|
-
return this.size > 0 ? this.
|
|
50
|
+
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
@@ -56,11 +58,11 @@ export class Queue extends IterableElementBase {
|
|
|
56
58
|
* Space Complexity: O(1) - no additional space is used.
|
|
57
59
|
*
|
|
58
60
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
59
|
-
* @returns The method `get last()` returns the last element of the `
|
|
61
|
+
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
60
62
|
* array is empty, it returns `undefined`.
|
|
61
63
|
*/
|
|
62
64
|
get last() {
|
|
63
|
-
return this.size > 0 ? this.
|
|
65
|
+
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
64
66
|
}
|
|
65
67
|
/**
|
|
66
68
|
* Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
|
|
@@ -90,7 +92,7 @@ export class Queue extends IterableElementBase {
|
|
|
90
92
|
* @returns The `add` method is returning a `Queue<E>` object.
|
|
91
93
|
*/
|
|
92
94
|
push(element) {
|
|
93
|
-
this.
|
|
95
|
+
this.elements.push(element);
|
|
94
96
|
return true;
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
@@ -110,11 +112,11 @@ export class Queue extends IterableElementBase {
|
|
|
110
112
|
return undefined;
|
|
111
113
|
const first = this.first;
|
|
112
114
|
this._offset += 1;
|
|
113
|
-
if (this.offset * 2 < this.
|
|
115
|
+
if (this.offset * 2 < this.elements.length)
|
|
114
116
|
return first;
|
|
115
117
|
// only delete dequeued elements when reaching half size
|
|
116
118
|
// to decrease latency of shifting elements.
|
|
117
|
-
this.
|
|
119
|
+
this._elements = this.elements.slice(this.offset);
|
|
118
120
|
this._offset = 0;
|
|
119
121
|
return first;
|
|
120
122
|
}
|
|
@@ -126,8 +128,8 @@ export class Queue extends IterableElementBase {
|
|
|
126
128
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
127
129
|
* Space Complexity: O(1) - no additional space is used.
|
|
128
130
|
*
|
|
129
|
-
* The `peek` function returns the first element of the array `
|
|
130
|
-
* @returns The `peek()` method returns the first element of the data structure, represented by the `
|
|
131
|
+
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
132
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
131
133
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
132
134
|
*/
|
|
133
135
|
peek() {
|
|
@@ -142,7 +144,7 @@ export class Queue extends IterableElementBase {
|
|
|
142
144
|
* Space Complexity: O(1) - no additional space is used.
|
|
143
145
|
*
|
|
144
146
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
145
|
-
* @returns The method `peekLast()` returns the last element of the `
|
|
147
|
+
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
146
148
|
* array is empty, it returns `undefined`.
|
|
147
149
|
*/
|
|
148
150
|
peekLast() {
|
|
@@ -187,7 +189,7 @@ export class Queue extends IterableElementBase {
|
|
|
187
189
|
* @param index
|
|
188
190
|
*/
|
|
189
191
|
getAt(index) {
|
|
190
|
-
return this.
|
|
192
|
+
return this.elements[index];
|
|
191
193
|
}
|
|
192
194
|
/**
|
|
193
195
|
* Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
|
|
@@ -211,17 +213,17 @@ export class Queue extends IterableElementBase {
|
|
|
211
213
|
* Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
|
|
212
214
|
* Space Complexity: O(n) - where n is the number of elements in the queue.
|
|
213
215
|
*
|
|
214
|
-
* The toArray() function returns an array of elements from the current offset to the end of the
|
|
216
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
215
217
|
* @returns An array of type E is being returned.
|
|
216
218
|
*/
|
|
217
219
|
toArray() {
|
|
218
|
-
return this.
|
|
220
|
+
return this.elements.slice(this.offset);
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
|
-
* The clear function resets the
|
|
223
|
+
* The clear function resets the elements array and offset to their initial values.
|
|
222
224
|
*/
|
|
223
225
|
clear() {
|
|
224
|
-
this.
|
|
226
|
+
this._elements = [];
|
|
225
227
|
this._offset = 0;
|
|
226
228
|
}
|
|
227
229
|
/**
|
|
@@ -236,7 +238,7 @@ export class Queue extends IterableElementBase {
|
|
|
236
238
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
237
239
|
*/
|
|
238
240
|
clone() {
|
|
239
|
-
return new Queue(this.
|
|
241
|
+
return new Queue(this.elements.slice(this.offset));
|
|
240
242
|
}
|
|
241
243
|
/**
|
|
242
244
|
* Time Complexity: O(n)
|
|
@@ -301,7 +303,7 @@ export class Queue extends IterableElementBase {
|
|
|
301
303
|
* Space Complexity: O(n)
|
|
302
304
|
*/
|
|
303
305
|
*_getIterator() {
|
|
304
|
-
for (const item of this.
|
|
306
|
+
for (const item of this.elements) {
|
|
305
307
|
yield item;
|
|
306
308
|
}
|
|
307
309
|
}
|
|
@@ -14,16 +14,14 @@ export class Stack extends IterableElementBase {
|
|
|
14
14
|
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
15
15
|
* is provided and is an array, it is assigned to the `_elements
|
|
16
16
|
*/
|
|
17
|
-
constructor(elements) {
|
|
17
|
+
constructor(elements = []) {
|
|
18
18
|
super();
|
|
19
|
-
this._elements = [];
|
|
20
19
|
if (elements) {
|
|
21
|
-
for (const el of elements)
|
|
20
|
+
for (const el of elements)
|
|
22
21
|
this.push(el);
|
|
23
|
-
}
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
|
-
_elements;
|
|
24
|
+
_elements = [];
|
|
27
25
|
get elements() {
|
|
28
26
|
return this._elements;
|
|
29
27
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElementCallback } from '../../types';
|
|
8
|
+
import type { ElementCallback, TrieOptions } from '../../types';
|
|
9
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,
|
|
@@ -31,7 +31,7 @@ export declare class TrieNode {
|
|
|
31
31
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
32
32
|
*/
|
|
33
33
|
export declare class Trie extends IterableElementBase<string> {
|
|
34
|
-
constructor(words?: string
|
|
34
|
+
constructor(words?: Iterable<string>, options?: TrieOptions);
|
|
35
35
|
protected _size: number;
|
|
36
36
|
get size(): number;
|
|
37
37
|
protected _caseSensitive: boolean;
|
|
@@ -27,26 +27,27 @@ export class TrieNode {
|
|
|
27
27
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
28
28
|
*/
|
|
29
29
|
export class Trie extends IterableElementBase {
|
|
30
|
-
constructor(words
|
|
30
|
+
constructor(words = [], options) {
|
|
31
31
|
super();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (options) {
|
|
33
|
+
const { caseSensitive } = options;
|
|
34
|
+
if (caseSensitive !== undefined)
|
|
35
|
+
this._caseSensitive = caseSensitive;
|
|
36
|
+
}
|
|
35
37
|
if (words) {
|
|
36
|
-
for (const word of words)
|
|
38
|
+
for (const word of words)
|
|
37
39
|
this.add(word);
|
|
38
|
-
}
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
_size;
|
|
42
|
+
_size = 0;
|
|
42
43
|
get size() {
|
|
43
44
|
return this._size;
|
|
44
45
|
}
|
|
45
|
-
_caseSensitive;
|
|
46
|
+
_caseSensitive = true;
|
|
46
47
|
get caseSensitive() {
|
|
47
48
|
return this._caseSensitive;
|
|
48
49
|
}
|
|
49
|
-
_root;
|
|
50
|
+
_root = new TrieNode('');
|
|
50
51
|
get root() {
|
|
51
52
|
return this._root;
|
|
52
53
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
2
|
+
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, KeyOrNodeOrEntry } 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:
|
|
7
|
-
addMany(nodes: Iterable<
|
|
6
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare enum BSTVariant {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
STANDARD = "STANDARD",
|
|
3
|
+
INVERSE = "INVERSE"
|
|
4
4
|
}
|
|
5
5
|
export declare enum CP {
|
|
6
6
|
lt = "lt",
|
|
@@ -44,7 +44,7 @@ export type BinaryTreePrintOptions = {
|
|
|
44
44
|
};
|
|
45
45
|
export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
46
46
|
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
47
|
-
export type
|
|
47
|
+
export type KeyOrNodeOrEntry<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
48
48
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
49
49
|
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
50
50
|
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
package/dist/mjs/types/common.js
CHANGED
|
@@ -3,6 +3,6 @@ import { IterationType } from "../../common";
|
|
|
3
3
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeOptions<K> = {
|
|
6
|
-
iterationType
|
|
7
|
-
extractor
|
|
6
|
+
iterationType?: IterationType;
|
|
7
|
+
extractor?: (key: K) => number;
|
|
8
8
|
};
|
|
@@ -4,5 +4,5 @@ import { BSTVariant } from "../../common";
|
|
|
4
4
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
6
|
export type BSTOptions<K> = BinaryTreeOptions<K> & {
|
|
7
|
-
variant
|
|
7
|
+
variant?: BSTVariant;
|
|
8
8
|
};
|
|
@@ -2,4 +2,4 @@ import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
|
2
2
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
3
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type TreeMultimapNested<K, V, N extends TreeMultimapNode<K, V, N>> = TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
-
export type TreeMultimapOptions<K> =
|
|
5
|
+
export type TreeMultimapOptions<K> = AVLTreeOptions<K> & {};
|
|
@@ -4,9 +4,12 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
4
4
|
next: HashMapLinkedNode<K, V>;
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
|
+
export type LinkedHashMapOptions<K> = {
|
|
8
|
+
hashFn?: (key: K) => string;
|
|
9
|
+
objHashFn?: (key: K) => object;
|
|
10
|
+
};
|
|
7
11
|
export type HashMapOptions<K> = {
|
|
8
|
-
hashFn
|
|
9
|
-
objHashFn: (key: K) => object;
|
|
12
|
+
hashFn?: (key: K) => string;
|
|
10
13
|
};
|
|
11
14
|
export type HashMapStoreItem<K, V> = {
|
|
12
15
|
key: K;
|