data-structure-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/avl-tree.js.map +1 -1
- 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/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js.map +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/binary-tree/tree-multiset.js.map +1 -1
- 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-map.js.map +1 -1
- 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/hash/hash-table.js.map +1 -1
- package/dist/data-structures/heap/heap.d.ts +66 -66
- package/dist/data-structures/heap/heap.js +167 -167
- package/dist/data-structures/heap/heap.js.map +1 -1
- 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/doubly-linked-list.js.map +1 -1
- 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/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +7 -7
- package/dist/data-structures/matrix/matrix2d.js +9 -9
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +6 -6
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/helpers.js.map +1 -1
- package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -9
- package/lib/data-structures/binary-tree/avl-tree.js +22 -22
- package/lib/data-structures/binary-tree/binary-tree.d.ts +31 -31
- package/lib/data-structures/binary-tree/binary-tree.js +32 -32
- package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +9 -9
- package/lib/data-structures/binary-tree/tree-multiset.js +23 -23
- package/lib/data-structures/hash/hash-map.d.ts +25 -25
- package/lib/data-structures/hash/hash-map.js +59 -59
- package/lib/data-structures/hash/hash-table.d.ts +34 -34
- package/lib/data-structures/hash/hash-table.js +99 -99
- package/lib/data-structures/heap/heap.d.ts +66 -66
- package/lib/data-structures/heap/heap.js +167 -167
- package/lib/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/lib/data-structures/linked-list/doubly-linked-list.js +3 -3
- package/lib/data-structures/linked-list/skip-linked-list.d.ts +17 -17
- package/lib/data-structures/linked-list/skip-linked-list.js +34 -34
- package/lib/data-structures/matrix/matrix2d.d.ts +7 -7
- package/lib/data-structures/matrix/matrix2d.js +9 -9
- package/lib/data-structures/trie/trie.d.ts +2 -2
- package/lib/data-structures/trie/trie.js +6 -6
- package/package.json +5 -5
- 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/types/helpers.ts +5 -1
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +1 -1
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -13,113 +13,32 @@ export class HashTableNode {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class HashTable {
|
|
16
|
-
get hashFn() {
|
|
17
|
-
return this._hashFn;
|
|
18
|
-
}
|
|
19
|
-
set hashFn(value) {
|
|
20
|
-
this._hashFn = value;
|
|
21
|
-
}
|
|
22
|
-
get buckets() {
|
|
23
|
-
return this._buckets;
|
|
24
|
-
}
|
|
25
|
-
set buckets(value) {
|
|
26
|
-
this._buckets = value;
|
|
27
|
-
}
|
|
28
|
-
get capacity() {
|
|
29
|
-
return this._capacity;
|
|
30
|
-
}
|
|
31
|
-
set capacity(value) {
|
|
32
|
-
this._capacity = value;
|
|
33
|
-
}
|
|
34
16
|
constructor(capacity = HashTable.DEFAULT_CAPACITY, hashFn) {
|
|
35
17
|
this._hashFn = hashFn || this._defaultHashFn;
|
|
36
18
|
this._capacity = Math.max(capacity, HashTable.DEFAULT_CAPACITY);
|
|
37
19
|
this._size = 0;
|
|
38
20
|
this._buckets = new Array(this._capacity).fill(null);
|
|
39
21
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* capacity of the data structure.
|
|
43
|
-
* @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
|
|
44
|
-
* code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
|
|
45
|
-
* function is used to
|
|
46
|
-
* @returns the hash value of the key modulo the capacity of the data structure.
|
|
47
|
-
*/
|
|
48
|
-
_defaultHashFn(key) {
|
|
49
|
-
// Can be replaced with other hash functions as needed
|
|
50
|
-
const hashValue = typeof key === 'string' ? this._murmurStringHashFn(key) : this._objectHash(key);
|
|
51
|
-
return hashValue % this._capacity;
|
|
22
|
+
get capacity() {
|
|
23
|
+
return this._capacity;
|
|
52
24
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* string hash function.
|
|
56
|
-
* @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
|
|
57
|
-
* type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
|
|
58
|
-
* @returns a number, which is the result of the multiplicative string hash function applied to the input key.
|
|
59
|
-
*/
|
|
60
|
-
_multiplicativeStringHashFn(key) {
|
|
61
|
-
const keyString = String(key);
|
|
62
|
-
let hash = 0;
|
|
63
|
-
for (let i = 0; i < keyString.length; i++) {
|
|
64
|
-
const charCode = keyString.charCodeAt(i);
|
|
65
|
-
// Some constants for adjusting the hash function
|
|
66
|
-
const A = 0.618033988749895;
|
|
67
|
-
const M = 1 << 30; // 2^30
|
|
68
|
-
hash = (hash * A + charCode) % M;
|
|
69
|
-
}
|
|
70
|
-
return Math.abs(hash); // Take absolute value to ensure non-negative numbers
|
|
25
|
+
set capacity(value) {
|
|
26
|
+
this._capacity = value;
|
|
71
27
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
|
|
75
|
-
* type, but it will be converted to a string using the `String()` function before calculating the hash.
|
|
76
|
-
* @returns a number, which is the hash value calculated for the given key.
|
|
77
|
-
*/
|
|
78
|
-
_murmurStringHashFn(key) {
|
|
79
|
-
const keyString = String(key);
|
|
80
|
-
const seed = 0;
|
|
81
|
-
let hash = seed;
|
|
82
|
-
for (let i = 0; i < keyString.length; i++) {
|
|
83
|
-
const char = keyString.charCodeAt(i);
|
|
84
|
-
hash = (hash ^ char) * 0x5bd1e995;
|
|
85
|
-
hash = (hash ^ (hash >>> 15)) * 0x27d4eb2d;
|
|
86
|
-
hash = hash ^ (hash >>> 15);
|
|
87
|
-
}
|
|
88
|
-
return Math.abs(hash);
|
|
28
|
+
get size() {
|
|
29
|
+
return this._size;
|
|
89
30
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
|
|
93
|
-
* @returns The hash function is returning a number.
|
|
94
|
-
*/
|
|
95
|
-
_hash(key) {
|
|
96
|
-
return this.hashFn(key);
|
|
31
|
+
get buckets() {
|
|
32
|
+
return this._buckets;
|
|
97
33
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
|
|
101
|
-
* which we want to calculate the hash value.
|
|
102
|
-
* @returns a number, which is the hash value of the input string.
|
|
103
|
-
*/
|
|
104
|
-
_stringHash(key) {
|
|
105
|
-
let hash = 0;
|
|
106
|
-
for (let i = 0; i < key.length; i++) {
|
|
107
|
-
hash = (hash * 31 + key.charCodeAt(i)) & 0xffffffff;
|
|
108
|
-
}
|
|
109
|
-
return hash;
|
|
34
|
+
set buckets(value) {
|
|
35
|
+
this._buckets = value;
|
|
110
36
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* @returns a number, which is the hash value of the key.
|
|
117
|
-
*/
|
|
118
|
-
_objectHash(key) {
|
|
119
|
-
// If the key is an object, you can write a custom hash function
|
|
120
|
-
// For example, convert the object's properties to a string and use string hashing
|
|
121
|
-
// This is just an example; you should write a specific object hash function as needed
|
|
122
|
-
return this._stringHash(JSON.stringify(key));
|
|
37
|
+
get hashFn() {
|
|
38
|
+
return this._hashFn;
|
|
39
|
+
}
|
|
40
|
+
set hashFn(value) {
|
|
41
|
+
this._hashFn = value;
|
|
123
42
|
}
|
|
124
43
|
/**
|
|
125
44
|
* The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
|
|
@@ -204,6 +123,90 @@ export class HashTable {
|
|
|
204
123
|
currentNode = currentNode.next;
|
|
205
124
|
}
|
|
206
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
|
|
128
|
+
* capacity of the data structure.
|
|
129
|
+
* @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
|
|
130
|
+
* code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
|
|
131
|
+
* function is used to
|
|
132
|
+
* @returns the hash value of the key modulo the capacity of the data structure.
|
|
133
|
+
*/
|
|
134
|
+
_defaultHashFn(key) {
|
|
135
|
+
// Can be replaced with other hash functions as needed
|
|
136
|
+
const hashValue = typeof key === 'string' ? this._murmurStringHashFn(key) : this._objectHash(key);
|
|
137
|
+
return hashValue % this._capacity;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
|
|
141
|
+
* string hash function.
|
|
142
|
+
* @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
|
|
143
|
+
* type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
|
|
144
|
+
* @returns a number, which is the result of the multiplicative string hash function applied to the input key.
|
|
145
|
+
*/
|
|
146
|
+
_multiplicativeStringHashFn(key) {
|
|
147
|
+
const keyString = String(key);
|
|
148
|
+
let hash = 0;
|
|
149
|
+
for (let i = 0; i < keyString.length; i++) {
|
|
150
|
+
const charCode = keyString.charCodeAt(i);
|
|
151
|
+
// Some constants for adjusting the hash function
|
|
152
|
+
const A = 0.618033988749895;
|
|
153
|
+
const M = 1 << 30; // 2^30
|
|
154
|
+
hash = (hash * A + charCode) % M;
|
|
155
|
+
}
|
|
156
|
+
return Math.abs(hash); // Take absolute value to ensure non-negative numbers
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
|
|
160
|
+
* @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
|
|
161
|
+
* type, but it will be converted to a string using the `String()` function before calculating the hash.
|
|
162
|
+
* @returns a number, which is the hash value calculated for the given key.
|
|
163
|
+
*/
|
|
164
|
+
_murmurStringHashFn(key) {
|
|
165
|
+
const keyString = String(key);
|
|
166
|
+
const seed = 0;
|
|
167
|
+
let hash = seed;
|
|
168
|
+
for (let i = 0; i < keyString.length; i++) {
|
|
169
|
+
const char = keyString.charCodeAt(i);
|
|
170
|
+
hash = (hash ^ char) * 0x5bd1e995;
|
|
171
|
+
hash = (hash ^ (hash >>> 15)) * 0x27d4eb2d;
|
|
172
|
+
hash = hash ^ (hash >>> 15);
|
|
173
|
+
}
|
|
174
|
+
return Math.abs(hash);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The _hash function takes a key and returns a number.
|
|
178
|
+
* @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
|
|
179
|
+
* @returns The hash function is returning a number.
|
|
180
|
+
*/
|
|
181
|
+
_hash(key) {
|
|
182
|
+
return this.hashFn(key);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The function calculates a hash value for a given string using the djb2 algorithm.
|
|
186
|
+
* @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
|
|
187
|
+
* which we want to calculate the hash value.
|
|
188
|
+
* @returns a number, which is the hash value of the input string.
|
|
189
|
+
*/
|
|
190
|
+
_stringHash(key) {
|
|
191
|
+
let hash = 0;
|
|
192
|
+
for (let i = 0; i < key.length; i++) {
|
|
193
|
+
hash = (hash * 31 + key.charCodeAt(i)) & 0xffffffff;
|
|
194
|
+
}
|
|
195
|
+
return hash;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
|
|
199
|
+
* @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
|
|
200
|
+
* boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
|
|
201
|
+
* the key, which can be used for
|
|
202
|
+
* @returns a number, which is the hash value of the key.
|
|
203
|
+
*/
|
|
204
|
+
_objectHash(key) {
|
|
205
|
+
// If the key is an object, you can write a custom hash function
|
|
206
|
+
// For example, convert the object's properties to a string and use string hashing
|
|
207
|
+
// This is just an example; you should write a specific object hash function as needed
|
|
208
|
+
return this._stringHash(JSON.stringify(key));
|
|
209
|
+
}
|
|
207
210
|
/**
|
|
208
211
|
* The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
|
|
209
212
|
* capacity and rehashing all the existing key-value pairs into the new buckets.
|
|
@@ -232,9 +235,6 @@ export class HashTable {
|
|
|
232
235
|
this._buckets = newBuckets;
|
|
233
236
|
this._capacity = newCapacity;
|
|
234
237
|
}
|
|
235
|
-
get size() {
|
|
236
|
-
return this._size;
|
|
237
|
-
}
|
|
238
238
|
}
|
|
239
239
|
HashTable.DEFAULT_CAPACITY = 16;
|
|
240
240
|
HashTable.LOAD_FACTOR = 0.75;
|
|
@@ -9,6 +9,22 @@ export declare class Heap<E> {
|
|
|
9
9
|
protected nodes: E[];
|
|
10
10
|
protected readonly comparator: Comparator<E>;
|
|
11
11
|
constructor(comparator: Comparator<E>);
|
|
12
|
+
/**
|
|
13
|
+
* Get the size (number of elements) of the heap.
|
|
14
|
+
*/
|
|
15
|
+
get size(): number;
|
|
16
|
+
/**
|
|
17
|
+
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
18
|
+
* @returns The last element or undefined if the heap is empty.
|
|
19
|
+
*/
|
|
20
|
+
get leaf(): E | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Static method that creates a binary heap from an array of nodes and a comparison function.
|
|
23
|
+
* @param nodes
|
|
24
|
+
* @param comparator - Comparison function.
|
|
25
|
+
* @returns A new Heap instance.
|
|
26
|
+
*/
|
|
27
|
+
static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
|
|
12
28
|
/**
|
|
13
29
|
* Insert an element into the heap and maintain the heap properties.
|
|
14
30
|
* @param element - The element to be inserted.
|
|
@@ -29,34 +45,11 @@ export declare class Heap<E> {
|
|
|
29
45
|
* @returns The top element or undefined if the heap is empty.
|
|
30
46
|
*/
|
|
31
47
|
pop(): E | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Float operation to maintain heap properties after adding an element.
|
|
34
|
-
* @param index - The index of the newly added element.
|
|
35
|
-
*/
|
|
36
|
-
protected bubbleUp(index: number): void;
|
|
37
|
-
/**
|
|
38
|
-
* Sinking operation to maintain heap properties after removing the top element.
|
|
39
|
-
* @param index - The index from which to start sinking.
|
|
40
|
-
*/
|
|
41
|
-
protected sinkDown(index: number): void;
|
|
42
|
-
/**
|
|
43
|
-
* Fix the entire heap to maintain heap properties.
|
|
44
|
-
*/
|
|
45
|
-
protected fix(): void;
|
|
46
48
|
/**
|
|
47
49
|
* Peek at the top element of the heap without removing it.
|
|
48
50
|
* @returns The top element or undefined if the heap is empty.
|
|
49
51
|
*/
|
|
50
52
|
peek(): E | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Get the size (number of elements) of the heap.
|
|
53
|
-
*/
|
|
54
|
-
get size(): number;
|
|
55
|
-
/**
|
|
56
|
-
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
57
|
-
* @returns The last element or undefined if the heap is empty.
|
|
58
|
-
*/
|
|
59
|
-
get leaf(): E | undefined;
|
|
60
53
|
/**
|
|
61
54
|
* Check if the heap is empty.
|
|
62
55
|
* @returns True if the heap is empty, otherwise false.
|
|
@@ -100,12 +93,19 @@ export declare class Heap<E> {
|
|
|
100
93
|
*/
|
|
101
94
|
sort(): E[];
|
|
102
95
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param comparator - Comparison function.
|
|
106
|
-
* @returns A new Heap instance.
|
|
96
|
+
* Float operation to maintain heap properties after adding an element.
|
|
97
|
+
* @param index - The index of the newly added element.
|
|
107
98
|
*/
|
|
108
|
-
|
|
99
|
+
protected bubbleUp(index: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Sinking operation to maintain heap properties after removing the top element.
|
|
102
|
+
* @param index - The index from which to start sinking.
|
|
103
|
+
*/
|
|
104
|
+
protected sinkDown(index: number): void;
|
|
105
|
+
/**
|
|
106
|
+
* Fix the entire heap to maintain heap properties.
|
|
107
|
+
*/
|
|
108
|
+
protected fix(): void;
|
|
109
109
|
}
|
|
110
110
|
export declare class FibonacciHeapNode<E> {
|
|
111
111
|
element: E;
|
|
@@ -119,33 +119,15 @@ export declare class FibonacciHeapNode<E> {
|
|
|
119
119
|
}
|
|
120
120
|
export declare class FibonacciHeap<E> {
|
|
121
121
|
root?: FibonacciHeapNode<E>;
|
|
122
|
-
protected min?: FibonacciHeapNode<E>;
|
|
123
122
|
size: number;
|
|
123
|
+
protected min?: FibonacciHeapNode<E>;
|
|
124
124
|
protected readonly comparator: Comparator<E>;
|
|
125
125
|
constructor(comparator?: Comparator<E>);
|
|
126
|
-
/**
|
|
127
|
-
* Default comparator function used by the heap.
|
|
128
|
-
* @param {E} a
|
|
129
|
-
* @param {E} b
|
|
130
|
-
* @protected
|
|
131
|
-
*/
|
|
132
|
-
protected defaultComparator(a: E, b: E): number;
|
|
133
126
|
/**
|
|
134
127
|
* Get the size (number of elements) of the heap.
|
|
135
128
|
* @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
|
|
136
129
|
*/
|
|
137
130
|
clear(): void;
|
|
138
|
-
/**
|
|
139
|
-
* Create a new node.
|
|
140
|
-
* @param element
|
|
141
|
-
* @protected
|
|
142
|
-
*/
|
|
143
|
-
protected createNode(element: E): FibonacciHeapNode<E>;
|
|
144
|
-
/**
|
|
145
|
-
* Merge the given node with the root list.
|
|
146
|
-
* @param node - The node to be merged.
|
|
147
|
-
*/
|
|
148
|
-
protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
|
|
149
131
|
/**
|
|
150
132
|
* O(1) time operation.
|
|
151
133
|
* Insert an element into the heap and maintain the heap properties.
|
|
@@ -175,13 +157,6 @@ export declare class FibonacciHeap<E> {
|
|
|
175
157
|
* @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
|
|
176
158
|
*/
|
|
177
159
|
consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[];
|
|
178
|
-
/**
|
|
179
|
-
* O(log n) time operation.
|
|
180
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
181
|
-
* @param node - The node to be removed.
|
|
182
|
-
* @protected
|
|
183
|
-
*/
|
|
184
|
-
protected removeFromRoot(node: FibonacciHeapNode<E>): void;
|
|
185
160
|
/**
|
|
186
161
|
* O(log n) time operation.
|
|
187
162
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -192,33 +167,58 @@ export declare class FibonacciHeap<E> {
|
|
|
192
167
|
/**
|
|
193
168
|
* O(log n) time operation.
|
|
194
169
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
195
|
-
* @
|
|
196
|
-
* @param x
|
|
197
|
-
* @protected
|
|
170
|
+
* @returns The top element or undefined if the heap is empty.
|
|
198
171
|
*/
|
|
199
|
-
|
|
172
|
+
poll(): E | undefined;
|
|
200
173
|
/**
|
|
201
174
|
* O(log n) time operation.
|
|
202
175
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
176
|
+
* @returns The top element or undefined if the heap is empty.
|
|
177
|
+
*/
|
|
178
|
+
pop(): E | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* O(log n) time operation.
|
|
181
|
+
* merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
|
|
182
|
+
* @param heapToMerge
|
|
183
|
+
*/
|
|
184
|
+
merge(heapToMerge: FibonacciHeap<E>): void;
|
|
185
|
+
/**
|
|
186
|
+
* Default comparator function used by the heap.
|
|
187
|
+
* @param {E} a
|
|
188
|
+
* @param {E} b
|
|
203
189
|
* @protected
|
|
204
190
|
*/
|
|
205
|
-
protected
|
|
191
|
+
protected defaultComparator(a: E, b: E): number;
|
|
192
|
+
/**
|
|
193
|
+
* Create a new node.
|
|
194
|
+
* @param element
|
|
195
|
+
* @protected
|
|
196
|
+
*/
|
|
197
|
+
protected createNode(element: E): FibonacciHeapNode<E>;
|
|
198
|
+
/**
|
|
199
|
+
* Merge the given node with the root list.
|
|
200
|
+
* @param node - The node to be merged.
|
|
201
|
+
*/
|
|
202
|
+
protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
|
|
206
203
|
/**
|
|
207
204
|
* O(log n) time operation.
|
|
208
205
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
209
|
-
* @
|
|
206
|
+
* @param node - The node to be removed.
|
|
207
|
+
* @protected
|
|
210
208
|
*/
|
|
211
|
-
|
|
209
|
+
protected removeFromRoot(node: FibonacciHeapNode<E>): void;
|
|
212
210
|
/**
|
|
213
211
|
* O(log n) time operation.
|
|
214
212
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
215
|
-
* @
|
|
213
|
+
* @param y
|
|
214
|
+
* @param x
|
|
215
|
+
* @protected
|
|
216
216
|
*/
|
|
217
|
-
|
|
217
|
+
protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
|
|
218
218
|
/**
|
|
219
219
|
* O(log n) time operation.
|
|
220
|
-
*
|
|
221
|
-
* @
|
|
220
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
221
|
+
* @protected
|
|
222
222
|
*/
|
|
223
|
-
|
|
223
|
+
protected consolidate(): void;
|
|
224
224
|
}
|