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.
Files changed (84) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
  2. package/dist/data-structures/base/iterable-element-base.js +14 -11
  3. package/dist/data-structures/base/linear-base.d.ts +277 -0
  4. package/dist/data-structures/base/linear-base.js +552 -0
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
  10. package/dist/data-structures/binary-tree/avl-tree.js +76 -8
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
  12. package/dist/data-structures/binary-tree/binary-tree.js +244 -149
  13. package/dist/data-structures/binary-tree/bst.d.ts +62 -56
  14. package/dist/data-structures/binary-tree/bst.js +89 -133
  15. package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  16. package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
  17. package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
  18. package/dist/data-structures/binary-tree/tree-counter.js +12 -12
  19. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  20. package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
  21. package/dist/data-structures/graph/abstract-graph.js +2 -2
  22. package/dist/data-structures/heap/heap.d.ts +3 -11
  23. package/dist/data-structures/heap/heap.js +0 -10
  24. package/dist/data-structures/heap/max-heap.d.ts +2 -2
  25. package/dist/data-structures/heap/min-heap.d.ts +2 -2
  26. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  27. package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
  28. package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  29. package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
  30. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  31. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  32. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
  33. package/dist/data-structures/queue/deque.d.ts +130 -91
  34. package/dist/data-structures/queue/deque.js +269 -169
  35. package/dist/data-structures/queue/queue.d.ts +84 -40
  36. package/dist/data-structures/queue/queue.js +134 -50
  37. package/dist/data-structures/stack/stack.d.ts +3 -11
  38. package/dist/data-structures/stack/stack.js +0 -10
  39. package/dist/data-structures/trie/trie.d.ts +4 -3
  40. package/dist/data-structures/trie/trie.js +3 -0
  41. package/dist/types/data-structures/base/base.d.ts +9 -4
  42. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  43. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  44. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  45. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  46. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  47. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  48. package/dist/types/data-structures/queue/deque.d.ts +2 -3
  49. package/dist/types/data-structures/queue/queue.d.ts +2 -2
  50. package/dist/utils/utils.d.ts +2 -2
  51. package/package.json +2 -2
  52. package/src/data-structures/base/iterable-element-base.ts +29 -20
  53. package/src/data-structures/base/linear-base.ts +649 -0
  54. package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
  55. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
  56. package/src/data-structures/binary-tree/avl-tree.ts +99 -29
  57. package/src/data-structures/binary-tree/binary-tree.ts +474 -257
  58. package/src/data-structures/binary-tree/bst.ts +150 -152
  59. package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
  60. package/src/data-structures/binary-tree/tree-counter.ts +33 -27
  61. package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
  62. package/src/data-structures/graph/abstract-graph.ts +2 -2
  63. package/src/data-structures/heap/heap.ts +3 -14
  64. package/src/data-structures/heap/max-heap.ts +2 -2
  65. package/src/data-structures/heap/min-heap.ts +2 -2
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  67. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  70. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  71. package/src/data-structures/queue/deque.ts +286 -183
  72. package/src/data-structures/queue/queue.ts +149 -63
  73. package/src/data-structures/stack/stack.ts +3 -18
  74. package/src/data-structures/trie/trie.ts +7 -3
  75. package/src/types/data-structures/base/base.ts +17 -8
  76. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  80. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  81. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  82. package/src/types/data-structures/queue/deque.ts +2 -3
  83. package/src/types/data-structures/queue/queue.ts +2 -2
  84. package/src/utils/utils.ts +2 -2
@@ -5,6 +5,7 @@ export type BinaryTreeOptions<K, V, R> = {
5
5
  iterationType?: IterationType;
6
6
  toEntryFn?: ToEntryFn<K, V, R>;
7
7
  isMapMode?: boolean;
8
+ isDuplicate?: boolean;
8
9
  };
9
10
  export type BinaryTreePrintOptions = {
10
11
  isShowUndefined?: boolean;
@@ -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> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {};
2
+ export type TreeMultiMapOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -1,2 +1,2 @@
1
- import { IterableElementBaseOptions } from '../base';
2
- export type DoublyLinkedListOptions<E, R> = IterableElementBaseOptions<E, R> & {};
1
+ import { LinearBaseOptions } from '../base';
2
+ export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -1,2 +1,2 @@
1
- import { IterableElementBaseOptions } from '../base';
2
- export type SinglyLinkedListOptions<E, R> = IterableElementBaseOptions<E, R> & {};
1
+ import { LinearBaseOptions } from '../base';
2
+ export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -1,5 +1,4 @@
1
- import { IterableElementBaseOptions } from '../base';
1
+ import { LinearBaseOptions } from '../base';
2
2
  export type DequeOptions<E, R> = {
3
3
  bucketSize?: number;
4
- maxLen?: number;
5
- } & IterableElementBaseOptions<E, R>;
4
+ } & LinearBaseOptions<E, R>;
@@ -1,4 +1,4 @@
1
- import { IterableElementBaseOptions } from '../base';
2
- export type QueueOptions<E, R> = IterableElementBaseOptions<E, R> & {
1
+ import { LinearBaseOptions } from '../base';
2
+ export type QueueOptions<E, R> = LinearBaseOptions<E, R> & {
3
3
  autoCompactRatio?: number;
4
4
  };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
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": "graph-typed",
3
- "version": "1.54.2",
3
+ "version": "2.0.0",
4
4
  "description": "Graph. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -136,6 +136,6 @@
136
136
  "typescript": "^4.9.5"
137
137
  },
138
138
  "dependencies": {
139
- "data-structure-typed": "^1.54.2"
139
+ "data-structure-typed": "^2.0.0"
140
140
  }
141
141
  }
@@ -1,6 +1,6 @@
1
1
  import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
2
 
3
- export abstract class IterableElementBase<E, R, C> {
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, C>, thisArg?: any): 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, C>, thisArg?: any): 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, C>, thisArg?: any): 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 callbackfn - The callbackfn parameter is a function that will be called for each element in
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(callbackfn: ElementCallback<E, R, boolean, C>, thisArg?: any): E | undefined {
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 (callbackfn.call(thisArg, item, index++, this)) return item;
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, C>, initialValue: U): 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 as E, index++, this);
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(): C;
222
+ abstract clone(): IterableElementBase<E, R>;
214
223
 
215
224
  abstract map(...args: any[]): any;
216
225