data-structure-typed 1.49.2 → 1.49.4
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 +69 -66
- package/README_zh-CN.md +43 -48
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +187 -187
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +8 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +43 -29
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +6 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
- 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.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/cjs/data-structures/queue/queue.js +40 -40
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +8 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +43 -29
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +6 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/mjs/data-structures/queue/queue.js +39 -39
- package/dist/umd/data-structure-typed.js +176 -158
- 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/binary-tree.ts +1 -1
- package/src/data-structures/graph/abstract-graph.ts +56 -27
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/queue.ts +45 -45
- package/test/performance/data-structures/comparison/comparison.test.ts +12 -12
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -27
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
- package/test/performance/data-structures/queue/deque.test.ts +8 -8
- package/test/performance/data-structures/queue/queue.test.ts +5 -5
- package/test/performance/data-structures/stack/stack.test.ts +11 -11
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +12 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +63 -5
- package/test/unit/data-structures/graph/undirected-graph.test.ts +61 -4
- package/test/unit/data-structures/hash/hash-map.test.ts +21 -0
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +27 -0
- package/test/utils/big-o.ts +14 -14
|
@@ -32,6 +32,32 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
32
32
|
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
33
33
|
*/
|
|
34
34
|
get size(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
37
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
38
|
+
*
|
|
39
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
40
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
41
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
get first(): E | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
46
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
50
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
51
|
+
*
|
|
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 `_nodes` array if the array is not empty. If the
|
|
54
|
+
* array is empty, it returns `undefined`.
|
|
55
|
+
*/
|
|
56
|
+
get last(): E | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* 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.
|
|
59
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
60
|
+
*/
|
|
35
61
|
/**
|
|
36
62
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
37
63
|
* @public
|
|
@@ -42,7 +68,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
42
68
|
*/
|
|
43
69
|
static fromArray<E>(elements: E[]): Queue<E>;
|
|
44
70
|
/**
|
|
45
|
-
* Time Complexity: O(1) - constant time as it
|
|
71
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
46
72
|
* Space Complexity: O(1) - no additional space is used.
|
|
47
73
|
*/
|
|
48
74
|
/**
|
|
@@ -55,7 +81,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
55
81
|
*/
|
|
56
82
|
push(element: E): boolean;
|
|
57
83
|
/**
|
|
58
|
-
* Time Complexity: O(
|
|
84
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
59
85
|
* Space Complexity: O(1) - no additional space is used.
|
|
60
86
|
*/
|
|
61
87
|
/**
|
|
@@ -67,19 +93,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
67
93
|
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
68
94
|
*/
|
|
69
95
|
shift(): E | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
72
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
73
|
-
*/
|
|
74
|
-
/**
|
|
75
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
76
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
77
|
-
*
|
|
78
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
79
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
80
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
81
|
-
*/
|
|
82
|
-
get first(): E | undefined;
|
|
83
96
|
/**
|
|
84
97
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
85
98
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -93,19 +106,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
93
106
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
94
107
|
*/
|
|
95
108
|
peek(): E | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
98
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
99
|
-
*/
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
102
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
103
|
-
*
|
|
104
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
105
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
106
|
-
* array is empty, it returns `undefined`.
|
|
107
|
-
*/
|
|
108
|
-
get last(): E | undefined;
|
|
109
109
|
/**
|
|
110
110
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
111
111
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -247,6 +247,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
247
247
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
248
248
|
*/
|
|
249
249
|
export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
250
|
+
/**
|
|
251
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
252
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
253
|
+
*/
|
|
254
|
+
get first(): E | undefined;
|
|
250
255
|
/**
|
|
251
256
|
* The enqueue function adds a value to the end of an array.
|
|
252
257
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -257,11 +262,6 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
257
262
|
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
258
263
|
*/
|
|
259
264
|
dequeue(): E | undefined;
|
|
260
|
-
/**
|
|
261
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
262
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
263
|
-
*/
|
|
264
|
-
get first(): E | undefined;
|
|
265
265
|
/**
|
|
266
266
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
267
267
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
@@ -36,6 +36,36 @@ export class Queue extends IterableElementBase {
|
|
|
36
36
|
get size() {
|
|
37
37
|
return this.nodes.length - this.offset;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
41
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
42
|
+
*
|
|
43
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
44
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
45
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
get first() {
|
|
48
|
+
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
52
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
56
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
57
|
+
*
|
|
58
|
+
* 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 `_nodes` array if the array is not empty. If the
|
|
60
|
+
* array is empty, it returns `undefined`.
|
|
61
|
+
*/
|
|
62
|
+
get last() {
|
|
63
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 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.
|
|
67
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
68
|
+
*/
|
|
39
69
|
/**
|
|
40
70
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
41
71
|
* @public
|
|
@@ -48,7 +78,7 @@ export class Queue extends IterableElementBase {
|
|
|
48
78
|
return new Queue(elements);
|
|
49
79
|
}
|
|
50
80
|
/**
|
|
51
|
-
* Time Complexity: O(1) - constant time as it
|
|
81
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
52
82
|
* Space Complexity: O(1) - no additional space is used.
|
|
53
83
|
*/
|
|
54
84
|
/**
|
|
@@ -64,7 +94,7 @@ export class Queue extends IterableElementBase {
|
|
|
64
94
|
return true;
|
|
65
95
|
}
|
|
66
96
|
/**
|
|
67
|
-
* Time Complexity: O(
|
|
97
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
68
98
|
* Space Complexity: O(1) - no additional space is used.
|
|
69
99
|
*/
|
|
70
100
|
/**
|
|
@@ -88,21 +118,6 @@ export class Queue extends IterableElementBase {
|
|
|
88
118
|
this._offset = 0;
|
|
89
119
|
return first;
|
|
90
120
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
93
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
94
|
-
*/
|
|
95
|
-
/**
|
|
96
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
97
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
98
|
-
*
|
|
99
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
100
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
101
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
102
|
-
*/
|
|
103
|
-
get first() {
|
|
104
|
-
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
105
|
-
}
|
|
106
121
|
/**
|
|
107
122
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
108
123
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -118,21 +133,6 @@ export class Queue extends IterableElementBase {
|
|
|
118
133
|
peek() {
|
|
119
134
|
return this.first;
|
|
120
135
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
123
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
124
|
-
*/
|
|
125
|
-
/**
|
|
126
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
127
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
128
|
-
*
|
|
129
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
130
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
131
|
-
* array is empty, it returns `undefined`.
|
|
132
|
-
*/
|
|
133
|
-
get last() {
|
|
134
|
-
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
135
|
-
}
|
|
136
136
|
/**
|
|
137
137
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
138
138
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -313,6 +313,13 @@ export class Queue extends IterableElementBase {
|
|
|
313
313
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
314
314
|
*/
|
|
315
315
|
export class LinkedListQueue extends SinglyLinkedList {
|
|
316
|
+
/**
|
|
317
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
318
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
319
|
+
*/
|
|
320
|
+
get first() {
|
|
321
|
+
return this.head?.value;
|
|
322
|
+
}
|
|
316
323
|
/**
|
|
317
324
|
* The enqueue function adds a value to the end of an array.
|
|
318
325
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -327,13 +334,6 @@ export class LinkedListQueue extends SinglyLinkedList {
|
|
|
327
334
|
dequeue() {
|
|
328
335
|
return this.shift();
|
|
329
336
|
}
|
|
330
|
-
/**
|
|
331
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
332
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
333
|
-
*/
|
|
334
|
-
get first() {
|
|
335
|
-
return this.head?.value;
|
|
336
|
-
}
|
|
337
337
|
/**
|
|
338
338
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
339
339
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|