data-structure-typed 1.37.9 → 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 +67 -68
- 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/data-structures/binary-tree/bst.d.ts +0 -5
- package/dist/types/data-structures/binary-tree/bst.js +0 -7
- package/dist/types/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/types/helpers.d.ts +5 -0
- package/dist/types/helpers.js +7 -0
- 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 +67 -68
- 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/lib/types/data-structures/binary-tree/bst.d.ts +0 -5
- package/lib/types/data-structures/binary-tree/bst.js +1 -6
- package/lib/types/helpers.d.ts +5 -0
- package/lib/types/helpers.js +6 -1
- package/package.json +7 -6
- 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 +183 -183
- 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;
|
|
@@ -4,12 +4,27 @@
|
|
|
4
4
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
5
5
|
* @license MIT License
|
|
6
6
|
*/
|
|
7
|
-
import type { Comparator } from '../../types';
|
|
8
|
-
import { DFSOrderPattern } from '../../types';
|
|
7
|
+
import type { Comparator, DFSOrderPattern } from '../../types';
|
|
9
8
|
export declare class Heap<E> {
|
|
10
9
|
protected nodes: E[];
|
|
11
10
|
protected readonly comparator: Comparator<E>;
|
|
12
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>;
|
|
13
28
|
/**
|
|
14
29
|
* Insert an element into the heap and maintain the heap properties.
|
|
15
30
|
* @param element - The element to be inserted.
|
|
@@ -30,34 +45,11 @@ export declare class Heap<E> {
|
|
|
30
45
|
* @returns The top element or undefined if the heap is empty.
|
|
31
46
|
*/
|
|
32
47
|
pop(): E | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Float operation to maintain heap properties after adding an element.
|
|
35
|
-
* @param index - The index of the newly added element.
|
|
36
|
-
*/
|
|
37
|
-
protected bubbleUp(index: number): void;
|
|
38
|
-
/**
|
|
39
|
-
* Sinking operation to maintain heap properties after removing the top element.
|
|
40
|
-
* @param index - The index from which to start sinking.
|
|
41
|
-
*/
|
|
42
|
-
protected sinkDown(index: number): void;
|
|
43
|
-
/**
|
|
44
|
-
* Fix the entire heap to maintain heap properties.
|
|
45
|
-
*/
|
|
46
|
-
protected fix(): void;
|
|
47
48
|
/**
|
|
48
49
|
* Peek at the top element of the heap without removing it.
|
|
49
50
|
* @returns The top element or undefined if the heap is empty.
|
|
50
51
|
*/
|
|
51
52
|
peek(): E | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Get the size (number of elements) of the heap.
|
|
54
|
-
*/
|
|
55
|
-
get size(): number;
|
|
56
|
-
/**
|
|
57
|
-
* Get the last element in the heap, which is not necessarily a leaf node.
|
|
58
|
-
* @returns The last element or undefined if the heap is empty.
|
|
59
|
-
*/
|
|
60
|
-
get leaf(): E | undefined;
|
|
61
53
|
/**
|
|
62
54
|
* Check if the heap is empty.
|
|
63
55
|
* @returns True if the heap is empty, otherwise false.
|
|
@@ -101,12 +93,19 @@ export declare class Heap<E> {
|
|
|
101
93
|
*/
|
|
102
94
|
sort(): E[];
|
|
103
95
|
/**
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param comparator - Comparison function.
|
|
107
|
-
* @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.
|
|
108
98
|
*/
|
|
109
|
-
|
|
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;
|
|
110
109
|
}
|
|
111
110
|
export declare class FibonacciHeapNode<E> {
|
|
112
111
|
element: E;
|
|
@@ -120,33 +119,15 @@ export declare class FibonacciHeapNode<E> {
|
|
|
120
119
|
}
|
|
121
120
|
export declare class FibonacciHeap<E> {
|
|
122
121
|
root?: FibonacciHeapNode<E>;
|
|
123
|
-
protected min?: FibonacciHeapNode<E>;
|
|
124
122
|
size: number;
|
|
123
|
+
protected min?: FibonacciHeapNode<E>;
|
|
125
124
|
protected readonly comparator: Comparator<E>;
|
|
126
125
|
constructor(comparator?: Comparator<E>);
|
|
127
|
-
/**
|
|
128
|
-
* Default comparator function used by the heap.
|
|
129
|
-
* @param {E} a
|
|
130
|
-
* @param {E} b
|
|
131
|
-
* @protected
|
|
132
|
-
*/
|
|
133
|
-
protected defaultComparator(a: E, b: E): number;
|
|
134
126
|
/**
|
|
135
127
|
* Get the size (number of elements) of the heap.
|
|
136
128
|
* @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
|
|
137
129
|
*/
|
|
138
130
|
clear(): void;
|
|
139
|
-
/**
|
|
140
|
-
* Create a new node.
|
|
141
|
-
* @param element
|
|
142
|
-
* @protected
|
|
143
|
-
*/
|
|
144
|
-
protected createNode(element: E): FibonacciHeapNode<E>;
|
|
145
|
-
/**
|
|
146
|
-
* Merge the given node with the root list.
|
|
147
|
-
* @param node - The node to be merged.
|
|
148
|
-
*/
|
|
149
|
-
protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
|
|
150
131
|
/**
|
|
151
132
|
* O(1) time operation.
|
|
152
133
|
* Insert an element into the heap and maintain the heap properties.
|
|
@@ -176,13 +157,6 @@ export declare class FibonacciHeap<E> {
|
|
|
176
157
|
* @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
|
|
177
158
|
*/
|
|
178
159
|
consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[];
|
|
179
|
-
/**
|
|
180
|
-
* O(log n) time operation.
|
|
181
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
182
|
-
* @param node - The node to be removed.
|
|
183
|
-
* @protected
|
|
184
|
-
*/
|
|
185
|
-
protected removeFromRoot(node: FibonacciHeapNode<E>): void;
|
|
186
160
|
/**
|
|
187
161
|
* O(log n) time operation.
|
|
188
162
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -193,33 +167,58 @@ export declare class FibonacciHeap<E> {
|
|
|
193
167
|
/**
|
|
194
168
|
* O(log n) time operation.
|
|
195
169
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
196
|
-
* @
|
|
197
|
-
* @param x
|
|
198
|
-
* @protected
|
|
170
|
+
* @returns The top element or undefined if the heap is empty.
|
|
199
171
|
*/
|
|
200
|
-
|
|
172
|
+
poll(): E | undefined;
|
|
201
173
|
/**
|
|
202
174
|
* O(log n) time operation.
|
|
203
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
|
|
204
189
|
* @protected
|
|
205
190
|
*/
|
|
206
|
-
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;
|
|
207
203
|
/**
|
|
208
204
|
* O(log n) time operation.
|
|
209
205
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
210
|
-
* @
|
|
206
|
+
* @param node - The node to be removed.
|
|
207
|
+
* @protected
|
|
211
208
|
*/
|
|
212
|
-
|
|
209
|
+
protected removeFromRoot(node: FibonacciHeapNode<E>): void;
|
|
213
210
|
/**
|
|
214
211
|
* O(log n) time operation.
|
|
215
212
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
216
|
-
* @
|
|
213
|
+
* @param y
|
|
214
|
+
* @param x
|
|
215
|
+
* @protected
|
|
217
216
|
*/
|
|
218
|
-
|
|
217
|
+
protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
|
|
219
218
|
/**
|
|
220
219
|
* O(log n) time operation.
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
220
|
+
* Remove and return the top element (smallest or largest element) from the heap.
|
|
221
|
+
* @protected
|
|
223
222
|
*/
|
|
224
|
-
|
|
223
|
+
protected consolidate(): void;
|
|
225
224
|
}
|