heap-typed 1.38.0 → 1.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/binary-tree/avl-tree.d.ts +9 -9
- package/dist/data-structures/binary-tree/avl-tree.js +22 -22
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -31
- package/dist/data-structures/binary-tree/binary-tree.js +32 -32
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -9
- package/dist/data-structures/binary-tree/tree-multiset.js +23 -23
- package/dist/data-structures/hash/hash-map.d.ts +25 -25
- package/dist/data-structures/hash/hash-map.js +59 -59
- package/dist/data-structures/hash/hash-table.d.ts +34 -34
- package/dist/data-structures/hash/hash-table.js +99 -99
- package/dist/data-structures/heap/heap.d.ts +66 -66
- package/dist/data-structures/heap/heap.js +167 -167
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +3 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +17 -17
- package/dist/data-structures/linked-list/skip-linked-list.js +34 -34
- package/dist/data-structures/matrix/matrix2d.d.ts +7 -7
- package/dist/data-structures/matrix/matrix2d.js +9 -9
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +6 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +1 -4
- package/src/data-structures/binary-tree/avl-tree.ts +27 -27
- package/src/data-structures/binary-tree/binary-tree.ts +55 -55
- package/src/data-structures/binary-tree/bst.ts +4 -0
- package/src/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multiset.ts +29 -29
- package/src/data-structures/hash/hash-map.ts +81 -75
- package/src/data-structures/hash/hash-table.ts +112 -109
- package/src/data-structures/heap/heap.ts +182 -181
- package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
- package/src/data-structures/linked-list/skip-linked-list.ts +45 -38
- package/src/data-structures/matrix/matrix2d.ts +10 -10
- package/src/data-structures/trie/trie.ts +9 -9
- package/src/index.ts +3 -3
- package/src/types/helpers.ts +5 -1
|
@@ -84,6 +84,10 @@ export class DoublyLinkedList<E = any> {
|
|
|
84
84
|
return this._length;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
get size(): number {
|
|
88
|
+
return this.length;
|
|
89
|
+
}
|
|
90
|
+
|
|
87
91
|
/**
|
|
88
92
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
89
93
|
* given array.
|
|
@@ -222,10 +226,6 @@ export class DoublyLinkedList<E = any> {
|
|
|
222
226
|
return this.tail?.val;
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
get size(): number {
|
|
226
|
-
return this.length;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
229
|
/**
|
|
230
230
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
231
231
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
@@ -19,20 +19,32 @@ export class SkipListNode<K, V> {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export class SkipList<K, V> {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The constructor initializes a SkipList with a specified maximum level and probability.
|
|
24
|
+
* @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
|
|
25
|
+
* the maximum number of levels that can be created in the skip list.
|
|
26
|
+
* @param [probability=0.5] - The probability parameter represents the probability of a node being promoted to a higher
|
|
27
|
+
* level in the skip list. It is used to determine the height of each node in the skip list.
|
|
28
|
+
*/
|
|
29
|
+
constructor(maxLevel = 16, probability = 0.5) {
|
|
30
|
+
this._head = new SkipListNode<K, V>(null as any, null as any, maxLevel);
|
|
31
|
+
this._level = 0;
|
|
32
|
+
this._maxLevel = maxLevel;
|
|
33
|
+
this._probability = probability;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return this._maxLevel;
|
|
36
|
+
private _head: SkipListNode<K, V>;
|
|
37
|
+
|
|
38
|
+
get head(): SkipListNode<K, V> {
|
|
39
|
+
return this._head;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
set
|
|
34
|
-
this.
|
|
42
|
+
set head(value: SkipListNode<K, V>) {
|
|
43
|
+
this._head = value;
|
|
35
44
|
}
|
|
45
|
+
|
|
46
|
+
private _level: number;
|
|
47
|
+
|
|
36
48
|
get level(): number {
|
|
37
49
|
return this._level;
|
|
38
50
|
}
|
|
@@ -40,42 +52,25 @@ export class SkipList<K, V> {
|
|
|
40
52
|
set level(value: number) {
|
|
41
53
|
this._level = value;
|
|
42
54
|
}
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
|
|
56
|
+
private _maxLevel: number;
|
|
57
|
+
|
|
58
|
+
get maxLevel(): number {
|
|
59
|
+
return this._maxLevel;
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
set
|
|
48
|
-
this.
|
|
62
|
+
set maxLevel(value: number) {
|
|
63
|
+
this._maxLevel = value;
|
|
49
64
|
}
|
|
50
|
-
|
|
51
|
-
private _level: number;
|
|
52
|
-
private _maxLevel: number;
|
|
65
|
+
|
|
53
66
|
private _probability: number;
|
|
54
67
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
|
|
58
|
-
* the maximum number of levels that can be created in the skip list.
|
|
59
|
-
* @param [probability=0.5] - The probability parameter represents the probability of a node being promoted to a higher
|
|
60
|
-
* level in the skip list. It is used to determine the height of each node in the skip list.
|
|
61
|
-
*/
|
|
62
|
-
constructor(maxLevel = 16, probability = 0.5) {
|
|
63
|
-
this._head = new SkipListNode<K, V>(null as any, null as any, maxLevel);
|
|
64
|
-
this._level = 0;
|
|
65
|
-
this._maxLevel = maxLevel;
|
|
66
|
-
this._probability = probability;
|
|
68
|
+
get probability(): number {
|
|
69
|
+
return this._probability;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* @returns the level, which is a number.
|
|
72
|
-
*/
|
|
73
|
-
private randomLevel(): number {
|
|
74
|
-
let level = 1;
|
|
75
|
-
while (Math.random() < this.probability && level < this.maxLevel) {
|
|
76
|
-
level++;
|
|
77
|
-
}
|
|
78
|
-
return level;
|
|
72
|
+
set probability(value: number) {
|
|
73
|
+
this._probability = value;
|
|
79
74
|
}
|
|
80
75
|
|
|
81
76
|
/**
|
|
@@ -163,4 +158,16 @@ export class SkipList<K, V> {
|
|
|
163
158
|
|
|
164
159
|
return false;
|
|
165
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The function "randomLevel" generates a random level based on a given probability and maximum level.
|
|
164
|
+
* @returns the level, which is a number.
|
|
165
|
+
*/
|
|
166
|
+
private randomLevel(): number {
|
|
167
|
+
let level = 1;
|
|
168
|
+
while (Math.random() < this.probability && level < this.maxLevel) {
|
|
169
|
+
level++;
|
|
170
|
+
}
|
|
171
|
+
return level;
|
|
172
|
+
}
|
|
166
173
|
}
|
|
@@ -58,16 +58,6 @@ export class Matrix2D {
|
|
|
58
58
|
return this._matrix;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
* The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
|
|
63
|
-
* _matrix array.
|
|
64
|
-
* @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
|
|
65
|
-
* the first column of the matrix.
|
|
66
|
-
*/
|
|
67
|
-
toVector(): Vector2D {
|
|
68
|
-
return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
61
|
/**
|
|
72
62
|
* The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
|
|
73
63
|
* @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
|
|
@@ -208,6 +198,16 @@ export class Matrix2D {
|
|
|
208
198
|
[0, 0, vector.w]
|
|
209
199
|
]);
|
|
210
200
|
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
|
|
204
|
+
* _matrix array.
|
|
205
|
+
* @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
|
|
206
|
+
* the first column of the matrix.
|
|
207
|
+
*/
|
|
208
|
+
toVector(): Vector2D {
|
|
209
|
+
return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
|
|
210
|
+
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
export default Matrix2D;
|
|
@@ -52,6 +52,8 @@ export class TrieNode {
|
|
|
52
52
|
* Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
|
|
53
53
|
*/
|
|
54
54
|
export class Trie {
|
|
55
|
+
private readonly _caseSensitive: boolean;
|
|
56
|
+
|
|
55
57
|
constructor(words?: string[], caseSensitive = true) {
|
|
56
58
|
this._root = new TrieNode('');
|
|
57
59
|
this._caseSensitive = caseSensitive;
|
|
@@ -72,8 +74,6 @@ export class Trie {
|
|
|
72
74
|
this._root = v;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
private readonly _caseSensitive: boolean;
|
|
76
|
-
|
|
77
77
|
/**
|
|
78
78
|
* Add a word to the Trie structure.
|
|
79
79
|
* @param {string} word - The word to add.
|
|
@@ -110,13 +110,6 @@ export class Trie {
|
|
|
110
110
|
return cur.isEnd;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
private _caseProcess(str: string) {
|
|
114
|
-
if (!this._caseSensitive) {
|
|
115
|
-
str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
|
|
116
|
-
}
|
|
117
|
-
return str;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
113
|
/**
|
|
121
114
|
* Remove a word from the Trie structure.
|
|
122
115
|
* @param{string} word - The word to delete.
|
|
@@ -282,5 +275,12 @@ export class Trie {
|
|
|
282
275
|
return words;
|
|
283
276
|
}
|
|
284
277
|
|
|
278
|
+
private _caseProcess(str: string) {
|
|
279
|
+
if (!this._caseSensitive) {
|
|
280
|
+
str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
|
|
281
|
+
}
|
|
282
|
+
return str;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
285
|
// --- end additional methods ---
|
|
286
286
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
// export { Heap, MaxHeap, MinHeap } from 'data-structure-typed';
|
|
9
|
-
export * from 'data-
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
9
|
+
export * from './data-structures/heap';
|
|
10
|
+
export * from './types/data-structures/heap';
|
|
11
|
+
export * from './types/helpers';
|
package/src/types/helpers.ts
CHANGED