directed-graph-typed 1.54.2 → 2.0.0
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/base/iterable-element-base.d.ts +14 -40
- package/dist/data-structures/base/iterable-element-base.js +14 -11
- package/dist/data-structures/base/linear-base.d.ts +277 -0
- package/dist/data-structures/base/linear-base.js +552 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
- package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
- package/dist/data-structures/binary-tree/avl-tree.js +76 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +244 -149
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +89 -133
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
- package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
- package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +3 -11
- package/dist/data-structures/heap/heap.js +0 -10
- package/dist/data-structures/heap/max-heap.d.ts +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
- package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
- package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
- package/dist/data-structures/queue/deque.d.ts +130 -91
- package/dist/data-structures/queue/deque.js +269 -169
- package/dist/data-structures/queue/queue.d.ts +84 -40
- package/dist/data-structures/queue/queue.js +134 -50
- package/dist/data-structures/stack/stack.d.ts +3 -11
- package/dist/data-structures/stack/stack.js +0 -10
- package/dist/data-structures/trie/trie.d.ts +4 -3
- package/dist/data-structures/trie/trie.js +3 -0
- package/dist/types/data-structures/base/base.d.ts +9 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/queue/deque.d.ts +2 -3
- package/dist/types/data-structures/queue/queue.d.ts +2 -2
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +29 -20
- package/src/data-structures/base/linear-base.ts +649 -0
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
- package/src/data-structures/binary-tree/avl-tree.ts +99 -29
- package/src/data-structures/binary-tree/binary-tree.ts +474 -257
- package/src/data-structures/binary-tree/bst.ts +150 -152
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/heap/heap.ts +3 -14
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/heap/min-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
- package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +286 -183
- package/src/data-structures/queue/queue.ts +149 -63
- package/src/data-structures/stack/stack.ts +3 -18
- package/src/data-structures/trie/trie.ts +7 -3
- package/src/types/data-structures/base/base.ts +17 -8
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
- package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/types/data-structures/queue/deque.ts +2 -3
- package/src/types/data-structures/queue/queue.ts +2 -2
- package/src/utils/utils.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
2
2
|
import { Comparable } from '../../utils';
|
|
3
3
|
import { OptValue } from '../../common';
|
|
4
|
-
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
4
|
+
export type BSTOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'> & {
|
|
5
5
|
specifyComparable?: (key: K) => Comparable;
|
|
6
6
|
isReverse?: boolean;
|
|
7
7
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RedBlackTreeOptions } from './red-black-tree';
|
|
2
|
-
export type TreeMultiMapOptions<K, V, R> =
|
|
2
|
+
export type TreeMultiMapOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type DoublyLinkedListOptions<E, R> =
|
|
1
|
+
import { LinearBaseOptions } from '../base';
|
|
2
|
+
export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type SinglyLinkedListOptions<E, R> =
|
|
1
|
+
import { LinearBaseOptions } from '../base';
|
|
2
|
+
export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { Comparable, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directed-graph-typed",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Directed Graph. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -147,6 +147,6 @@
|
|
|
147
147
|
"typescript": "^4.9.5"
|
|
148
148
|
},
|
|
149
149
|
"dependencies": {
|
|
150
|
-
"data-structure-typed": "^
|
|
150
|
+
"data-structure-typed": "^2.0.0"
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
|
|
2
2
|
|
|
3
|
-
export abstract class IterableElementBase<E, R
|
|
3
|
+
export abstract class IterableElementBase<E, R> {
|
|
4
4
|
/**
|
|
5
5
|
* The protected constructor initializes the options for the IterableElementBase class, including the
|
|
6
6
|
* toElementFn function.
|
|
@@ -14,17 +14,8 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
abstract get size(): number;
|
|
18
|
-
|
|
19
17
|
protected _toElementFn?: (rawElement: R) => E;
|
|
20
18
|
|
|
21
|
-
/**
|
|
22
|
-
* The function returns the _toElementFn property, which is a function that converts a raw element to
|
|
23
|
-
* a specific type.
|
|
24
|
-
* @returns The function `get toElementFn()` is returning either a function that takes a raw element
|
|
25
|
-
* `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
|
|
26
|
-
* `_toElementFn`.
|
|
27
|
-
*/
|
|
28
19
|
get toElementFn(): ((rawElement: R) => E) | undefined {
|
|
29
20
|
return this._toElementFn;
|
|
30
21
|
}
|
|
@@ -68,7 +59,7 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
68
59
|
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
69
60
|
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
70
61
|
*/
|
|
71
|
-
every(predicate: ElementCallback<E, R, boolean
|
|
62
|
+
every(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean {
|
|
72
63
|
let index = 0;
|
|
73
64
|
for (const item of this) {
|
|
74
65
|
if (!predicate.call(thisArg, item, index++, this)) {
|
|
@@ -92,7 +83,7 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
92
83
|
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
93
84
|
* in the collection, and false otherwise.
|
|
94
85
|
*/
|
|
95
|
-
some(predicate: ElementCallback<E, R, boolean
|
|
86
|
+
some(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean {
|
|
96
87
|
let index = 0;
|
|
97
88
|
for (const item of this) {
|
|
98
89
|
if (predicate.call(thisArg, item, index++, this)) {
|
|
@@ -115,20 +106,23 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
115
106
|
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
116
107
|
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
117
108
|
*/
|
|
118
|
-
forEach(callbackfn: ElementCallback<E, R, void
|
|
109
|
+
forEach(callbackfn: ElementCallback<E, R, void>, thisArg?: any): void {
|
|
119
110
|
let index = 0;
|
|
120
111
|
for (const item of this) {
|
|
121
112
|
callbackfn.call(thisArg, item, index++, this);
|
|
122
113
|
}
|
|
123
114
|
}
|
|
124
115
|
|
|
116
|
+
find<S extends E>(predicate: ElementCallback<E, R, S>, thisArg?: any): S | undefined;
|
|
117
|
+
find(predicate: ElementCallback<E, R, unknown>, thisArg?: any): E | undefined;
|
|
118
|
+
|
|
125
119
|
/**
|
|
126
120
|
* Time Complexity: O(n)
|
|
127
121
|
* Space Complexity: O(1)
|
|
128
122
|
*
|
|
129
123
|
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
130
124
|
* element that satisfies the provided callback function.
|
|
131
|
-
* @param
|
|
125
|
+
* @param predicate - The predicate parameter is a function that will be called for each element in
|
|
132
126
|
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
133
127
|
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
134
128
|
* current element matches the desired condition.
|
|
@@ -138,10 +132,10 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
138
132
|
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
139
133
|
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
140
134
|
*/
|
|
141
|
-
find(
|
|
135
|
+
find(predicate: ElementCallback<E, R, boolean>, thisArg?: any): E | undefined {
|
|
142
136
|
let index = 0;
|
|
143
137
|
for (const item of this) {
|
|
144
|
-
if (
|
|
138
|
+
if (predicate.call(thisArg, item, index++, this)) return item;
|
|
145
139
|
}
|
|
146
140
|
|
|
147
141
|
return;
|
|
@@ -164,6 +158,10 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
164
158
|
return false;
|
|
165
159
|
}
|
|
166
160
|
|
|
161
|
+
reduce(callbackfn: ReduceElementCallback<E, R>): E;
|
|
162
|
+
reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
|
|
163
|
+
reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
|
|
164
|
+
|
|
167
165
|
/**
|
|
168
166
|
* Time Complexity: O(n)
|
|
169
167
|
* Space Complexity: O(1)
|
|
@@ -177,15 +175,26 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
177
175
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
178
176
|
* all the elements in the array and applying the callback function to each element.
|
|
179
177
|
*/
|
|
180
|
-
reduce<U>(callbackfn: ReduceElementCallback<E, R, U
|
|
181
|
-
let accumulator = initialValue;
|
|
178
|
+
reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue?: U): U {
|
|
179
|
+
let accumulator = initialValue ?? (0 as U);
|
|
182
180
|
let index = 0;
|
|
183
181
|
for (const item of this) {
|
|
184
|
-
accumulator = callbackfn(accumulator, item
|
|
182
|
+
accumulator = callbackfn(accumulator, item, index++, this);
|
|
185
183
|
}
|
|
186
184
|
return accumulator;
|
|
187
185
|
}
|
|
188
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Time Complexity: O(n)
|
|
189
|
+
* Space Complexity: O(n)
|
|
190
|
+
*
|
|
191
|
+
* The `toArray` function converts a linked list into an array.
|
|
192
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
193
|
+
*/
|
|
194
|
+
toArray(): E[] {
|
|
195
|
+
return [...this];
|
|
196
|
+
}
|
|
197
|
+
|
|
189
198
|
/**
|
|
190
199
|
* Time Complexity: O(n)
|
|
191
200
|
* Space Complexity: O(n)
|
|
@@ -210,7 +219,7 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
210
219
|
|
|
211
220
|
abstract clear(): void;
|
|
212
221
|
|
|
213
|
-
abstract clone():
|
|
222
|
+
abstract clone(): IterableElementBase<E, R>;
|
|
214
223
|
|
|
215
224
|
abstract map(...args: any[]): any;
|
|
216
225
|
|