directed-graph-typed 1.46.2 → 1.46.5

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 (42) hide show
  1. package/dist/data-structures/hash/hash-map.d.ts +31 -116
  2. package/dist/data-structures/hash/hash-map.js +126 -254
  3. package/dist/data-structures/hash/index.d.ts +0 -4
  4. package/dist/data-structures/hash/index.js +0 -4
  5. package/dist/data-structures/queue/deque.d.ts +6 -74
  6. package/dist/data-structures/queue/deque.js +20 -142
  7. package/dist/types/data-structures/hash/hash-map.d.ts +5 -0
  8. package/dist/types/data-structures/hash/index.d.ts +0 -4
  9. package/dist/types/data-structures/hash/index.js +0 -4
  10. package/dist/utils/utils.d.ts +1 -1
  11. package/dist/utils/utils.js +3 -3
  12. package/package.json +2 -2
  13. package/src/data-structures/hash/hash-map.ts +153 -275
  14. package/src/data-structures/hash/index.ts +0 -4
  15. package/src/data-structures/queue/deque.ts +22 -161
  16. package/src/types/data-structures/hash/hash-map.ts +6 -0
  17. package/src/types/data-structures/hash/index.ts +0 -4
  18. package/src/utils/utils.ts +1 -1
  19. package/dist/data-structures/hash/coordinate-map.d.ts +0 -44
  20. package/dist/data-structures/hash/coordinate-map.js +0 -62
  21. package/dist/data-structures/hash/coordinate-set.d.ts +0 -36
  22. package/dist/data-structures/hash/coordinate-set.js +0 -52
  23. package/dist/data-structures/hash/tree-map.d.ts +0 -2
  24. package/dist/data-structures/hash/tree-map.js +0 -6
  25. package/dist/data-structures/hash/tree-set.d.ts +0 -2
  26. package/dist/data-structures/hash/tree-set.js +0 -6
  27. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -1
  28. package/dist/types/data-structures/hash/coordinate-map.js +0 -2
  29. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -1
  30. package/dist/types/data-structures/hash/coordinate-set.js +0 -2
  31. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  32. package/dist/types/data-structures/hash/tree-map.js +0 -2
  33. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  34. package/dist/types/data-structures/hash/tree-set.js +0 -2
  35. package/src/data-structures/hash/coordinate-map.ts +0 -63
  36. package/src/data-structures/hash/coordinate-set.ts +0 -52
  37. package/src/data-structures/hash/tree-map.ts +0 -2
  38. package/src/data-structures/hash/tree-set.ts +0 -2
  39. package/src/types/data-structures/hash/coordinate-map.ts +0 -1
  40. package/src/types/data-structures/hash/coordinate-set.ts +0 -1
  41. package/src/types/data-structures/hash/tree-map.ts +0 -1
  42. package/src/types/data-structures/hash/tree-set.ts +0 -1
@@ -1,6 +1,2 @@
1
1
  export * from './hash-table';
2
- export * from './coordinate-map';
3
- export * from './coordinate-set';
4
- export * from './tree-map';
5
- export * from './tree-set';
6
2
  export * from './hash-map';
@@ -15,8 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./hash-table"), exports);
18
- __exportStar(require("./coordinate-map"), exports);
19
- __exportStar(require("./coordinate-set"), exports);
20
- __exportStar(require("./tree-map"), exports);
21
- __exportStar(require("./tree-set"), exports);
22
18
  __exportStar(require("./hash-map"), exports);
@@ -5,39 +5,13 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { IterableWithSizeOrLength, IterateDirection } from "../../types";
8
+ import { IterableWithSizeOrLength } from "../../types";
9
9
  /**
10
10
  * Deque can provide random access with O(1) time complexity
11
11
  * Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
12
12
  * Deque may experience performance jitter, but DoublyLinkedList will not
13
13
  * Deque is implemented using a dynamic array. Inserting or deleting beyond both ends of the array may require moving elements or reallocating space.
14
14
  */
15
- export declare class DequeIterator<E> {
16
- iterateDirection: IterateDirection;
17
- index: number;
18
- readonly deque: Deque<E>;
19
- /**
20
- * The constructor initializes the index, iterate direction, and prev/next functions for a
21
- * DequeIterator object.
22
- * @param {number} index - The index parameter represents the current index position of the iterator
23
- * within the deque. It is a number that indicates the position of the element that the iterator is
24
- * currently pointing to.
25
- * @param deque - The `deque` parameter is an instance of the `Deque` class. It represents a
26
- * double-ended queue data structure, which allows elements to be added or removed from both ends.
27
- * @param iterateDirection - The `iterateDirection` parameter is an optional parameter that specifies
28
- * the direction in which the iterator should iterate over the elements of the `deque`. It has a
29
- * default value of `IterateDirection.DEFAULT`.
30
- * @returns The constructor is not returning anything. It is used to initialize the properties of the
31
- * object being created.
32
- */
33
- constructor(index: number, deque: Deque<E>, iterateDirection?: IterateDirection);
34
- get current(): E;
35
- set current(newElement: E);
36
- isAccessible(): boolean;
37
- prev(): DequeIterator<E>;
38
- next(): DequeIterator<E>;
39
- clone(): DequeIterator<E>;
40
- }
41
15
  export declare class Deque<E> {
42
16
  protected _bucketFirst: number;
43
17
  protected _firstInBucket: number;
@@ -120,28 +94,14 @@ export declare class Deque<E> {
120
94
  */
121
95
  clear(): void;
122
96
  /**
123
- * The `begin()` function returns a new iterator for a deque starting from the first element.
124
- * @returns A new instance of the DequeIterator class is being returned.
125
- */
126
- begin(): DequeIterator<E>;
127
- /**
128
- * The `end()` function returns a new `DequeIterator` object with the size and reference to the
129
- * current deque.
130
- * @returns A new instance of the DequeIterator class is being returned.
97
+ * The below function is a generator that yields elements from a collection one by one.
131
98
  */
132
- end(): DequeIterator<E>;
99
+ begin(): Generator<E>;
133
100
  /**
134
- * The reverseBegin function returns a new DequeIterator object that starts at the last element of
135
- * the deque and iterates in reverse direction.
136
- * @returns A new instance of the DequeIterator class is being returned.
101
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
102
+ * the last element.
137
103
  */
138
- reverseBegin(): DequeIterator<E>;
139
- /**
140
- * The reverseEnd() function returns a new DequeIterator object that iterates over the elements of a
141
- * Deque in reverse order.
142
- * @returns A new instance of the DequeIterator class is being returned.
143
- */
144
- reverseEnd(): DequeIterator<E>;
104
+ reverseBegin(): Generator<E>;
145
105
  /**
146
106
  * Time Complexity - Amortized O(1) (possible reallocation)
147
107
  * Space Complexity - O(n) (due to potential resizing).
@@ -294,34 +254,6 @@ export declare class Deque<E> {
294
254
  * @returns The size of the data structure after the element has been deleted.
295
255
  */
296
256
  delete(element: E): number;
297
- /**
298
- * Time Complexity: O(n)
299
- * Space Complexity: O(1)
300
- */
301
- /**
302
- * Time Complexity: O(n)
303
- * Space Complexity: O(1)
304
- *
305
- * The function deletes an element from a deque using an iterator and returns the next iterator.
306
- * @param iter - The parameter `iter` is of type `DequeIterator<E>`. It represents an iterator object
307
- * that is used to iterate over elements in a deque (double-ended queue).
308
- * @returns the updated iterator after deleting an element from the deque.
309
- */
310
- deleteByIterator(iter: DequeIterator<E>): DequeIterator<E>;
311
- /**
312
- * Time Complexity: O(n)
313
- * Space Complexity: O(1)
314
- */
315
- /**
316
- * Time Complexity: O(n)
317
- * Space Complexity: O(1)
318
- *
319
- * The function `findIterator` searches for an element in a deque and returns an iterator pointing to
320
- * the element if found, otherwise it returns an iterator pointing to the end of the deque.
321
- * @param {E} element - The `element` parameter is the element that you want to find in the deque.
322
- * @returns The method `findIterator(element: E)` returns a `DequeIterator<E>` object.
323
- */
324
- findIterator(element: E): DequeIterator<E>;
325
257
  /**
326
258
  * Time Complexity: O(n)
327
259
  * Space Complexity: O(1)
@@ -7,7 +7,7 @@
7
7
  * @license MIT License
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ObjectDeque = exports.Deque = exports.DequeIterator = void 0;
10
+ exports.ObjectDeque = exports.Deque = void 0;
11
11
  const utils_1 = require("../../utils");
12
12
  /**
13
13
  * Deque can provide random access with O(1) time complexity
@@ -15,78 +15,6 @@ const utils_1 = require("../../utils");
15
15
  * Deque may experience performance jitter, but DoublyLinkedList will not
16
16
  * Deque is implemented using a dynamic array. Inserting or deleting beyond both ends of the array may require moving elements or reallocating space.
17
17
  */
18
- class DequeIterator {
19
- /**
20
- * The constructor initializes the index, iterate direction, and prev/next functions for a
21
- * DequeIterator object.
22
- * @param {number} index - The index parameter represents the current index position of the iterator
23
- * within the deque. It is a number that indicates the position of the element that the iterator is
24
- * currently pointing to.
25
- * @param deque - The `deque` parameter is an instance of the `Deque` class. It represents a
26
- * double-ended queue data structure, which allows elements to be added or removed from both ends.
27
- * @param iterateDirection - The `iterateDirection` parameter is an optional parameter that specifies
28
- * the direction in which the iterator should iterate over the elements of the `deque`. It has a
29
- * default value of `IterateDirection.DEFAULT`.
30
- * @returns The constructor is not returning anything. It is used to initialize the properties of the
31
- * object being created.
32
- */
33
- constructor(index, deque, iterateDirection = 0 /* IterateDirection.DEFAULT */) {
34
- this.index = index;
35
- this.iterateDirection = iterateDirection;
36
- if (this.iterateDirection === 0 /* IterateDirection.DEFAULT */) {
37
- this.prev = function () {
38
- if (this.index === 0) {
39
- (0, utils_1.throwRangeError)();
40
- }
41
- this.index -= 1;
42
- return this;
43
- };
44
- this.next = function () {
45
- if (this.index === this.deque.size) {
46
- (0, utils_1.throwRangeError)();
47
- }
48
- this.index += 1;
49
- return this;
50
- };
51
- }
52
- else {
53
- this.prev = function () {
54
- if (this.index === this.deque.size - 1) {
55
- (0, utils_1.throwRangeError)();
56
- }
57
- this.index += 1;
58
- return this;
59
- };
60
- this.next = function () {
61
- if (this.index === -1) {
62
- (0, utils_1.throwRangeError)();
63
- }
64
- this.index -= 1;
65
- return this;
66
- };
67
- }
68
- this.deque = deque;
69
- }
70
- get current() {
71
- return this.deque.getAt(this.index);
72
- }
73
- set current(newElement) {
74
- this.deque.setAt(this.index, newElement);
75
- }
76
- isAccessible() {
77
- return this.index !== this.deque.size;
78
- }
79
- prev() {
80
- return this;
81
- }
82
- next() {
83
- return this;
84
- }
85
- clone() {
86
- return new DequeIterator(this.index, this.deque, this.iterateDirection);
87
- }
88
- }
89
- exports.DequeIterator = DequeIterator;
90
18
  class Deque {
91
19
  /**
92
20
  * The constructor initializes a data structure with a specified bucket size and populates it with
@@ -220,35 +148,25 @@ class Deque {
220
148
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
221
149
  }
222
150
  /**
223
- * The `begin()` function returns a new iterator for a deque starting from the first element.
224
- * @returns A new instance of the DequeIterator class is being returned.
225
- */
226
- begin() {
227
- return new DequeIterator(0, this);
228
- }
229
- /**
230
- * The `end()` function returns a new `DequeIterator` object with the size and reference to the
231
- * current deque.
232
- * @returns A new instance of the DequeIterator class is being returned.
151
+ * The below function is a generator that yields elements from a collection one by one.
233
152
  */
234
- end() {
235
- return new DequeIterator(this.size, this);
236
- }
237
- /**
238
- * The reverseBegin function returns a new DequeIterator object that starts at the last element of
239
- * the deque and iterates in reverse direction.
240
- * @returns A new instance of the DequeIterator class is being returned.
241
- */
242
- reverseBegin() {
243
- return new DequeIterator(this.size - 1, this, 1 /* IterateDirection.REVERSE */);
153
+ *begin() {
154
+ let index = 0;
155
+ while (index < this.size) {
156
+ yield this.getAt(index);
157
+ index++;
158
+ }
244
159
  }
245
160
  /**
246
- * The reverseEnd() function returns a new DequeIterator object that iterates over the elements of a
247
- * Deque in reverse order.
248
- * @returns A new instance of the DequeIterator class is being returned.
161
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
162
+ * the last element.
249
163
  */
250
- reverseEnd() {
251
- return new DequeIterator(-1, this, 1 /* IterateDirection.REVERSE */);
164
+ *reverseBegin() {
165
+ let index = this.size - 1;
166
+ while (index >= 0) {
167
+ yield this.getAt(index);
168
+ index--;
169
+ }
252
170
  }
253
171
  /**
254
172
  * Time Complexity - Amortized O(1) (possible reallocation)
@@ -399,7 +317,7 @@ class Deque {
399
317
  * @returns The element at the specified position in the data structure is being returned.
400
318
  */
401
319
  getAt(pos) {
402
- utils_1.rangeCheck(pos, 0, this.size - 1);
320
+ (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
403
321
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
404
322
  return this._buckets[bucketIndex][indexInBucket];
405
323
  }
@@ -418,7 +336,7 @@ class Deque {
418
336
  * position in the data structure.
419
337
  */
420
338
  setAt(pos, element) {
421
- utils_1.rangeCheck(pos, 0, this.size - 1);
339
+ (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
422
340
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
423
341
  this._buckets[bucketIndex][indexInBucket] = element;
424
342
  }
@@ -443,7 +361,7 @@ class Deque {
443
361
  */
444
362
  insertAt(pos, element, num = 1) {
445
363
  const length = this.size;
446
- utils_1.rangeCheck(pos, 0, length);
364
+ (0, utils_1.rangeCheck)(pos, 0, length);
447
365
  if (pos === 0) {
448
366
  while (num--)
449
367
  this.unshift(element);
@@ -506,7 +424,7 @@ class Deque {
506
424
  * @returns The size of the data structure after the deletion operation is performed.
507
425
  */
508
426
  deleteAt(pos) {
509
- utils_1.rangeCheck(pos, 0, this.size - 1);
427
+ (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
510
428
  if (pos === 0)
511
429
  this.shift();
512
430
  else if (pos === this.size - 1)
@@ -555,46 +473,6 @@ class Deque {
555
473
  this.cut(index - 1);
556
474
  return this.size;
557
475
  }
558
- /**
559
- * Time Complexity: O(n)
560
- * Space Complexity: O(1)
561
- */
562
- /**
563
- * Time Complexity: O(n)
564
- * Space Complexity: O(1)
565
- *
566
- * The function deletes an element from a deque using an iterator and returns the next iterator.
567
- * @param iter - The parameter `iter` is of type `DequeIterator<E>`. It represents an iterator object
568
- * that is used to iterate over elements in a deque (double-ended queue).
569
- * @returns the updated iterator after deleting an element from the deque.
570
- */
571
- deleteByIterator(iter) {
572
- const index = iter.index;
573
- this.deleteAt(index);
574
- iter = iter.next();
575
- return iter;
576
- }
577
- /**
578
- * Time Complexity: O(n)
579
- * Space Complexity: O(1)
580
- */
581
- /**
582
- * Time Complexity: O(n)
583
- * Space Complexity: O(1)
584
- *
585
- * The function `findIterator` searches for an element in a deque and returns an iterator pointing to
586
- * the element if found, otherwise it returns an iterator pointing to the end of the deque.
587
- * @param {E} element - The `element` parameter is the element that you want to find in the deque.
588
- * @returns The method `findIterator(element: E)` returns a `DequeIterator<E>` object.
589
- */
590
- findIterator(element) {
591
- for (let i = 0; i < this.size; ++i) {
592
- if (this.getAt(i) === element) {
593
- return new DequeIterator(i, this);
594
- }
595
- }
596
- return this.end();
597
- }
598
476
  /**
599
477
  * Time Complexity: O(n)
600
478
  * Space Complexity: O(1)
@@ -4,3 +4,8 @@ export type HashMapLinkedNode<K, V> = {
4
4
  next: HashMapLinkedNode<K, V>;
5
5
  prev: HashMapLinkedNode<K, V>;
6
6
  };
7
+ export type HashMapOptions<K, V> = {
8
+ elements: Iterable<[K, V]>;
9
+ hashFn: (key: K) => string;
10
+ objHashFn: (key: K) => object;
11
+ };
@@ -1,7 +1,3 @@
1
- export * from './coordinate-map';
2
- export * from './coordinate-set';
3
1
  export * from './hash-map';
4
2
  export * from './hash-table';
5
- export * from './tree-map';
6
- export * from './tree-set';
7
3
  export type HashFunction<K> = (key: K) => number;
@@ -14,9 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./coordinate-map"), exports);
18
- __exportStar(require("./coordinate-set"), exports);
19
17
  __exportStar(require("./hash-map"), exports);
20
18
  __exportStar(require("./hash-table"), exports);
21
- __exportStar(require("./tree-map"), exports);
22
- __exportStar(require("./tree-set"), exports);
@@ -20,5 +20,5 @@ export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Paramet
20
20
  export declare const getMSB: (value: number) => number;
21
21
  export declare const rangeCheck: (index: number, min: number, max: number, message?: string) => void;
22
22
  export declare const throwRangeError: (message?: string) => void;
23
- export declare const isObjOrFunc: (input: unknown) => input is Record<string, unknown> | ((...args: any[]) => any);
23
+ export declare const isWeakKey: (input: unknown) => input is object;
24
24
  export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.calcMinUnitsRequired = exports.isObjOrFunc = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
12
+ exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
13
13
  const uuidV4 = function () {
14
14
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
15
15
  const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
@@ -80,10 +80,10 @@ const throwRangeError = (message = 'The value is off-limits.') => {
80
80
  throw new RangeError(message);
81
81
  };
82
82
  exports.throwRangeError = throwRangeError;
83
- const isObjOrFunc = (input) => {
83
+ const isWeakKey = (input) => {
84
84
  const inputType = typeof input;
85
85
  return (inputType === 'object' && input !== null) || inputType === 'function';
86
86
  };
87
- exports.isObjOrFunc = isObjOrFunc;
87
+ exports.isWeakKey = isWeakKey;
88
88
  const calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
89
89
  exports.calcMinUnitsRequired = calcMinUnitsRequired;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directed-graph-typed",
3
- "version": "1.46.2",
3
+ "version": "1.46.5",
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": "^1.46.2"
150
+ "data-structure-typed": "^1.46.5"
151
151
  }
152
152
  }