max-heap-typed 1.19.3

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.
@@ -0,0 +1,449 @@
1
+ /** @type {import('dependency-cruiser').IConfiguration} */
2
+ module.exports = {
3
+ forbidden: [
4
+ /* rules from the 'recommended' preset: */
5
+ {
6
+ name: 'no-circular',
7
+ severity: 'warn',
8
+ comment:
9
+ 'This dependency is part of a circular relationship. You might want to revise ' +
10
+ 'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ',
11
+ from: {},
12
+ to: {
13
+ circular: true
14
+ }
15
+ },
16
+ {
17
+ name: 'no-orphans',
18
+ comment:
19
+ "This is an orphan module - it's likely not used (anymore?). Either use it or " +
20
+ "remove it. If it's logical this module is an orphan (i.e. it's a config file), " +
21
+ "add an exception for it in your dependency-cruiser configuration. By default " +
22
+ "this rule does not scrutinize dot-files (e.g. .eslintrc.js), TypeScript declaration " +
23
+ "files (.d.ts), tsconfig.json and some of the babel and webpack configs.",
24
+ severity: 'warn',
25
+ from: {
26
+ orphan: true,
27
+ pathNot: [
28
+ '(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$', // dot files
29
+ '\\.d\\.ts$', // TypeScript declaration files
30
+ '(^|/)tsconfig\\.json$', // TypeScript config
31
+ '(^|/)(babel|webpack)\\.config\\.(js|cjs|mjs|ts|json)$' // other configs
32
+ ]
33
+ },
34
+ to: {},
35
+ },
36
+ {
37
+ name: 'no-deprecated-core',
38
+ comment:
39
+ 'A module depends on a node core module that has been deprecated. Find an alternative - these are ' +
40
+ "bound to exist - node doesn't deprecate lightly.",
41
+ severity: 'warn',
42
+ from: {},
43
+ to: {
44
+ dependencyTypes: [
45
+ 'core'
46
+ ],
47
+ path: [
48
+ '^(v8\/tools\/codemap)$',
49
+ '^(v8\/tools\/consarray)$',
50
+ '^(v8\/tools\/csvparser)$',
51
+ '^(v8\/tools\/logreader)$',
52
+ '^(v8\/tools\/profile_view)$',
53
+ '^(v8\/tools\/profile)$',
54
+ '^(v8\/tools\/SourceMap)$',
55
+ '^(v8\/tools\/splaytree)$',
56
+ '^(v8\/tools\/tickprocessor-driver)$',
57
+ '^(v8\/tools\/tickprocessor)$',
58
+ '^(node-inspect\/lib\/_inspect)$',
59
+ '^(node-inspect\/lib\/internal\/inspect_client)$',
60
+ '^(node-inspect\/lib\/internal\/inspect_repl)$',
61
+ '^(async_hooks)$',
62
+ '^(punycode)$',
63
+ '^(domain)$',
64
+ '^(constants)$',
65
+ '^(sys)$',
66
+ '^(_linklist)$',
67
+ '^(_stream_wrap)$'
68
+ ],
69
+ }
70
+ },
71
+ {
72
+ name: 'not-to-deprecated',
73
+ comment:
74
+ 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' +
75
+ 'version of that module, or find an alternative. Deprecated modules are a security risk.',
76
+ severity: 'warn',
77
+ from: {},
78
+ to: {
79
+ dependencyTypes: [
80
+ 'deprecated'
81
+ ]
82
+ }
83
+ },
84
+ {
85
+ name: 'no-non-package-json',
86
+ severity: 'error',
87
+ comment:
88
+ "This module depends on an npm package that isn't in the 'dependencies' section of your package.json. " +
89
+ "That's problematic as the package either (1) won't be available on live (2 - worse) will be " +
90
+ "available on live with an non-guaranteed version. Fix it by adding the package to the dependencies " +
91
+ "in your package.json.",
92
+ from: {},
93
+ to: {
94
+ dependencyTypes: [
95
+ 'npm-no-pkg',
96
+ 'npm-unknown'
97
+ ]
98
+ }
99
+ },
100
+ {
101
+ name: 'not-to-unresolvable',
102
+ comment:
103
+ "This module depends on a module that cannot be found ('resolved to disk'). If it's an npm " +
104
+ 'module: add it to your package.json. In all other cases you likely already know what to do.',
105
+ severity: 'error',
106
+ from: {},
107
+ to: {
108
+ couldNotResolve: true
109
+ }
110
+ },
111
+ {
112
+ name: 'no-duplicate-dep-types',
113
+ comment:
114
+ "Likely this module depends on an external ('npm') package that occurs more than once " +
115
+ "in your package.json i.e. bot as a devDependencies and in dependencies. This will cause " +
116
+ "maintenance problems later on.",
117
+ severity: 'warn',
118
+ from: {},
119
+ to: {
120
+ moreThanOneDependencyType: true,
121
+ // as it's pretty common to have a type import be a type only import
122
+ // _and_ (e.g.) a devDependency - don't consider type-only dependency
123
+ // types for this rule
124
+ dependencyTypesNot: ["type-only"]
125
+ }
126
+ },
127
+
128
+ /* rules you might want to tweak for your specific situation: */
129
+ {
130
+ name: 'not-to-spec',
131
+ comment:
132
+ 'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +
133
+ "If there's something in a spec that's of use to other modules, it doesn't have that single " +
134
+ 'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
135
+ severity: 'error',
136
+ from: {},
137
+ to: {
138
+ path: '\\.(spec|test)\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
139
+ }
140
+ },
141
+ {
142
+ name: 'not-to-dev-dep',
143
+ severity: 'error',
144
+ comment:
145
+ "This module depends on an npm package from the 'devDependencies' section of your " +
146
+ 'package.json. It looks like something that ships to production, though. To prevent problems ' +
147
+ "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
148
+ 'section of your package.json. If this module is development only - add it to the ' +
149
+ 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
150
+ from: {
151
+ path: '^(src)',
152
+ pathNot: '\\.(spec|test)\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\.md)$'
153
+ },
154
+ to: {
155
+ dependencyTypes: [
156
+ 'npm-dev'
157
+ ]
158
+ }
159
+ },
160
+ {
161
+ name: 'optional-deps-used',
162
+ severity: 'info',
163
+ comment:
164
+ "This module depends on an npm package that is declared as an optional dependency " +
165
+ "in your package.json. As this makes sense in limited situations only, it's flagged here. " +
166
+ "If you're using an optional dependency here by design - add an exception to your" +
167
+ "dependency-cruiser configuration.",
168
+ from: {},
169
+ to: {
170
+ dependencyTypes: [
171
+ 'npm-optional'
172
+ ]
173
+ }
174
+ },
175
+ {
176
+ name: 'peer-deps-used',
177
+ comment:
178
+ "This module depends on an npm package that is declared as a peer dependency " +
179
+ "in your package.json. This makes sense if your package is e.g. a plugin, but in " +
180
+ "other cases - maybe not so much. If the use of a peer dependency is intentional " +
181
+ "add an exception to your dependency-cruiser configuration.",
182
+ severity: 'warn',
183
+ from: {},
184
+ to: {
185
+ dependencyTypes: [
186
+ 'npm-peer'
187
+ ]
188
+ }
189
+ }
190
+ ],
191
+ options: {
192
+
193
+ /* conditions specifying which files not to follow further when encountered:
194
+ - path: a regular expression to match
195
+ - dependencyTypes: see https://github.com/sverweij/dependency-cruiser/blob/main/doc/rules-reference.md#dependencytypes-and-dependencytypesnot
196
+ for a complete list
197
+ */
198
+ doNotFollow: {
199
+ path: ['node_modules', 'src/libs']
200
+ },
201
+
202
+ /* conditions specifying which dependencies to exclude
203
+ - path: a regular expression to match
204
+ - dynamic: a boolean indicating whether to ignore dynamic (true) or static (false) dependencies.
205
+ leave out if you want to exclude neither (recommended!)
206
+ */
207
+ // exclude : {
208
+ // path: '',
209
+ // dynamic: true
210
+ // },
211
+
212
+ /* pattern specifying which files to include (regular expression)
213
+ dependency-cruiser will skip everything not matching this pattern
214
+ */
215
+ // includeOnly : '',
216
+
217
+ /* dependency-cruiser will include modules matching against the focus
218
+ regular expression in its output, as well as their neighbours (direct
219
+ dependencies and dependents)
220
+ */
221
+ // focus : '',
222
+
223
+ /* list of module systems to cruise */
224
+ // moduleSystems: ['amd', 'cjs', 'es6', 'tsd'],
225
+
226
+ /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/develop/'
227
+ to open it on your online repo or `vscode://file/${process.cwd()}/` to
228
+ open it in visual studio code),
229
+ */
230
+ // prefix: '',
231
+
232
+ /* false (the default): ignore dependencies that only exist before typescript-to-javascript compilation
233
+ true: also detect dependencies that only exist before typescript-to-javascript compilation
234
+ "specify": for each dependency identify whether it only exists before compilation or also after
235
+ */
236
+ tsPreCompilationDeps: true,
237
+
238
+ /*
239
+ list of extensions to scan that aren't javascript or compile-to-javascript.
240
+ Empty by default. Only put extensions in here that you want to take into
241
+ account that are _not_ parsable.
242
+ */
243
+ // extraExtensionsToScan: [".json", ".jpg", ".png", ".svg", ".webp"],
244
+
245
+ /* if true combines the package.jsons found from the module up to the base
246
+ folder the cruise is initiated from. Useful for how (some) mono-repos
247
+ manage dependencies & dependency definitions.
248
+ */
249
+ // combinedDependencies: false,
250
+
251
+ /* if true leave symlinks untouched, otherwise use the realpath */
252
+ // preserveSymlinks: false,
253
+
254
+ /* TypeScript project file ('tsconfig.json') to use for
255
+ (1) compilation and
256
+ (2) resolution (e.g. with the paths property)
257
+
258
+ The (optional) fileName attribute specifies which file to take (relative to
259
+ dependency-cruiser's current working directory). When not provided
260
+ defaults to './tsconfig.json'.
261
+ */
262
+ tsConfig: {
263
+ fileName: 'tsconfig.json'
264
+ },
265
+
266
+ /* Webpack configuration to use to get resolve options from.
267
+
268
+ The (optional) fileName attribute specifies which file to take (relative
269
+ to dependency-cruiser's current working directory. When not provided defaults
270
+ to './webpack.conf.js'.
271
+
272
+ The (optional) `env` and `arguments` attributes contain the parameters to be passed if
273
+ your webpack config is a function and takes them (see webpack documentation
274
+ for details)
275
+ */
276
+ // webpackConfig: {
277
+ // fileName: './webpack.config.js',
278
+ // env: {},
279
+ // arguments: {},
280
+ // },
281
+
282
+ /* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use
283
+ for compilation (and whatever other naughty things babel plugins do to
284
+ source code). This feature is well tested and usable, but might change
285
+ behavior a bit over time (e.g. more precise results for used module
286
+ systems) without dependency-cruiser getting a major version bump.
287
+ */
288
+ // babelConfig: {
289
+ // fileName: './.babelrc'
290
+ // },
291
+
292
+ /* List of strings you have in use in addition to cjs/ es6 requires
293
+ & imports to declare module dependencies. Use this e.g. if you've
294
+ re-declared require, use a require-wrapper or use window.require as
295
+ a hack.
296
+ */
297
+ // exoticRequireStrings: [],
298
+ /* options to pass on to enhanced-resolve, the package dependency-cruiser
299
+ uses to resolve module references to disk. You can set most of these
300
+ options in a webpack.conf.js - this section is here for those
301
+ projects that don't have a separate webpack config file.
302
+
303
+ Note: settings in webpack.conf.js override the ones specified here.
304
+ */
305
+ enhancedResolveOptions: {
306
+ /* List of strings to consider as 'exports' fields in package.json. Use
307
+ ['exports'] when you use packages that use such a field and your environment
308
+ supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack).
309
+
310
+ If you have an `exportsFields` attribute in your webpack config, that one
311
+ will have precedence over the one specified here.
312
+ */
313
+ exportsFields: ["exports"],
314
+ /* List of conditions to check for in the exports field. e.g. use ['imports']
315
+ if you're only interested in exposed es6 modules, ['require'] for commonjs,
316
+ or all conditions at once `(['import', 'require', 'node', 'default']`)
317
+ if anything goes for you. Only works when the 'exportsFields' array is
318
+ non-empty.
319
+
320
+ If you have a 'conditionNames' attribute in your webpack config, that one will
321
+ have precedence over the one specified here.
322
+ */
323
+ conditionNames: ["import", "require", "node", "default"],
324
+ /*
325
+ The extensions, by default are the same as the ones dependency-cruiser
326
+ can access (run `npx depcruise --info` to see which ones that are in
327
+ _your_ environment. If that list is larger than what you need (e.g.
328
+ it contains .js, .jsx, .ts, .tsx, .cts, .mts - but you don't use
329
+ TypeScript you can pass just the extensions you actually use (e.g.
330
+ [".js", ".jsx"]). This can speed up the most expensive step in
331
+ dependency cruising (module resolution) quite a bit.
332
+ */
333
+ // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
334
+ /*
335
+ If your TypeScript project makes use of types specified in 'types'
336
+ fields in package.jsons of external dependencies, specify "types"
337
+ in addition to "main" in here, so enhanced-resolve (the resolver
338
+ dependency-cruiser uses) knows to also look there. You can also do
339
+ this if you're not sure, but still use TypeScript. In a future version
340
+ of dependency-cruiser this will likely become the default.
341
+ */
342
+ mainFields: ["main", "types"],
343
+ },
344
+ reporterOptions: {
345
+ dot: {
346
+ /* pattern of modules that can be consolidated in the detailed
347
+ graphical dependency graph. The default pattern in this configuration
348
+ collapses everything in node_modules to one folder deep so you see
349
+ the external modules, but not the innards your app depends upon.
350
+ */
351
+ collapsePattern: 'node_modules/(@[^/]+/[^/]+|[^/]+)',
352
+
353
+ /* Options to tweak the appearance of your graph.See
354
+ https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions
355
+ for details and some examples. If you don't specify a theme
356
+ don't worry - dependency-cruiser will fall back to the default one.
357
+ */
358
+ // theme: {
359
+ // graph: {
360
+ // /* use splines: "ortho" for straight lines. Be aware though
361
+ // graphviz might take a long time calculating ortho(gonal)
362
+ // routings.
363
+ // */
364
+ // splines: "true"
365
+ // },
366
+ // modules: [
367
+ // {
368
+ // criteria: { matchesFocus: true },
369
+ // attributes: {
370
+ // fillcolor: "lime",
371
+ // penwidth: 2,
372
+ // },
373
+ // },
374
+ // {
375
+ // criteria: { matchesFocus: false },
376
+ // attributes: {
377
+ // fillcolor: "lightgrey",
378
+ // },
379
+ // },
380
+ // {
381
+ // criteria: { matchesReaches: true },
382
+ // attributes: {
383
+ // fillcolor: "lime",
384
+ // penwidth: 2,
385
+ // },
386
+ // },
387
+ // {
388
+ // criteria: { matchesReaches: false },
389
+ // attributes: {
390
+ // fillcolor: "lightgrey",
391
+ // },
392
+ // },
393
+ // {
394
+ // criteria: { source: "^src/model" },
395
+ // attributes: { fillcolor: "#ccccff" }
396
+ // },
397
+ // {
398
+ // criteria: { source: "^src/view" },
399
+ // attributes: { fillcolor: "#ccffcc" }
400
+ // },
401
+ // ],
402
+ // dependencies: [
403
+ // {
404
+ // criteria: { "rules[0].severity": "error" },
405
+ // attributes: { fontcolor: "red", color: "red" }
406
+ // },
407
+ // {
408
+ // criteria: { "rules[0].severity": "warn" },
409
+ // attributes: { fontcolor: "orange", color: "orange" }
410
+ // },
411
+ // {
412
+ // criteria: { "rules[0].severity": "info" },
413
+ // attributes: { fontcolor: "blue", color: "blue" }
414
+ // },
415
+ // {
416
+ // criteria: { resolved: "^src/model" },
417
+ // attributes: { color: "#0000ff77" }
418
+ // },
419
+ // {
420
+ // criteria: { resolved: "^src/view" },
421
+ // attributes: { color: "#00770077" }
422
+ // }
423
+ // ]
424
+ // }
425
+ },
426
+ archi: {
427
+ /* pattern of modules that can be consolidated in the high level
428
+ graphical dependency graph. If you use the high level graphical
429
+ dependency graph reporter (`archi`) you probably want to tweak
430
+ this collapsePattern to your situation.
431
+ */
432
+ collapsePattern: '^(packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+|node_modules/(@[^/]+/[^/]+|[^/]+)',
433
+
434
+ /* Options to tweak the appearance of your graph.See
435
+ https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions
436
+ for details and some examples. If you don't specify a theme
437
+ for 'archi' dependency-cruiser will use the one specified in the
438
+ dot section (see above), if any, and otherwise use the default one.
439
+ */
440
+ // theme: {
441
+ // },
442
+ },
443
+ "text": {
444
+ "highlightFocused": true
445
+ },
446
+ }
447
+ }
448
+ };
449
+ // generated: dependency-cruiser@13.1.1 on 2023-08-02T09:11:55.676Z
package/README.md ADDED
@@ -0,0 +1,700 @@
1
+ # What
2
+
3
+ ## Brief
4
+ Javascript & TypeScript Data Structure Library.
5
+
6
+ Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
7
+
8
+ ## Algorithms list only a few out, you can discover more in API docs
9
+
10
+ DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
11
+
12
+ ## Code design
13
+ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
14
+
15
+ # How
16
+
17
+ ## install
18
+ ### yarn
19
+
20
+ ```bash
21
+ yarn add data-structure-typed
22
+ ```
23
+
24
+ ### npm
25
+
26
+ ```bash
27
+ npm install data-structure-typed
28
+ ```
29
+
30
+ ### Binary Search Tree (BST) snippet
31
+
32
+ #### TS
33
+ ```typescript
34
+ import {BST, BSTNode} from 'data-structure-typed';
35
+
36
+ const bst = new BST();
37
+ bst.add(11);
38
+ bst.add(3);
39
+ bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
40
+ bst.size === 16; // true
41
+ bst.has(6); // true
42
+ const node6 = bst.get(6);
43
+ bst.getHeight(6) === 2; // true
44
+ bst.getHeight() === 5; // true
45
+ bst.getDepth(6) === 3; // true
46
+ const leftMost = bst.getLeftMost();
47
+ leftMost?.id === 1; // true
48
+ expect(leftMost?.id).toBe(1);
49
+ bst.remove(6);
50
+ bst.get(6); // null
51
+ bst.isAVLBalanced(); // true or false
52
+ const bfsIDs = bst.BFS();
53
+ bfsIDs[0] === 11; // true
54
+ expect(bfsIDs[0]).toBe(11);
55
+
56
+ const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
57
+ objBST.add(11, {id: 11, keyA: 11});
58
+ objBST.add(3, {id: 3, keyA: 3});
59
+
60
+ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
61
+ {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
62
+ {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
63
+ {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
64
+ {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
65
+
66
+ objBST.remove(11);
67
+
68
+
69
+ const avlTree = new AVLTree();
70
+ avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
71
+ avlTree.isAVLBalanced(); // true
72
+ avlTree.remove(10);
73
+ avlTree.isAVLBalanced(); // true
74
+
75
+ ```
76
+ #### JS
77
+ ```javascript
78
+ const {BST, BSTNode} = require('data-structure-typed');
79
+
80
+ const bst = new BST();
81
+ bst.add(11);
82
+ bst.add(3);
83
+ bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
84
+ bst.size === 16; // true
85
+ bst.has(6); // true
86
+ const node6 = bst.get(6);
87
+ bst.getHeight(6) === 2; // true
88
+ bst.getHeight() === 5; // true
89
+ bst.getDepth(6) === 3; // true
90
+ const leftMost = bst.getLeftMost();
91
+ leftMost?.id === 1; // true
92
+ expect(leftMost?.id).toBe(1);
93
+ bst.remove(6);
94
+ bst.get(6); // null
95
+ bst.isAVLBalanced(); // true or false
96
+ const bfsIDs = bst.BFS();
97
+ bfsIDs[0] === 11; // true
98
+ expect(bfsIDs[0]).toBe(11);
99
+
100
+ const objBST = new BST();
101
+ objBST.add(11, {id: 11, keyA: 11});
102
+ objBST.add(3, {id: 3, keyA: 3});
103
+
104
+ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
105
+ {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
106
+ {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
107
+ {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
108
+ {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
109
+
110
+ objBST.remove(11);
111
+
112
+
113
+ const avlTree = new AVLTree();
114
+ avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
115
+ avlTree.isAVLBalanced(); // true
116
+ avlTree.remove(10);
117
+ avlTree.isAVLBalanced(); // true
118
+
119
+ ```
120
+
121
+ ### Directed Graph simple snippet
122
+
123
+ #### TS or JS
124
+ ```typescript
125
+ import {DirectedGraph} from 'data-structure-typed';
126
+
127
+ const graph = new DirectedGraph();
128
+
129
+ graph.addVertex('A');
130
+ graph.addVertex('B');
131
+
132
+ graph.hasVertex('A'); // true
133
+ graph.hasVertex('B'); // true
134
+ graph.hasVertex('C'); // false
135
+
136
+ graph.addEdge('A', 'B');
137
+ graph.hasEdge('A', 'B'); // true
138
+ graph.hasEdge('B', 'A'); // false
139
+
140
+ graph.removeEdgeSrcToDest('A', 'B');
141
+ graph.hasEdge('A', 'B'); // false
142
+
143
+ graph.addVertex('C');
144
+
145
+ graph.addEdge('A', 'B');
146
+ graph.addEdge('B', 'C');
147
+
148
+ const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
149
+ ```
150
+
151
+ ### Undirected Graph snippet
152
+
153
+ #### TS or JS
154
+ ```typescript
155
+ import {UndirectedGraph} from 'data-structure-typed';
156
+
157
+ const graph = new UndirectedGraph();
158
+ graph.addVertex('A');
159
+ graph.addVertex('B');
160
+ graph.addVertex('C');
161
+ graph.addVertex('D');
162
+ graph.removeVertex('C');
163
+ graph.addEdge('A', 'B');
164
+ graph.addEdge('B', 'D');
165
+
166
+ const dijkstraResult = graph.dijkstra('A');
167
+ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
168
+ ```
169
+
170
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/dfs-pre-order.webp)
171
+
172
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/test-graphs.webp)
173
+
174
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/cut-off-trees-for-golf.webp)
175
+
176
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/parenthesis-check.webp)
177
+
178
+
179
+ ## API docs & Examples
180
+
181
+ [API Docs](https://data-structure-typed-docs.vercel.app)
182
+
183
+ [Live Examples](https://data-structure-typed-examples.vercel.app)
184
+
185
+ <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
186
+
187
+ [//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)
188
+
189
+ <a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
190
+
191
+ ## Data Structures
192
+
193
+ <table>
194
+ <thead>
195
+ <tr>
196
+ <th>Data Structure</th>
197
+ <th>Unit Test</th>
198
+ <th>Performance Test</th>
199
+ <th>API Documentation</th>
200
+ <th>Implemented</th>
201
+ </tr>
202
+ </thead>
203
+ <tbody>
204
+ <tr>
205
+ <td>Binary Tree</td>
206
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
207
+ </img></td>
208
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
209
+ </img></td>
210
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
211
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
212
+ </tr>
213
+ <tr>
214
+ <td>Binary Search Tree (BST)</td>
215
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
216
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
217
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></td>
218
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
219
+ </tr>
220
+ <tr>
221
+ <td>AVL Tree</td>
222
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
223
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
224
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></td>
225
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
226
+ </tr>
227
+ <tr>
228
+ <td>Tree Multiset</td>
229
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
230
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
231
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiset.html"><span>TreeMultiset</span></a></td>
232
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
233
+ </tr>
234
+ <tr>
235
+ <td>Segment Tree</td>
236
+ <td></td>
237
+ <td></td>
238
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>SegmentTree</span></a></td>
239
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
240
+ </tr>
241
+ <tr>
242
+ <td>Binary Indexed Tree</td>
243
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
244
+ <td></td>
245
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>BinaryIndexedTree</span></a></td>
246
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
247
+ </tr>
248
+ <tr>
249
+ <td>Graph</td>
250
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
251
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
252
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>AbstractGraph</span></a></td>
253
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
254
+ </tr>
255
+ <tr>
256
+ <td>Directed Graph</td>
257
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
258
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
259
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>DirectedGraph</span></a></td>
260
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
261
+ </tr>
262
+ <tr>
263
+ <td>Undirected Graph</td>
264
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
265
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
266
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>UndirectedGraph</span></a></td>
267
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
268
+ </tr>
269
+ <tr>
270
+ <td>Linked List</td>
271
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
272
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
273
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
274
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
275
+ </tr>
276
+ <tr>
277
+ <td>Singly Linked List</td>
278
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
279
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
280
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
281
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
282
+ </tr>
283
+ <tr>
284
+ <td>Doubly Linked List</td>
285
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
286
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
287
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>DoublyLinkedList</span></a></td>
288
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
289
+ </tr>
290
+ <tr>
291
+ <td>Queue</td>
292
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
293
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
294
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></td>
295
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
296
+ </tr>
297
+ <tr>
298
+ <td>Object Deque</td>
299
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
300
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
301
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>ObjectDeque</span></a></td>
302
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
303
+ </tr>
304
+ <tr>
305
+ <td>Array Deque</td>
306
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
307
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
308
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>ArrayDeque</span></a></td>
309
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
310
+ </tr>
311
+ <tr>
312
+ <td>Stack</td>
313
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
314
+ <td></td>
315
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></td>
316
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
317
+ </tr>
318
+
319
+ [//]: # (<tr>)
320
+
321
+ [//]: # (<td>Hash</td>)
322
+
323
+ [//]: # (<td></td>)
324
+
325
+ [//]: # (<td></td>)
326
+
327
+ [//]: # (<td><a href="https://data-structure-typed-docs.vercel.app/classes/HashTable.html"><span>HashTable</span></a></td>)
328
+
329
+ [//]: # (<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>)
330
+
331
+ [//]: # (</tr>)
332
+ <tr>
333
+ <td>Coordinate Set</td>
334
+ <td></td>
335
+ <td></td>
336
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>CoordinateSet</span></a></td>
337
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
338
+ </tr>
339
+ <tr>
340
+ <td>Coordinate Map</td>
341
+ <td></td>
342
+ <td></td>
343
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>CoordinateMap</span></a></td>
344
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
345
+ </tr>
346
+ <tr>
347
+ <td>Heap</td>
348
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
349
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
350
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></td>
351
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
352
+ </tr>
353
+ <tr>
354
+ <td>Priority Queue</td>
355
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
356
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
357
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>PriorityQueue</span></a></td>
358
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
359
+ </tr>
360
+ <tr>
361
+ <td>Max Priority Queue</td>
362
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
363
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
364
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>MaxPriorityQueue</span></a></td>
365
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
366
+ </tr>
367
+ <tr>
368
+ <td>Min Priority Queue</td>
369
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
370
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
371
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>MinPriorityQueue</span></a></td>
372
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
373
+ </tr>
374
+ <tr>
375
+ <td>Trie</td>
376
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
377
+ <td></td>
378
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></td>
379
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
380
+ </tr>
381
+ </tbody>
382
+ </table>
383
+
384
+
385
+ # Why
386
+
387
+ ## Complexities
388
+
389
+ ### performance of Big O
390
+
391
+ <table>
392
+ <thead>
393
+ <tr>
394
+ <th>Big O Notation</th>
395
+ <th>Type</th>
396
+ <th>Computations for 10 elements</th>
397
+ <th>Computations for 100 elements</th>
398
+ <th>Computations for 1000 elements</th>
399
+ </tr>
400
+ </thead>
401
+ <tbody>
402
+ <tr>
403
+ <td><strong>O(1)</strong></td>
404
+ <td>Constant</td>
405
+ <td>1</td>
406
+ <td>1</td>
407
+ <td>1</td>
408
+ </tr>
409
+ <tr>
410
+ <td><strong>O(log N)</strong></td>
411
+ <td>Logarithmic</td>
412
+ <td>3</td>
413
+ <td>6</td>
414
+ <td>9</td>
415
+ </tr>
416
+ <tr>
417
+ <td><strong>O(N)</strong></td>
418
+ <td>Linear</td>
419
+ <td>10</td>
420
+ <td>100</td>
421
+ <td>1000</td>
422
+ </tr>
423
+ <tr>
424
+ <td><strong>O(N log N)</strong></td>
425
+ <td>n log(n)</td>
426
+ <td>30</td>
427
+ <td>600</td>
428
+ <td>9000</td>
429
+ </tr>
430
+ <tr>
431
+ <td><strong>O(N^2)</strong></td>
432
+ <td>Quadratic</td>
433
+ <td>100</td>
434
+ <td>10000</td>
435
+ <td>1000000</td>
436
+ </tr>
437
+ <tr>
438
+ <td><strong>O(2^N)</strong></td>
439
+ <td>Exponential</td>
440
+ <td>1024</td>
441
+ <td>1.26e+29</td>
442
+ <td>1.07e+301</td>
443
+ </tr>
444
+ <tr>
445
+ <td><strong>O(N!)</strong></td>
446
+ <td>Factorial</td>
447
+ <td>3628800</td>
448
+ <td>9.3e+157</td>
449
+ <td>4.02e+2567</td>
450
+ </tr>
451
+ </tbody>
452
+ </table>
453
+
454
+ ### Data Structure Complexity
455
+
456
+ <table>
457
+ <thead>
458
+ <tr>
459
+ <th>Data Structure</th>
460
+ <th>Access</th>
461
+ <th>Search</th>
462
+ <th>Insertion</th>
463
+ <th>Deletion</th>
464
+ <th>Comments</th>
465
+ </tr>
466
+ </thead>
467
+ <tbody>
468
+ <tr>
469
+ <td><strong>Array</strong></td>
470
+ <td>1</td>
471
+ <td>n</td>
472
+ <td>n</td>
473
+ <td>n</td>
474
+ <td></td>
475
+ </tr>
476
+ <tr>
477
+ <td><strong>Stack</strong></td>
478
+ <td>n</td>
479
+ <td>n</td>
480
+ <td>1</td>
481
+ <td>1</td>
482
+ <td></td>
483
+ </tr>
484
+ <tr>
485
+ <td><strong>Queue</strong></td>
486
+ <td>n</td>
487
+ <td>n</td>
488
+ <td>1</td>
489
+ <td>1</td>
490
+ <td></td>
491
+ </tr>
492
+ <tr>
493
+ <td><strong>Linked List</strong></td>
494
+ <td>n</td>
495
+ <td>n</td>
496
+ <td>1</td>
497
+ <td>n</td>
498
+ <td></td>
499
+ </tr>
500
+ <tr>
501
+ <td><strong>Hash Table</strong></td>
502
+ <td>-</td>
503
+ <td>n</td>
504
+ <td>n</td>
505
+ <td>n</td>
506
+ <td>In case of perfect hash function costs would be O(1)</td>
507
+ </tr>
508
+ <tr>
509
+ <td><strong>Binary Search Tree</strong></td>
510
+ <td>n</td>
511
+ <td>n</td>
512
+ <td>n</td>
513
+ <td>n</td>
514
+ <td>In case of balanced tree costs would be O(log(n))</td>
515
+ </tr>
516
+ <tr>
517
+ <td><strong>B-Tree</strong></td>
518
+ <td>log(n)</td>
519
+ <td>log(n)</td>
520
+ <td>log(n)</td>
521
+ <td>log(n)</td>
522
+ <td></td>
523
+ </tr>
524
+ <tr>
525
+ <td><strong>Red-Black Tree</strong></td>
526
+ <td>log(n)</td>
527
+ <td>log(n)</td>
528
+ <td>log(n)</td>
529
+ <td>log(n)</td>
530
+ <td></td>
531
+ </tr>
532
+ <tr>
533
+ <td><strong>AVL Tree</strong></td>
534
+ <td>log(n)</td>
535
+ <td>log(n)</td>
536
+ <td>log(n)</td>
537
+ <td>log(n)</td>
538
+ <td></td>
539
+ </tr>
540
+ <tr>
541
+ <td><strong>Bloom Filter</strong></td>
542
+ <td>-</td>
543
+ <td>1</td>
544
+ <td>1</td>
545
+ <td>-</td>
546
+ <td>False positives are possible while searching</td>
547
+ </tr>
548
+ </tbody>
549
+ </table>
550
+
551
+ ### Sorting Complexity
552
+
553
+ <table>
554
+ <thead>
555
+ <tr>
556
+ <th>Name</th>
557
+ <th>Best</th>
558
+ <th>Average</th>
559
+ <th>Worst</th>
560
+ <th>Memory</th>
561
+ <th>Stable</th>
562
+ <th>Comments</th>
563
+ </tr>
564
+ </thead>
565
+ <tbody>
566
+ <tr>
567
+ <td><strong>Bubble sort</strong></td>
568
+ <td>n</td>
569
+ <td>n<sup>2</sup></td>
570
+ <td>n<sup>2</sup></td>
571
+ <td>1</td>
572
+ <td>Yes</td>
573
+ <td></td>
574
+ </tr>
575
+ <tr>
576
+ <td><strong>Insertion sort</strong></td>
577
+ <td>n</td>
578
+ <td>n<sup>2</sup></td>
579
+ <td>n<sup>2</sup></td>
580
+ <td>1</td>
581
+ <td>Yes</td>
582
+ <td></td>
583
+ </tr>
584
+ <tr>
585
+ <td><strong>Selection sort</strong></td>
586
+ <td>n<sup>2</sup></td>
587
+ <td>n<sup>2</sup></td>
588
+ <td>n<sup>2</sup></td>
589
+ <td>1</td>
590
+ <td>No</td>
591
+ <td></td>
592
+ </tr>
593
+ <tr>
594
+ <td><strong>Heap sort</strong></td>
595
+ <td>n&nbsp;log(n)</td>
596
+ <td>n&nbsp;log(n)</td>
597
+ <td>n&nbsp;log(n)</td>
598
+ <td>1</td>
599
+ <td>No</td>
600
+ <td></td>
601
+ </tr>
602
+ <tr>
603
+ <td><strong>Merge sort</strong></td>
604
+ <td>n&nbsp;log(n)</td>
605
+ <td>n&nbsp;log(n)</td>
606
+ <td>n&nbsp;log(n)</td>
607
+ <td>n</td>
608
+ <td>Yes</td>
609
+ <td></td>
610
+ </tr>
611
+ <tr>
612
+ <td><strong>Quick sort</strong></td>
613
+ <td>n&nbsp;log(n)</td>
614
+ <td>n&nbsp;log(n)</td>
615
+ <td>n<sup>2</sup></td>
616
+ <td>log(n)</td>
617
+ <td>No</td>
618
+ <td>Quicksort is usually done in-place with O(log(n)) stack space</td>
619
+ </tr>
620
+ <tr>
621
+ <td><strong>Shell sort</strong></td>
622
+ <td>n&nbsp;log(n)</td>
623
+ <td>depends on gap sequence</td>
624
+ <td>n&nbsp;(log(n))<sup>2</sup></td>
625
+ <td>1</td>
626
+ <td>No</td>
627
+ <td></td>
628
+ </tr>
629
+ <tr>
630
+ <td><strong>Counting sort</strong></td>
631
+ <td>n + r</td>
632
+ <td>n + r</td>
633
+ <td>n + r</td>
634
+ <td>n + r</td>
635
+ <td>Yes</td>
636
+ <td>r - biggest number in array</td>
637
+ </tr>
638
+ <tr>
639
+ <td><strong>Radix sort</strong></td>
640
+ <td>n * k</td>
641
+ <td>n * k</td>
642
+ <td>n * k</td>
643
+ <td>n + k</td>
644
+ <td>Yes</td>
645
+ <td>k - length of longest key</td>
646
+ </tr>
647
+ </tbody>
648
+ </table>
649
+
650
+ ![overview diagram](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/overview-diagram-of-data-structures.png)
651
+
652
+ ![complexities](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/complexities-diff.jpg)
653
+
654
+ ![complexities of data structures](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/data-structure-complexities.jpg)
655
+
656
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/bst-rotation.gif&#41;)
657
+
658
+ [//]: # ()
659
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/avl-tree-inserting.gif&#41;)
660
+
661
+ [//]: # ()
662
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan.webp&#41;)
663
+
664
+ [//]: # ()
665
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list.jpg&#41;)
666
+
667
+ [//]: # ()
668
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list-pros-cons.jpg&#41;)
669
+
670
+ [//]: # ()
671
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix.jpg&#41;)
672
+
673
+ [//]: # ()
674
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix-pros-cons.jpg&#41;)
675
+
676
+ [//]: # ()
677
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/dfs-can-do.jpg&#41;)
678
+
679
+ [//]: # ()
680
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list.jpg&#41;)
681
+
682
+ [//]: # ()
683
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list-pros-cons.jpg&#41;)
684
+
685
+ [//]: # ()
686
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/max-flow.jpg&#41;)
687
+
688
+ [//]: # ()
689
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/mst.jpg&#41;)
690
+
691
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-articulation-point-bridge.png&#41;)
692
+
693
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-complicate-simple.png&#41;)
694
+
695
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-strongly-connected-component.png&#41;)
696
+
697
+
698
+
699
+
700
+
@@ -0,0 +1 @@
1
+ export * from './max-heap';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./max-heap"), exports);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { Heap, HeapItem } from 'data-structure-typed';
9
+ import { PriorityQueue } from 'data-structure-typed';
10
+ import type { HeapOptions } from 'data-structure-typed';
11
+ /**
12
+ * @class MaxHeap
13
+ * @extends Heap
14
+ */
15
+ export declare class MaxHeap<T = number> extends Heap<T> {
16
+ protected _pq: PriorityQueue<HeapItem<T>>;
17
+ /**
18
+ * The constructor initializes a PriorityQueue with a custom comparator function.
19
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
20
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
21
+ */
22
+ constructor(options?: HeapOptions<T>);
23
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
8
+ */
9
+ var __extends = (this && this.__extends) || (function () {
10
+ var extendStatics = function (d, b) {
11
+ extendStatics = Object.setPrototypeOf ||
12
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
14
+ return extendStatics(d, b);
15
+ };
16
+ return function (d, b) {
17
+ if (typeof b !== "function" && b !== null)
18
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
19
+ extendStatics(d, b);
20
+ function __() { this.constructor = d; }
21
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22
+ };
23
+ })();
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.MaxHeap = void 0;
26
+ var data_structure_typed_1 = require("data-structure-typed");
27
+ var data_structure_typed_2 = require("data-structure-typed");
28
+ /**
29
+ * @class MaxHeap
30
+ * @extends Heap
31
+ */
32
+ var MaxHeap = /** @class */ (function (_super) {
33
+ __extends(MaxHeap, _super);
34
+ /**
35
+ * The constructor initializes a PriorityQueue with a custom comparator function.
36
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
37
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
38
+ */
39
+ function MaxHeap(options) {
40
+ var _this = _super.call(this, options) || this;
41
+ _this._pq = new data_structure_typed_2.PriorityQueue({
42
+ comparator: function (a, b) { return b.priority - a.priority; }
43
+ });
44
+ return _this;
45
+ }
46
+ return MaxHeap;
47
+ }(data_structure_typed_1.Heap));
48
+ exports.MaxHeap = MaxHeap;
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testMatch: ['<rootDir>/tests/**/*.test.ts'],
5
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "max-heap-typed",
3
+ "version": "1.19.3",
4
+ "description": "Max Heap. Javascript & Typescript Data Structure.",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "rm -rf dist && npx tsc",
8
+ "test": "jest",
9
+ "build:docs": "typedoc --out docs ./src",
10
+ "deps:check": "dependency-cruiser src",
11
+ "build:publish": "npm run build && npm run build:docs && npm publish"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/zrwusa/data-structure-typed"
16
+ },
17
+ "keywords": [
18
+ "Binary heap",
19
+ "Max heap",
20
+ "Heap data structure",
21
+ "Priority queue",
22
+ "Complete binary tree",
23
+ "Heap property",
24
+ "Insertion",
25
+ "Deletion",
26
+ "Heapify",
27
+ "Heap sort",
28
+ "Heap operations",
29
+ "Parent",
30
+ "Child",
31
+ "Root",
32
+ "Heapify up",
33
+ "Heapify down",
34
+ "Extract maximum",
35
+ "Decrease key",
36
+ "Increase key",
37
+ "Heap operations complexity",
38
+ "Binary tree",
39
+ "Data structure",
40
+ "Efficient priority management",
41
+ "Ordering property"
42
+ ],
43
+ "author": "Tyler Zeng zrwusa@gmail.com",
44
+ "license": "MIT",
45
+ "bugs": {
46
+ "url": "https://github.com/zrwusa/data-structure-typed/issues"
47
+ },
48
+ "homepage": "https://github.com/zrwusa/data-structure-typed#readme",
49
+ "types": "dist/index.d.ts",
50
+ "devDependencies": {
51
+ "@types/jest": "^29.5.3",
52
+ "@types/node": "^20.4.9",
53
+ "dependency-cruiser": "^13.1.2",
54
+ "jest": "^29.6.2",
55
+ "ts-jest": "^29.1.1",
56
+ "typedoc": "^0.24.8",
57
+ "typescript": "^4.9.5"
58
+ },
59
+ "dependencies": {
60
+ "data-structure-typed": "^1.19.3",
61
+ "zod": "^3.22.2"
62
+ }
63
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "outDir": "./dist",
5
+ "module": "commonjs",
6
+ "target": "es5",
7
+ "lib": [
8
+ "esnext",
9
+ ],
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "moduleResolution": "node",
13
+ "declarationDir": "./dist",
14
+ "skipLibCheck": true,
15
+ "downlevelIteration": true,
16
+ "experimentalDecorators": true,
17
+ // "allowJs": true,
18
+ // "allowSyntheticDefaultImports": true,
19
+ // "forceConsistentCasingInFileNames": true,
20
+ // "noFallthroughCasesInSwitch": true,
21
+ // "resolveJsonModule": true,
22
+ // "isolatedModules": true,
23
+ // "noEmit": true,
24
+ "typeRoots": [
25
+ "node_modules/@types"
26
+ ]
27
+ },
28
+
29
+ "include": [
30
+ "src",
31
+ ],
32
+ "exclude": [
33
+ // "node_modules/data-structure-typed",
34
+ "node_modules",
35
+ "dist"
36
+ ]
37
+ }