graph-typed 1.53.5 → 1.53.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.
Files changed (45) hide show
  1. package/README.md +4 -7
  2. package/dist/common/index.d.ts +12 -0
  3. package/dist/common/index.js +23 -0
  4. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +7 -10
  5. package/dist/data-structures/binary-tree/avl-tree.js +2 -2
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +54 -19
  7. package/dist/data-structures/binary-tree/binary-tree.js +100 -66
  8. package/dist/data-structures/binary-tree/bst.d.ts +100 -36
  9. package/dist/data-structures/binary-tree/bst.js +185 -66
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +4 -0
  11. package/dist/data-structures/binary-tree/rb-tree.js +6 -2
  12. package/dist/data-structures/binary-tree/tree-multi-map.js +2 -2
  13. package/dist/data-structures/heap/heap.d.ts +6 -6
  14. package/dist/data-structures/heap/heap.js +6 -6
  15. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -19
  16. package/dist/data-structures/linked-list/doubly-linked-list.js +49 -34
  17. package/dist/data-structures/linked-list/singly-linked-list.d.ts +144 -62
  18. package/dist/data-structures/linked-list/singly-linked-list.js +201 -97
  19. package/dist/data-structures/trie/trie.d.ts +104 -4
  20. package/dist/data-structures/trie/trie.js +116 -12
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +2 -1
  23. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  24. package/dist/types/data-structures/binary-tree/bst.d.ts +3 -2
  25. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  26. package/dist/types/utils/utils.d.ts +10 -6
  27. package/dist/utils/utils.js +4 -2
  28. package/package.json +2 -2
  29. package/src/common/index.ts +19 -0
  30. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +7 -9
  31. package/src/data-structures/binary-tree/avl-tree.ts +3 -2
  32. package/src/data-structures/binary-tree/binary-tree.ts +108 -64
  33. package/src/data-structures/binary-tree/bst.ts +190 -69
  34. package/src/data-structures/binary-tree/rb-tree.ts +6 -2
  35. package/src/data-structures/binary-tree/tree-multi-map.ts +3 -3
  36. package/src/data-structures/heap/heap.ts +39 -39
  37. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -121
  38. package/src/data-structures/linked-list/singly-linked-list.ts +219 -98
  39. package/src/data-structures/trie/trie.ts +116 -11
  40. package/src/index.ts +2 -1
  41. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  42. package/src/types/data-structures/binary-tree/bst.ts +3 -2
  43. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  44. package/src/types/utils/utils.ts +16 -10
  45. package/src/utils/utils.ts +4 -2
@@ -74,13 +74,100 @@ exports.TrieNode = TrieNode;
74
74
  * 9. Spell Check: Checking the spelling of words.
75
75
  * 10. IP Routing: Used in certain types of IP routing algorithms.
76
76
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
77
+ * @example
78
+ * // Autocomplete: Prefix validation and checking
79
+ * const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
80
+ *
81
+ * // Get all completions for a prefix
82
+ * const gmailCompletions = autocomplete.getWords('gmail');
83
+ * console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
84
+ * @example
85
+ * // File System Path Operations
86
+ * const fileSystem = new Trie<string>([
87
+ * '/home/user/documents/file1.txt',
88
+ * '/home/user/documents/file2.txt',
89
+ * '/home/user/pictures/photo.jpg',
90
+ * '/home/user/pictures/vacation/',
91
+ * '/home/user/downloads'
92
+ * ]);
93
+ *
94
+ * // Find common directory prefix
95
+ * console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
96
+ *
97
+ * // List all files in a directory
98
+ * const documentsFiles = fileSystem.getWords('/home/user/documents/');
99
+ * console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
100
+ * @example
101
+ * // Autocomplete: Basic word suggestions
102
+ * // Create a trie for autocomplete
103
+ * const autocomplete = new Trie<string>([
104
+ * 'function',
105
+ * 'functional',
106
+ * 'functions',
107
+ * 'class',
108
+ * 'classes',
109
+ * 'classical',
110
+ * 'closure',
111
+ * 'const',
112
+ * 'constructor'
113
+ * ]);
114
+ *
115
+ * // Test autocomplete with different prefixes
116
+ * console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
117
+ * console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
118
+ * console.log(autocomplete.getWords('con')); // ['constructor', 'const']
119
+ *
120
+ * // Test with non-matching prefix
121
+ * console.log(autocomplete.getWords('xyz')); // []
122
+ * @example
123
+ * // Dictionary: Case-insensitive word lookup
124
+ * // Create a case-insensitive dictionary
125
+ * const dictionary = new Trie<string>([], { caseSensitive: false });
126
+ *
127
+ * // Add words with mixed casing
128
+ * dictionary.add('Hello');
129
+ * dictionary.add('WORLD');
130
+ * dictionary.add('JavaScript');
131
+ *
132
+ * // Test lookups with different casings
133
+ * console.log(dictionary.has('hello')); // true
134
+ * console.log(dictionary.has('HELLO')); // true
135
+ * console.log(dictionary.has('Hello')); // true
136
+ * console.log(dictionary.has('javascript')); // true
137
+ * console.log(dictionary.has('JAVASCRIPT')); // true
138
+ * @example
139
+ * // IP Address Routing Table
140
+ * // Add IP address prefixes and their corresponding routes
141
+ * const routes = {
142
+ * '192.168.1': 'LAN_SUBNET_1',
143
+ * '192.168.2': 'LAN_SUBNET_2',
144
+ * '10.0.0': 'PRIVATE_NETWORK_1',
145
+ * '10.0.1': 'PRIVATE_NETWORK_2'
146
+ * };
147
+ *
148
+ * const ipRoutingTable = new Trie<string>(Object.keys(routes));
149
+ *
150
+ * // Check IP address prefix matching
151
+ * console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
152
+ * console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
153
+ *
154
+ * // Validate IP address belongs to subnet
155
+ * const ip = '192.168.1.100';
156
+ * const subnet = ip.split('.').slice(0, 3).join('.');
157
+ * console.log(ipRoutingTable.hasPrefix(subnet)); // true
77
158
  */
78
159
  class Trie extends base_1.IterableElementBase {
79
160
  /**
80
- * The constructor function for the Trie class.
81
- * @param words: Iterable string Initialize the trie with a set of words
82
- * @param options?: TrieOptions Allow the user to pass in options for the trie
83
- * @return This
161
+ * The constructor initializes a Trie data structure with optional options and words provided as
162
+ * input.
163
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
164
+ * iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
165
+ * a list of words or elements. If no `words` are provided, an empty iterable is used as the default
166
+ * value.
167
+ * @param [options] - The `options` parameter in the constructor is an optional object that can
168
+ * contain configuration options for the Trie data structure. One of the options it can have is
169
+ * `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
170
+ * not. If `caseSensitive` is set to `
84
171
  */
85
172
  constructor(words = [], options) {
86
173
  super(options);
@@ -93,14 +180,7 @@ class Trie extends base_1.IterableElementBase {
93
180
  this._caseSensitive = caseSensitive;
94
181
  }
95
182
  if (words) {
96
- for (const word of words) {
97
- if (this.toElementFn) {
98
- this.add(this.toElementFn(word));
99
- }
100
- else {
101
- this.add(word);
102
- }
103
- }
183
+ this.addMany(words);
104
184
  }
105
185
  }
106
186
  /**
@@ -151,6 +231,30 @@ class Trie extends base_1.IterableElementBase {
151
231
  }
152
232
  return isNewWord;
153
233
  }
234
+ /**
235
+ * Time Complexity: O(n * l)
236
+ * Space Complexity: O(1)
237
+ *
238
+ * The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
239
+ * them using a provided function if available, and adds them to a data structure while returning an
240
+ * array of boolean values indicating success.
241
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
242
+ * an iterable that contains either strings or elements of type `R`.
243
+ * @returns The `addMany` method returns an array of boolean values indicating whether each word in
244
+ * the input iterable was successfully added to the data structure.
245
+ */
246
+ addMany(words = []) {
247
+ const ans = [];
248
+ for (const word of words) {
249
+ if (this.toElementFn) {
250
+ ans.push(this.add(this.toElementFn(word)));
251
+ }
252
+ else {
253
+ ans.push(this.add(word));
254
+ }
255
+ }
256
+ return ans;
257
+ }
154
258
  /**
155
259
  * Time Complexity: O(l), where l is the length of the input word.
156
260
  * Space Complexity: O(1) - Constant space.
package/dist/index.d.ts CHANGED
@@ -8,4 +8,5 @@
8
8
  export * from './data-structures/graph';
9
9
  export * from './types/data-structures/graph';
10
10
  export * from './types/common';
11
- export * from './constants';
11
+ export * from './types/utils';
12
+ export * from './common';
package/dist/index.js CHANGED
@@ -38,4 +38,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  __exportStar(require("./data-structures/graph"), exports);
39
39
  __exportStar(require("./types/data-structures/graph"), exports);
40
40
  __exportStar(require("./types/common"), exports);
41
- __exportStar(require("./constants"), exports);
41
+ __exportStar(require("./types/utils"), exports);
42
+ __exportStar(require("./common"), exports);
@@ -1,6 +1,6 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType, OptValue } from '../../common';
3
- import { DFSOperation } from '../../../constants';
3
+ import { DFSOperation } from '../../../common';
4
4
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
6
  export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
@@ -1,10 +1,11 @@
1
1
  import { BST, BSTNode } from '../../../data-structures';
2
2
  import type { BinaryTreeOptions } from './binary-tree';
3
- import { Comparator } from '../../common';
3
+ import { Comparable } from '../../utils';
4
4
  export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
6
  export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
7
- comparator?: Comparator<K>;
7
+ extractComparable?: (key: K) => Comparable;
8
+ isReverse?: boolean;
8
9
  };
9
10
  export type BSTNOptKey<K> = K | undefined;
10
11
  export type OptNode<NODE> = NODE | undefined;
@@ -3,4 +3,4 @@ import type { BSTOptions } from "./bst";
3
3
  export type RBTNColor = 'RED' | 'BLACK';
4
4
  export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type RedBlackTreeNested<K, V, R, NODE extends RedBlackTreeNode<K, V, NODE>> = RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
- export type RBTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
6
+ export type RBTreeOptions<K, V, R> = Omit<BSTOptions<K, V, R>, 'isReverse'> & {};
@@ -6,13 +6,17 @@ export type TrlFn<A extends any[] = any[], R = any> = (...args: A) => R;
6
6
  export type TrlAsyncFn = (...args: any[]) => any;
7
7
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
8
  export type Any = string | number | bigint | boolean | symbol | undefined | object;
9
+ export type Arithmetic = number | bigint;
9
10
  export type ComparablePrimitive = number | bigint | string | boolean;
10
- export type ComparableObject = {
11
- [key in string]: any;
12
- } & ({
13
- valueOf: () => ComparablePrimitive | ComparableObject;
11
+ export interface BaseComparableObject {
12
+ [key: string]: unknown;
13
+ }
14
+ export interface ValueComparableObject extends BaseComparableObject {
15
+ valueOf: () => ComparablePrimitive | ValueComparableObject;
14
16
  toString?: () => string;
15
- } | {
17
+ }
18
+ export interface StringComparableObject extends BaseComparableObject {
16
19
  toString: () => string;
17
- });
20
+ }
21
+ export type ComparableObject = ValueComparableObject | StringComparableObject;
18
22
  export type Comparable = ComparablePrimitive | Date | ComparableObject;
@@ -213,7 +213,8 @@ exports.roundFixed = roundFixed;
213
213
  function isPrimitiveComparable(value) {
214
214
  const valueType = typeof value;
215
215
  if (valueType === 'number')
216
- return !Number.isNaN(value);
216
+ return true;
217
+ // if (valueType === 'number') return !Number.isNaN(value);
217
218
  return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
218
219
  }
219
220
  /**
@@ -265,7 +266,8 @@ function isComparable(value, isForceObjectComparable = false) {
265
266
  if (typeof value !== 'object')
266
267
  return false;
267
268
  if (value instanceof Date)
268
- return !Number.isNaN(value.getTime());
269
+ return true;
270
+ // if (value instanceof Date) return !Number.isNaN(value.getTime());
269
271
  if (isForceObjectComparable)
270
272
  return true;
271
273
  const comparableValue = tryObjectToPrimitive(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graph-typed",
3
- "version": "1.53.5",
3
+ "version": "1.53.7",
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.53.5"
139
+ "data-structure-typed": "^1.53.7"
140
140
  }
141
141
  }
@@ -0,0 +1,19 @@
1
+ export enum DFSOperation {
2
+ VISIT = 0,
3
+ PROCESS = 1
4
+ }
5
+ export class Range<K> {
6
+ constructor(
7
+ public low: K,
8
+ public high: K,
9
+ public includeLow: boolean = true,
10
+ public includeHigh: boolean = true
11
+ ) {}
12
+
13
+ // Determine whether a key is within the range
14
+ isInRange(key: K, comparator: (a: K, b: K) => number): boolean {
15
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
16
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
17
+ return lowCheck && highCheck;
18
+ }
19
+ }
@@ -143,8 +143,9 @@ export class AVLTreeMultiMap<
143
143
  return new AVLTreeMultiMap<K, V, R, NODE, TREE>([], {
144
144
  iterationType: this.iterationType,
145
145
  isMapMode: this._isMapMode,
146
- comparator: this._comparator,
146
+ extractComparable: this._extractComparable,
147
147
  toEntryFn: this._toEntryFn,
148
+ isReverse: this._isReverse,
148
149
  ...options
149
150
  }) as TREE;
150
151
  }
@@ -187,17 +188,14 @@ export class AVLTreeMultiMap<
187
188
  return [this.createNode(key, finalValue, count), finalValue];
188
189
  }
189
190
 
190
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
191
-
192
191
  if (this.isRaw(keyNodeEntryOrRaw)) {
193
- if (this._toEntryFn) {
194
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
195
- const finalValue = value ?? entryValue;
196
- if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
197
- }
198
- return [undefined, undefined];
192
+ const [key, entryValue] = this._toEntryFn!(keyNodeEntryOrRaw);
193
+ const finalValue = value ?? entryValue;
194
+ if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
199
195
  }
200
196
 
197
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
198
+
201
199
  return [undefined, undefined];
202
200
  }
203
201
 
@@ -113,8 +113,9 @@ export class AVLTree<
113
113
  return new AVLTree<K, V, R, NODE, TREE>([], {
114
114
  iterationType: this.iterationType,
115
115
  isMapMode: this._isMapMode,
116
- comparator: this._comparator,
116
+ extractComparable: this._extractComparable,
117
117
  toEntryFn: this._toEntryFn,
118
+ isReverse: this._isReverse,
118
119
  ...options
119
120
  }) as TREE;
120
121
  }
@@ -434,7 +435,7 @@ export class AVLTree<
434
435
  */
435
436
  protected _balancePath(node: BTNRep<K, V, NODE> | R): void {
436
437
  node = this.ensureNode(node);
437
- const path = this.getPathToRoot(node => node, node, false); // first O(log n) + O(log n)
438
+ const path = this.getPathToRoot(node, node => node, false); // first O(log n) + O(log n)
438
439
  for (let i = 0; i < path.length; i++) {
439
440
  // second O(log n)
440
441
  const A = path[i];