min-heap-typed 1.49.6 → 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/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/avl-tree.js +5 -5
- package/dist/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/binary-tree.js +7 -9
- package/dist/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/data-structures/binary-tree/bst.js +6 -7
- package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/data-structures/hash/hash-map.d.ts +24 -27
- package/dist/data-structures/hash/hash-map.js +35 -35
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -1
- package/dist/data-structures/heap/heap.d.ts +2 -1
- package/dist/data-structures/heap/heap.js +13 -13
- package/dist/data-structures/heap/max-heap.js +1 -1
- package/dist/data-structures/heap/min-heap.js +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
- package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
- package/dist/data-structures/matrix/matrix.d.ts +2 -7
- package/dist/data-structures/matrix/matrix.js +0 -7
- package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +1 -1
- package/dist/data-structures/queue/deque.d.ts +2 -11
- package/dist/data-structures/queue/deque.js +9 -13
- package/dist/data-structures/queue/queue.d.ts +13 -13
- package/dist/data-structures/queue/queue.js +29 -25
- package/dist/data-structures/stack/stack.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +9 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/index.js +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/types/data-structures/linked-list/index.d.ts +1 -0
- package/dist/types/data-structures/linked-list/index.js +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +1 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +6 -10
- package/src/data-structures/binary-tree/bst.ts +5 -7
- package/src/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-multimap.ts +2 -2
- 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/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/dist/data-structures/hash/hash-table.d.ts +0 -108
- package/dist/data-structures/hash/hash-table.js +0 -281
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/hash-table.js +0 -2
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/matrix2d.js +0 -2
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/vector2d.js +0 -2
- 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
|
@@ -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
|
import { calcMinUnitsRequired, rangeCheck } from '../../utils';
|
|
11
11
|
|
|
@@ -22,19 +22,16 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
22
22
|
protected _bucketLast = 0;
|
|
23
23
|
protected _lastInBucket = 0;
|
|
24
24
|
protected _bucketCount = 0;
|
|
25
|
-
protected readonly _bucketSize: number;
|
|
25
|
+
protected readonly _bucketSize: number = 1 << 12;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
* The constructor initializes a data structure with a specified bucket size and populates it with
|
|
29
|
-
* elements from an iterable.
|
|
30
|
-
* @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
|
|
31
|
-
* contains the initial elements to be stored in the data structure. It can also be an object with a
|
|
32
|
-
* `length` property or a `size` property, which represents the number of elements in the iterable.
|
|
33
|
-
* @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
|
|
34
|
-
* stored in each bucket. It determines the size of each bucket in the data structure.
|
|
35
|
-
*/
|
|
36
|
-
constructor(elements: IterableWithSizeOrLength<E> = [], bucketSize = 1 << 12) {
|
|
27
|
+
constructor(elements: IterableWithSizeOrLength<E> = [], options?: DequeOptions) {
|
|
37
28
|
super();
|
|
29
|
+
|
|
30
|
+
if (options) {
|
|
31
|
+
const { bucketSize } = options;
|
|
32
|
+
if (typeof bucketSize === 'number') this._bucketSize = bucketSize;
|
|
33
|
+
}
|
|
34
|
+
|
|
38
35
|
let _size: number;
|
|
39
36
|
if ('length' in elements) {
|
|
40
37
|
if (elements.length instanceof Function) _size = elements.length();
|
|
@@ -44,7 +41,6 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
44
41
|
else _size = elements.size;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
this._bucketSize = bucketSize;
|
|
48
44
|
this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
|
|
49
45
|
for (let i = 0; i < this._bucketCount; ++i) {
|
|
50
46
|
this._buckets.push(new Array(this._bucketSize));
|
|
@@ -637,7 +633,7 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
637
633
|
* satisfy the given predicate function.
|
|
638
634
|
*/
|
|
639
635
|
filter(predicate: ElementCallback<E, boolean>, thisArg?: any): Deque<E> {
|
|
640
|
-
const newDeque = new Deque<E>([], this._bucketSize);
|
|
636
|
+
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
|
|
641
637
|
let index = 0;
|
|
642
638
|
for (const el of this) {
|
|
643
639
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -666,7 +662,7 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
666
662
|
* @returns a new Deque object with the mapped values.
|
|
667
663
|
*/
|
|
668
664
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T> {
|
|
669
|
-
const newDeque = new Deque<T>([], this._bucketSize);
|
|
665
|
+
const newDeque = new Deque<T>([], { bucketSize: this._bucketSize });
|
|
670
666
|
let index = 0;
|
|
671
667
|
for (const el of this) {
|
|
672
668
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -13,29 +13,30 @@ import { SinglyLinkedList } from '../linked-list';
|
|
|
13
13
|
* 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.
|
|
14
14
|
* 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
|
|
15
15
|
* 5. Data Buffering: Acting as a buffer for data packets in network communication.
|
|
16
|
-
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store
|
|
16
|
+
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
|
|
17
17
|
* 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
18
18
|
*/
|
|
19
19
|
export class Queue<E = any> extends IterableElementBase<E> {
|
|
20
20
|
/**
|
|
21
21
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
22
22
|
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
23
|
-
* will be used to initialize the `
|
|
23
|
+
* will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
|
|
24
24
|
* initialized as an empty array.
|
|
25
25
|
*/
|
|
26
|
-
constructor(elements
|
|
26
|
+
constructor(elements: Iterable<E> = []) {
|
|
27
27
|
super();
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (elements) {
|
|
29
|
+
for (const el of elements) this.push(el);
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
protected
|
|
33
|
+
protected _elements: E[] = [];
|
|
33
34
|
|
|
34
|
-
get
|
|
35
|
-
return this.
|
|
35
|
+
get elements(): E[] {
|
|
36
|
+
return this._elements;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
protected _offset: number;
|
|
39
|
+
protected _offset: number = 0;
|
|
39
40
|
|
|
40
41
|
get offset(): number {
|
|
41
42
|
return this._offset;
|
|
@@ -46,19 +47,19 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
46
47
|
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
47
48
|
*/
|
|
48
49
|
get size(): number {
|
|
49
|
-
return this.
|
|
50
|
+
return this.elements.length - this.offset;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
54
55
|
* Space Complexity: O(1) - no additional space is used.
|
|
55
56
|
*
|
|
56
|
-
* The `first` function returns the first element of the array `
|
|
57
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `
|
|
57
|
+
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
58
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
58
59
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
59
60
|
*/
|
|
60
61
|
get first(): E | undefined {
|
|
61
|
-
return this.size > 0 ? this.
|
|
62
|
+
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
@@ -71,11 +72,11 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
71
72
|
* Space Complexity: O(1) - no additional space is used.
|
|
72
73
|
*
|
|
73
74
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
74
|
-
* @returns The method `get last()` returns the last element of the `
|
|
75
|
+
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
75
76
|
* array is empty, it returns `undefined`.
|
|
76
77
|
*/
|
|
77
78
|
get last(): E | undefined {
|
|
78
|
-
return this.size > 0 ? this.
|
|
79
|
+
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
@@ -109,7 +110,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
109
110
|
* @returns The `add` method is returning a `Queue<E>` object.
|
|
110
111
|
*/
|
|
111
112
|
push(element: E): boolean {
|
|
112
|
-
this.
|
|
113
|
+
this.elements.push(element);
|
|
113
114
|
return true;
|
|
114
115
|
}
|
|
115
116
|
|
|
@@ -132,11 +133,11 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
132
133
|
const first = this.first;
|
|
133
134
|
this._offset += 1;
|
|
134
135
|
|
|
135
|
-
if (this.offset * 2 < this.
|
|
136
|
+
if (this.offset * 2 < this.elements.length) return first;
|
|
136
137
|
|
|
137
138
|
// only delete dequeued elements when reaching half size
|
|
138
139
|
// to decrease latency of shifting elements.
|
|
139
|
-
this.
|
|
140
|
+
this._elements = this.elements.slice(this.offset);
|
|
140
141
|
this._offset = 0;
|
|
141
142
|
return first;
|
|
142
143
|
}
|
|
@@ -150,8 +151,8 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
150
151
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
151
152
|
* Space Complexity: O(1) - no additional space is used.
|
|
152
153
|
*
|
|
153
|
-
* The `peek` function returns the first element of the array `
|
|
154
|
-
* @returns The `peek()` method returns the first element of the data structure, represented by the `
|
|
154
|
+
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
155
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
155
156
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
156
157
|
*/
|
|
157
158
|
peek(): E | undefined {
|
|
@@ -168,7 +169,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
168
169
|
* Space Complexity: O(1) - no additional space is used.
|
|
169
170
|
*
|
|
170
171
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
171
|
-
* @returns The method `peekLast()` returns the last element of the `
|
|
172
|
+
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
172
173
|
* array is empty, it returns `undefined`.
|
|
173
174
|
*/
|
|
174
175
|
peekLast(): E | undefined {
|
|
@@ -219,7 +220,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
219
220
|
* @param index
|
|
220
221
|
*/
|
|
221
222
|
getAt(index: number): E | undefined {
|
|
222
|
-
return this.
|
|
223
|
+
return this.elements[index];
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
/**
|
|
@@ -247,18 +248,18 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
247
248
|
* Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
|
|
248
249
|
* Space Complexity: O(n) - where n is the number of elements in the queue.
|
|
249
250
|
*
|
|
250
|
-
* The toArray() function returns an array of elements from the current offset to the end of the
|
|
251
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
251
252
|
* @returns An array of type E is being returned.
|
|
252
253
|
*/
|
|
253
254
|
toArray(): E[] {
|
|
254
|
-
return this.
|
|
255
|
+
return this.elements.slice(this.offset);
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
/**
|
|
258
|
-
* The clear function resets the
|
|
259
|
+
* The clear function resets the elements array and offset to their initial values.
|
|
259
260
|
*/
|
|
260
261
|
clear(): void {
|
|
261
|
-
this.
|
|
262
|
+
this._elements = [];
|
|
262
263
|
this._offset = 0;
|
|
263
264
|
}
|
|
264
265
|
|
|
@@ -275,7 +276,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
275
276
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
276
277
|
*/
|
|
277
278
|
clone(): Queue<E> {
|
|
278
|
-
return new Queue(this.
|
|
279
|
+
return new Queue(this.elements.slice(this.offset));
|
|
279
280
|
}
|
|
280
281
|
|
|
281
282
|
/**
|
|
@@ -345,7 +346,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
345
346
|
*/
|
|
346
347
|
|
|
347
348
|
protected* _getIterator(): IterableIterator<E> {
|
|
348
|
-
for (const item of this.
|
|
349
|
+
for (const item of this.elements) {
|
|
349
350
|
yield item;
|
|
350
351
|
}
|
|
351
352
|
}
|
|
@@ -23,17 +23,14 @@ export class Stack<E = any> extends IterableElementBase<E> {
|
|
|
23
23
|
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
24
24
|
* is provided and is an array, it is assigned to the `_elements
|
|
25
25
|
*/
|
|
26
|
-
constructor(elements
|
|
26
|
+
constructor(elements: Iterable<E> = []) {
|
|
27
27
|
super();
|
|
28
|
-
this._elements = [];
|
|
29
28
|
if (elements) {
|
|
30
|
-
for (const el of elements)
|
|
31
|
-
this.push(el);
|
|
32
|
-
}
|
|
29
|
+
for (const el of elements) this.push(el);
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
protected _elements: E[];
|
|
33
|
+
protected _elements: E[] = [];
|
|
37
34
|
|
|
38
35
|
get elements(): E[] {
|
|
39
36
|
return this._elements;
|
|
@@ -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
|
/**
|
|
@@ -38,31 +38,30 @@ export class TrieNode {
|
|
|
38
38
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
39
39
|
*/
|
|
40
40
|
export class Trie extends IterableElementBase<string> {
|
|
41
|
-
constructor(words
|
|
41
|
+
constructor(words: Iterable<string> = [], options?: TrieOptions) {
|
|
42
42
|
super();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (options) {
|
|
44
|
+
const { caseSensitive } = options;
|
|
45
|
+
if (caseSensitive !== undefined) this._caseSensitive = caseSensitive;
|
|
46
|
+
}
|
|
46
47
|
if (words) {
|
|
47
|
-
for (const word of words)
|
|
48
|
-
this.add(word);
|
|
49
|
-
}
|
|
48
|
+
for (const word of words) this.add(word);
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
protected _size: number;
|
|
52
|
+
protected _size: number = 0;
|
|
54
53
|
|
|
55
54
|
get size(): number {
|
|
56
55
|
return this._size;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
protected _caseSensitive: boolean;
|
|
58
|
+
protected _caseSensitive: boolean = true;
|
|
60
59
|
|
|
61
60
|
get caseSensitive(): boolean {
|
|
62
61
|
return this._caseSensitive;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
protected _root: TrieNode;
|
|
64
|
+
protected _root: TrieNode = new TrieNode('');
|
|
66
65
|
|
|
67
66
|
get root() {
|
|
68
67
|
return this._root;
|
|
@@ -6,6 +6,6 @@ export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K,
|
|
|
6
6
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
8
|
export type BinaryTreeOptions<K> = {
|
|
9
|
-
iterationType
|
|
10
|
-
extractor
|
|
9
|
+
iterationType?: IterationType,
|
|
10
|
+
extractor?: (key: K) => number
|
|
11
11
|
}
|
|
@@ -7,5 +7,5 @@ export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTN
|
|
|
7
7
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
8
8
|
|
|
9
9
|
export type BSTOptions<K> = BinaryTreeOptions<K> & {
|
|
10
|
-
variant
|
|
10
|
+
variant?: BSTVariant
|
|
11
11
|
}
|
|
@@ -5,4 +5,4 @@ export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNo
|
|
|
5
5
|
|
|
6
6
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
|
-
export type TreeMultimapOptions<K> =
|
|
8
|
+
export type TreeMultimapOptions<K> = AVLTreeOptions<K> & {}
|
|
@@ -5,9 +5,13 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export type LinkedHashMapOptions<K> = {
|
|
9
|
+
hashFn?: (key: K) => string;
|
|
10
|
+
objHashFn?: (key: K) => object;
|
|
11
|
+
};
|
|
12
|
+
|
|
8
13
|
export type HashMapOptions<K> = {
|
|
9
|
-
hashFn
|
|
10
|
-
objHashFn: (key: K) => object;
|
|
14
|
+
hashFn?: (key: K) => string;
|
|
11
15
|
};
|
|
12
16
|
|
|
13
17
|
export type HashMapStoreItem<K, V> = { key: K; value: V };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export type SkipLinkedListOptions = { maxLevel?: number; probability?: number };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export type DequeOptions = { bucketSize?: number };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export type TrieOptions = { caseSensitive?: boolean };
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Tyler Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { HashFunction } from '../../types';
|
|
9
|
-
export declare class HashTableNode<K = any, V = any> {
|
|
10
|
-
key: K;
|
|
11
|
-
value: V;
|
|
12
|
-
next: HashTableNode<K, V> | undefined;
|
|
13
|
-
constructor(key: K, value: V);
|
|
14
|
-
}
|
|
15
|
-
export declare class HashTable<K = any, V = any> {
|
|
16
|
-
protected static readonly DEFAULT_CAPACITY = 16;
|
|
17
|
-
protected static readonly LOAD_FACTOR = 0.75;
|
|
18
|
-
constructor(capacity?: number, hashFn?: HashFunction<K>);
|
|
19
|
-
protected _capacity: number;
|
|
20
|
-
get capacity(): number;
|
|
21
|
-
protected _size: number;
|
|
22
|
-
get size(): number;
|
|
23
|
-
protected _buckets: Array<HashTableNode<K, V> | undefined>;
|
|
24
|
-
get buckets(): Array<HashTableNode<K, V> | undefined>;
|
|
25
|
-
protected _hashFn: HashFunction<K>;
|
|
26
|
-
get hashFn(): HashFunction<K>;
|
|
27
|
-
/**
|
|
28
|
-
* The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
|
|
29
|
-
* @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
|
|
30
|
-
* table. It is of type K, which is a generic type representing the key's data type.
|
|
31
|
-
* @param {V} value - The parameter `value` represents the value that you want to associate with the given key in the hash
|
|
32
|
-
* table.
|
|
33
|
-
* @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
|
|
34
|
-
* value.
|
|
35
|
-
*/
|
|
36
|
-
set(key: K, value: V): void;
|
|
37
|
-
/**
|
|
38
|
-
* The `get` function retrieves the value associated with a given key from a hash table.
|
|
39
|
-
* @param {K} key - The `key` parameter represents the key of the element that we want to retrieve from the data
|
|
40
|
-
* structure.
|
|
41
|
-
* @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
|
|
42
|
-
* not found, it returns `undefined`.
|
|
43
|
-
*/
|
|
44
|
-
get(key: K): V | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* The delete function removes a key-value pair from a hash table.
|
|
47
|
-
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
|
|
48
|
-
* table.
|
|
49
|
-
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
|
|
50
|
-
* any value.
|
|
51
|
-
*/
|
|
52
|
-
delete(key: K): void;
|
|
53
|
-
[Symbol.iterator](): Generator<[K, V], void, undefined>;
|
|
54
|
-
forEach(callback: (entry: [K, V], index: number, table: HashTable<K, V>) => void): void;
|
|
55
|
-
filter(predicate: (entry: [K, V], index: number, table: HashTable<K, V>) => boolean): HashTable<K, V>;
|
|
56
|
-
map<T>(callback: (entry: [K, V], index: number, table: HashTable<K, V>) => T): HashTable<K, T>;
|
|
57
|
-
reduce<T>(callback: (accumulator: T, entry: [K, V], index: number, table: HashTable<K, V>) => T, initialValue: T): T;
|
|
58
|
-
/**
|
|
59
|
-
* The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
|
|
60
|
-
* capacity of the data structure.
|
|
61
|
-
* @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
|
|
62
|
-
* code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
|
|
63
|
-
* function is used to
|
|
64
|
-
* @returns the hash value of the key modulo the capacity of the data structure.
|
|
65
|
-
*/
|
|
66
|
-
protected _defaultHashFn(key: K): number;
|
|
67
|
-
/**
|
|
68
|
-
* The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
|
|
69
|
-
* string hash function.
|
|
70
|
-
* @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
|
|
71
|
-
* type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
|
|
72
|
-
* @returns a number, which is the result of the multiplicative string hash function applied to the input key.
|
|
73
|
-
*/
|
|
74
|
-
protected _multiplicativeStringHashFn<K>(key: K): number;
|
|
75
|
-
/**
|
|
76
|
-
* The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
|
|
77
|
-
* @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
|
|
78
|
-
* type, but it will be converted to a string using the `String()` function before calculating the hash.
|
|
79
|
-
* @returns a number, which is the hash value calculated for the given key.
|
|
80
|
-
*/
|
|
81
|
-
protected _murmurStringHashFn<K>(key: K): number;
|
|
82
|
-
/**
|
|
83
|
-
* The _hash function takes a key and returns a number.
|
|
84
|
-
* @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
|
|
85
|
-
* @returns The hash function is returning a number.
|
|
86
|
-
*/
|
|
87
|
-
protected _hash(key: K): number;
|
|
88
|
-
/**
|
|
89
|
-
* The function calculates a hash value for a given string using the djb2 algorithm.
|
|
90
|
-
* @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
|
|
91
|
-
* which we want to calculate the hash value.
|
|
92
|
-
* @returns a number, which is the hash value of the input string.
|
|
93
|
-
*/
|
|
94
|
-
protected _stringHash(key: string): number;
|
|
95
|
-
/**
|
|
96
|
-
* The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
|
|
97
|
-
* @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
|
|
98
|
-
* boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
|
|
99
|
-
* the key, which can be used for
|
|
100
|
-
* @returns a number, which is the hash value of the key.
|
|
101
|
-
*/
|
|
102
|
-
protected _objectHash(key: K): number;
|
|
103
|
-
/**
|
|
104
|
-
* The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
|
|
105
|
-
* capacity and rehashing all the existing key-value pairs into the new buckets.
|
|
106
|
-
*/
|
|
107
|
-
protected _expand(): void;
|
|
108
|
-
}
|