data-structure-typed 1.12.11 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -179
- package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +72 -18
- package/dist/data-structures/binary-tree/binary-tree.js +139 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +70 -2
- package/dist/data-structures/binary-tree/segment-tree.js +86 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +45 -5
- package/dist/data-structures/graph/abstract-graph.js +59 -11
- package/dist/data-structures/graph/directed-graph.d.ts +26 -4
- package/dist/data-structures/graph/directed-graph.js +38 -39
- package/dist/data-structures/graph/undirected-graph.d.ts +23 -0
- package/dist/data-structures/graph/undirected-graph.js +41 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-map.js +21 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-set.js +21 -2
- package/dist/data-structures/heap/heap.d.ts +25 -6
- package/dist/data-structures/heap/heap.js +46 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +32 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +75 -8
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +267 -330
- package/dist/data-structures/linked-list/singly-linked-list.js +263 -275
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +14 -5
- package/dist/data-structures/priority-queue/priority-queue.js +20 -4
- package/dist/data-structures/queue/deque.d.ts +30 -16
- package/dist/data-structures/queue/deque.js +62 -12
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/data-structures/types/abstract-graph.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +2 -2
- package/src/data-structures/binary-tree/aa-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +84 -14
- package/src/data-structures/binary-tree/segment-tree.ts +45 -13
- package/src/data-structures/graph/abstract-graph.ts +58 -15
- package/src/data-structures/graph/directed-graph.ts +14 -5
- package/src/data-structures/graph/undirected-graph.ts +23 -6
- package/src/data-structures/hash/coordinate-map.ts +13 -1
- package/src/data-structures/hash/coordinate-set.ts +13 -1
- package/src/data-structures/heap/heap.ts +31 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
- package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
- package/src/data-structures/priority-queue/priority-queue.ts +15 -2
- package/src/data-structures/queue/deque.ts +38 -8
- package/src/data-structures/types/abstract-graph.ts +3 -3
- package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { AnyFunction } from './types';
|
|
2
|
-
export type JSONSerializable = {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
};
|
|
5
|
-
export type JSONValue = string | number | boolean | undefined | JSONObject;
|
|
6
|
-
export interface JSONObject {
|
|
7
|
-
[key: string]: JSONValue;
|
|
8
|
-
}
|
|
1
|
+
import type { AnyFunction, JSONObject, JSONSerializable } from './types';
|
|
9
2
|
export declare function randomText(length: number): string;
|
|
10
3
|
export declare const uuidV4: () => string;
|
|
11
4
|
export declare class IncrementId {
|
|
@@ -103,3 +96,20 @@ export declare function zip<T = number, T1 = number>(array1: T[], array2: T1[],
|
|
|
103
96
|
x: T;
|
|
104
97
|
y: T1;
|
|
105
98
|
}[];
|
|
99
|
+
/**
|
|
100
|
+
* data-structure-typed
|
|
101
|
+
*
|
|
102
|
+
* @author Tyler Zeng
|
|
103
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
104
|
+
* @license MIT License
|
|
105
|
+
*/
|
|
106
|
+
import { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
107
|
+
export declare const THUNK_SYMBOL: unique symbol;
|
|
108
|
+
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
109
|
+
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
110
|
+
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
111
|
+
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
112
|
+
};
|
|
113
|
+
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
114
|
+
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
115
|
+
};
|
package/dist/utils/utils.js
CHANGED
|
@@ -10,29 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -105,9 +82,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
105
82
|
}
|
|
106
83
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
107
84
|
};
|
|
85
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
86
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
|
+
};
|
|
108
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
109
|
-
exports.zip = exports.memo = exports.arrayRemove = exports.timeEnd = exports.timeStart = exports.bunnyConsole = exports.deepAdd = exports.deepReplaceValues = exports.deepRenameKeys = exports.deepRemoveByKey = exports.deepKeysConvert = exports.StringUtil = exports.diffAB = exports.onlyInB = exports.onlyInA = exports.comparerArray = exports.capitalizeFirstLetter = exports.capitalizeWords = exports.randomDate = exports.minuted = exports.keyValueToArray = exports.extractValue = exports.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
|
|
110
|
-
var
|
|
89
|
+
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.zip = exports.memo = exports.arrayRemove = exports.timeEnd = exports.timeStart = exports.bunnyConsole = exports.deepAdd = exports.deepReplaceValues = exports.deepRenameKeys = exports.deepRemoveByKey = exports.deepKeysConvert = exports.StringUtil = exports.diffAB = exports.onlyInB = exports.onlyInA = exports.comparerArray = exports.capitalizeFirstLetter = exports.capitalizeWords = exports.randomDate = exports.minuted = exports.keyValueToArray = exports.extractValue = exports.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
|
|
90
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
111
91
|
function randomText(length) {
|
|
112
92
|
var result = '';
|
|
113
93
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
@@ -396,7 +376,7 @@ var comparerArray = function (otherArray, limitKeys) {
|
|
|
396
376
|
return function (current) {
|
|
397
377
|
return otherArray.filter(function (other) {
|
|
398
378
|
if (!limitKeys) {
|
|
399
|
-
return
|
|
379
|
+
return lodash_1.default.isEqual(current, other);
|
|
400
380
|
}
|
|
401
381
|
else {
|
|
402
382
|
// TODO
|
|
@@ -416,43 +396,43 @@ var StringUtil = /** @class */ (function () {
|
|
|
416
396
|
}
|
|
417
397
|
// camelCase
|
|
418
398
|
StringUtil.toCamelCase = function (str) {
|
|
419
|
-
return
|
|
399
|
+
return lodash_1.default.camelCase(str);
|
|
420
400
|
};
|
|
421
401
|
// snake_case
|
|
422
402
|
StringUtil.toSnakeCase = function (str) {
|
|
423
|
-
return
|
|
403
|
+
return lodash_1.default.snakeCase(str);
|
|
424
404
|
};
|
|
425
405
|
// PascalCase
|
|
426
406
|
StringUtil.toPascalCase = function (str) {
|
|
427
|
-
return
|
|
407
|
+
return lodash_1.default.startCase(lodash_1.default.camelCase(str)).replace(/ /g, '');
|
|
428
408
|
};
|
|
429
409
|
// CONSTANT_CASE
|
|
430
410
|
StringUtil.toConstantCase = function (str) {
|
|
431
|
-
return
|
|
411
|
+
return lodash_1.default.upperCase(str).replace(/ /g, '_');
|
|
432
412
|
};
|
|
433
413
|
// kebab-case
|
|
434
414
|
StringUtil.toKebabCase = function (str) {
|
|
435
|
-
return
|
|
415
|
+
return lodash_1.default.kebabCase(str);
|
|
436
416
|
};
|
|
437
417
|
// lowercase
|
|
438
418
|
StringUtil.toLowerCase = function (str) {
|
|
439
|
-
return
|
|
419
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '');
|
|
440
420
|
};
|
|
441
421
|
// Title Case
|
|
442
422
|
StringUtil.toTitleCase = function (str) {
|
|
443
|
-
return
|
|
423
|
+
return lodash_1.default.startCase(lodash_1.default.camelCase(str));
|
|
444
424
|
};
|
|
445
425
|
// Sentence case
|
|
446
426
|
StringUtil.toSentenceCase = function (str) {
|
|
447
|
-
return
|
|
427
|
+
return lodash_1.default.upperFirst(lodash_1.default.lowerCase(str));
|
|
448
428
|
};
|
|
449
429
|
// path/case
|
|
450
430
|
StringUtil.toPathCase = function (str) {
|
|
451
|
-
return
|
|
431
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '/');
|
|
452
432
|
};
|
|
453
433
|
// dot.case
|
|
454
434
|
StringUtil.toDotCase = function (str) {
|
|
455
|
-
return
|
|
435
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '.');
|
|
456
436
|
};
|
|
457
437
|
return StringUtil;
|
|
458
438
|
}());
|
|
@@ -508,27 +488,27 @@ var deepKeysConvert = function (obj, toType) {
|
|
|
508
488
|
};
|
|
509
489
|
exports.deepKeysConvert = deepKeysConvert;
|
|
510
490
|
var deepRemoveByKey = function (obj, keysToBeRemoved) {
|
|
511
|
-
var result =
|
|
512
|
-
if (
|
|
491
|
+
var result = lodash_1.default.transform(obj, function (result, value, key) {
|
|
492
|
+
if (lodash_1.default.isObject(value)) {
|
|
513
493
|
value = (0, exports.deepRemoveByKey)(value, keysToBeRemoved);
|
|
514
494
|
}
|
|
515
495
|
if (!keysToBeRemoved.includes(key)) {
|
|
516
|
-
|
|
496
|
+
lodash_1.default.isArray(obj) ? result.push(value) : result[key] = value;
|
|
517
497
|
}
|
|
518
498
|
});
|
|
519
499
|
return result;
|
|
520
500
|
};
|
|
521
501
|
exports.deepRemoveByKey = deepRemoveByKey;
|
|
522
502
|
var deepRenameKeys = function (obj, keysMap) {
|
|
523
|
-
return
|
|
503
|
+
return lodash_1.default.transform(obj, function (result, value, key) {
|
|
524
504
|
var currentKey = keysMap[key] || key;
|
|
525
|
-
result[currentKey] =
|
|
505
|
+
result[currentKey] = lodash_1.default.isObject(value) ? (0, exports.deepRenameKeys)(value, keysMap) : value;
|
|
526
506
|
});
|
|
527
507
|
};
|
|
528
508
|
exports.deepRenameKeys = deepRenameKeys;
|
|
529
509
|
var deepReplaceValues = function (obj, keyReducerMap) {
|
|
530
|
-
var newObject =
|
|
531
|
-
|
|
510
|
+
var newObject = lodash_1.default.clone(obj);
|
|
511
|
+
lodash_1.default.each(obj, function (val, key) {
|
|
532
512
|
for (var item in keyReducerMap) {
|
|
533
513
|
if (key === item) {
|
|
534
514
|
newObject[key] = keyReducerMap[item](newObject);
|
|
@@ -543,14 +523,14 @@ var deepReplaceValues = function (obj, keyReducerMap) {
|
|
|
543
523
|
exports.deepReplaceValues = deepReplaceValues;
|
|
544
524
|
// TODO determine depth and pass root node as a param through callback
|
|
545
525
|
var deepAdd = function (obj, keyReducerMap, isItemRootParent) {
|
|
546
|
-
var newObject =
|
|
547
|
-
if (
|
|
526
|
+
var newObject = lodash_1.default.clone(obj);
|
|
527
|
+
if (lodash_1.default.isObject(newObject) && !lodash_1.default.isArray(newObject)) {
|
|
548
528
|
for (var item in keyReducerMap) {
|
|
549
529
|
newObject[item] = keyReducerMap[item](newObject);
|
|
550
530
|
}
|
|
551
531
|
}
|
|
552
|
-
|
|
553
|
-
if (
|
|
532
|
+
lodash_1.default.each(obj, function (val, key) {
|
|
533
|
+
if (lodash_1.default.isObject(val)) {
|
|
554
534
|
for (var item in keyReducerMap) {
|
|
555
535
|
// @ts-ignore
|
|
556
536
|
newObject[key] = (0, exports.deepAdd)(val, keyReducerMap, isItemRootParent);
|
|
@@ -649,3 +629,69 @@ function zip(array1, array2, options) {
|
|
|
649
629
|
return isToObj ? zippedObjCoords : zipped;
|
|
650
630
|
}
|
|
651
631
|
exports.zip = zip;
|
|
632
|
+
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
633
|
+
var isThunk = function (fnOrValue) {
|
|
634
|
+
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
635
|
+
};
|
|
636
|
+
exports.isThunk = isThunk;
|
|
637
|
+
var toThunk = function (fn) {
|
|
638
|
+
var thunk = function () { return fn(); };
|
|
639
|
+
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
640
|
+
return thunk;
|
|
641
|
+
};
|
|
642
|
+
exports.toThunk = toThunk;
|
|
643
|
+
var trampoline = function (fn) {
|
|
644
|
+
var cont = function () {
|
|
645
|
+
var args = [];
|
|
646
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
647
|
+
args[_i] = arguments[_i];
|
|
648
|
+
}
|
|
649
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
650
|
+
};
|
|
651
|
+
return Object.assign(function () {
|
|
652
|
+
var args = [];
|
|
653
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
654
|
+
args[_i] = arguments[_i];
|
|
655
|
+
}
|
|
656
|
+
var result = fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
657
|
+
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
658
|
+
result = result();
|
|
659
|
+
}
|
|
660
|
+
return result;
|
|
661
|
+
}, { cont: cont });
|
|
662
|
+
};
|
|
663
|
+
exports.trampoline = trampoline;
|
|
664
|
+
var trampolineAsync = function (fn) {
|
|
665
|
+
var cont = function () {
|
|
666
|
+
var args = [];
|
|
667
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
668
|
+
args[_i] = arguments[_i];
|
|
669
|
+
}
|
|
670
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
671
|
+
};
|
|
672
|
+
return Object.assign(function () {
|
|
673
|
+
var args = [];
|
|
674
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
675
|
+
args[_i] = arguments[_i];
|
|
676
|
+
}
|
|
677
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
678
|
+
var result;
|
|
679
|
+
return __generator(this, function (_a) {
|
|
680
|
+
switch (_a.label) {
|
|
681
|
+
case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
|
|
682
|
+
case 1:
|
|
683
|
+
result = _a.sent();
|
|
684
|
+
_a.label = 2;
|
|
685
|
+
case 2:
|
|
686
|
+
if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
|
|
687
|
+
return [4 /*yield*/, result()];
|
|
688
|
+
case 3:
|
|
689
|
+
result = _a.sent();
|
|
690
|
+
return [3 /*break*/, 2];
|
|
691
|
+
case 4: return [2 /*return*/, result];
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}, { cont: cont });
|
|
696
|
+
};
|
|
697
|
+
exports.trampolineAsync = trampolineAsync;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"jest": "^29.6.2",
|
|
55
55
|
"ts-jest": "^29.1.1",
|
|
56
56
|
"typedoc": "^0.24.8",
|
|
57
|
-
"typescript": "^4.
|
|
57
|
+
"typescript": "^4.9.5"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"lodash": "^4.17.21"
|
|
@@ -30,38 +30,50 @@ export enum LoopType { iterative = 1, recursive = 2}
|
|
|
30
30
|
|
|
31
31
|
export class BinaryTreeNode<T> {
|
|
32
32
|
|
|
33
|
-
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
|
|
34
|
-
this._id = id;
|
|
35
|
-
this._val = val;
|
|
36
|
-
this._count = count ?? 1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
protected _id: BinaryTreeNodeId;
|
|
40
|
-
|
|
41
34
|
get id(): BinaryTreeNodeId {
|
|
42
35
|
return this._id;
|
|
43
36
|
}
|
|
44
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
40
|
+
*/
|
|
41
|
+
getId(): BinaryTreeNodeId {
|
|
42
|
+
return this._id;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
45
|
set id(v: BinaryTreeNodeId) {
|
|
46
46
|
this._id = v;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
protected _val: T;
|
|
50
|
-
|
|
51
50
|
get val(): T {
|
|
52
51
|
return this._val;
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
56
|
+
*/
|
|
57
|
+
getVal(): T {
|
|
58
|
+
return this._val;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
set val(v: T) {
|
|
56
62
|
this._val = v;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
protected _left?: BinaryTreeNode<T> | null;
|
|
60
|
-
|
|
61
66
|
get left(): BinaryTreeNode<T> | null | undefined {
|
|
62
67
|
return this._left;
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
72
|
+
*/
|
|
73
|
+
getLeft(): BinaryTreeNode<T> | null | undefined {
|
|
74
|
+
return this._left;
|
|
75
|
+
}
|
|
76
|
+
|
|
65
77
|
set left(v: BinaryTreeNode<T> | null | undefined) {
|
|
66
78
|
if (v) {
|
|
67
79
|
v.parent = this;
|
|
@@ -71,11 +83,17 @@ export class BinaryTreeNode<T> {
|
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
protected _right?: BinaryTreeNode<T> | null;
|
|
74
|
-
|
|
75
86
|
get right(): BinaryTreeNode<T> | null | undefined {
|
|
76
87
|
return this._right;
|
|
77
88
|
}
|
|
78
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
92
|
+
*/
|
|
93
|
+
getRight(): BinaryTreeNode<T> | null | undefined {
|
|
94
|
+
return this._right;
|
|
95
|
+
}
|
|
96
|
+
|
|
79
97
|
set right(v: BinaryTreeNode<T> | null | undefined) {
|
|
80
98
|
if (v) {
|
|
81
99
|
v.parent = this;
|
|
@@ -85,45 +103,75 @@ export class BinaryTreeNode<T> {
|
|
|
85
103
|
}
|
|
86
104
|
|
|
87
105
|
protected _parent: BinaryTreeNode<T> | null | undefined;
|
|
88
|
-
|
|
89
106
|
get parent(): BinaryTreeNode<T> | null | undefined {
|
|
90
107
|
return this._parent;
|
|
91
108
|
}
|
|
92
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
112
|
+
*/
|
|
113
|
+
getParent(): BinaryTreeNode<T> | null | undefined {
|
|
114
|
+
return this._parent;
|
|
115
|
+
}
|
|
116
|
+
|
|
93
117
|
set parent(v: BinaryTreeNode<T> | null | undefined) {
|
|
94
118
|
this._parent = v;
|
|
95
119
|
}
|
|
96
120
|
|
|
97
121
|
protected _familyPosition: FamilyPosition = FamilyPosition.root;
|
|
98
|
-
|
|
99
122
|
get familyPosition(): FamilyPosition {
|
|
100
123
|
return this._familyPosition;
|
|
101
124
|
}
|
|
102
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
128
|
+
*/
|
|
129
|
+
getFamilyPosition(): FamilyPosition {
|
|
130
|
+
return this._familyPosition;
|
|
131
|
+
}
|
|
132
|
+
|
|
103
133
|
set familyPosition(v: FamilyPosition) {
|
|
104
134
|
this._familyPosition = v;
|
|
105
135
|
}
|
|
106
136
|
|
|
107
137
|
protected _count = 1;
|
|
108
|
-
|
|
109
138
|
get count(): number {
|
|
110
139
|
return this._count;
|
|
111
140
|
}
|
|
112
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
144
|
+
*/
|
|
145
|
+
getCount(): number {
|
|
146
|
+
return this._count;
|
|
147
|
+
}
|
|
148
|
+
|
|
113
149
|
set count(v: number) {
|
|
114
150
|
this._count = v;
|
|
115
151
|
}
|
|
116
152
|
|
|
117
153
|
protected _height = 0;
|
|
118
|
-
|
|
119
154
|
get height(): number {
|
|
120
155
|
return this._height;
|
|
121
156
|
}
|
|
122
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
160
|
+
*/
|
|
161
|
+
getHeight(): number {
|
|
162
|
+
return this._height;
|
|
163
|
+
}
|
|
164
|
+
|
|
123
165
|
set height(v: number) {
|
|
124
166
|
this._height = v;
|
|
125
167
|
}
|
|
126
168
|
|
|
169
|
+
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
|
|
170
|
+
this._id = id;
|
|
171
|
+
this._val = val;
|
|
172
|
+
this._count = count ?? 1;
|
|
173
|
+
}
|
|
174
|
+
|
|
127
175
|
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T> {
|
|
128
176
|
const {val, count, height} = swapNode;
|
|
129
177
|
const tempNode = new BinaryTreeNode<T>(swapNode.id, val);
|
|
@@ -187,6 +235,14 @@ export class BinaryTree<T> {
|
|
|
187
235
|
return this._root;
|
|
188
236
|
}
|
|
189
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Getters (using the same name as the property) while utilizing separate method names for Setters.
|
|
240
|
+
* @returns The method is returning either a BinaryTreeNode object of type T or null.
|
|
241
|
+
*/
|
|
242
|
+
getRoot(): BinaryTreeNode<T> | null {
|
|
243
|
+
return this._root;
|
|
244
|
+
}
|
|
245
|
+
|
|
190
246
|
protected set root(v: BinaryTreeNode<T> | null) {
|
|
191
247
|
if (v) {
|
|
192
248
|
v.parent = null;
|
|
@@ -201,6 +257,13 @@ export class BinaryTree<T> {
|
|
|
201
257
|
return this._size;
|
|
202
258
|
}
|
|
203
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
262
|
+
*/
|
|
263
|
+
getSize(): number {
|
|
264
|
+
return this._size;
|
|
265
|
+
}
|
|
266
|
+
|
|
204
267
|
protected set size(v: number) {
|
|
205
268
|
this._size = v;
|
|
206
269
|
}
|
|
@@ -211,6 +274,13 @@ export class BinaryTree<T> {
|
|
|
211
274
|
return this._count;
|
|
212
275
|
}
|
|
213
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
279
|
+
*/
|
|
280
|
+
getCount(): number {
|
|
281
|
+
return this._count;
|
|
282
|
+
}
|
|
283
|
+
|
|
214
284
|
protected set count(v: number) {
|
|
215
285
|
this._count = v;
|
|
216
286
|
}
|
|
@@ -17,61 +17,85 @@ export class SegmentTreeNode {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
protected _start = 0;
|
|
20
|
-
|
|
21
20
|
get start(): number {
|
|
22
21
|
return this._start;
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
25
|
+
*/
|
|
26
|
+
getStart(): number {
|
|
27
|
+
return this._start;
|
|
28
|
+
}
|
|
25
29
|
set start(v: number) {
|
|
26
30
|
this._start = v;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
protected _end = 0;
|
|
30
|
-
|
|
31
34
|
get end(): number {
|
|
32
35
|
return this._end;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
39
|
+
*/
|
|
40
|
+
getEnd(): number {
|
|
41
|
+
return this._end;
|
|
42
|
+
}
|
|
35
43
|
set end(v: number) {
|
|
36
44
|
this._end = v;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
protected _val: SegmentTreeNodeVal | null = null;
|
|
40
|
-
|
|
41
48
|
get val(): SegmentTreeNodeVal | null {
|
|
42
49
|
return this._val;
|
|
43
50
|
}
|
|
44
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
53
|
+
*/
|
|
54
|
+
getVal(): SegmentTreeNodeVal | null {
|
|
55
|
+
return this._val;
|
|
56
|
+
}
|
|
45
57
|
set val(v: SegmentTreeNodeVal | null) {
|
|
46
58
|
this._val = v;
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
protected _sum = 0;
|
|
50
|
-
|
|
51
62
|
get sum(): number {
|
|
52
63
|
return this._sum;
|
|
53
64
|
}
|
|
54
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
67
|
+
*/
|
|
68
|
+
getSum(): number {
|
|
69
|
+
return this._sum;
|
|
70
|
+
}
|
|
55
71
|
set sum(v: number) {
|
|
56
72
|
this._sum = v;
|
|
57
73
|
}
|
|
58
74
|
|
|
59
75
|
protected _left: SegmentTreeNode | null = null;
|
|
60
|
-
|
|
61
76
|
get left(): SegmentTreeNode | null {
|
|
62
77
|
return this._left;
|
|
63
78
|
}
|
|
64
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
81
|
+
*/
|
|
82
|
+
getLeft(): SegmentTreeNode | null {
|
|
83
|
+
return this._left;
|
|
84
|
+
}
|
|
65
85
|
set left(v: SegmentTreeNode | null) {
|
|
66
86
|
this._left = v;
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
protected _right: SegmentTreeNode | null = null;
|
|
70
|
-
|
|
71
90
|
get right(): SegmentTreeNode | null {
|
|
72
91
|
return this._right;
|
|
73
92
|
}
|
|
74
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
95
|
+
*/
|
|
96
|
+
getRight(): SegmentTreeNode | null {
|
|
97
|
+
return this._right;
|
|
98
|
+
}
|
|
75
99
|
set right(v: SegmentTreeNode | null) {
|
|
76
100
|
this._right = v;
|
|
77
101
|
}
|
|
@@ -101,10 +125,18 @@ export class SegmentTree {
|
|
|
101
125
|
}
|
|
102
126
|
|
|
103
127
|
protected _root: SegmentTreeNode | null;
|
|
104
|
-
|
|
105
128
|
get root(): SegmentTreeNode | null {
|
|
106
129
|
return this._root;
|
|
107
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
133
|
+
*/
|
|
134
|
+
getRoot(): SegmentTreeNode | null {
|
|
135
|
+
return this._root;
|
|
136
|
+
}
|
|
137
|
+
set root(v: SegmentTreeNode | null) {
|
|
138
|
+
this._root = v;
|
|
139
|
+
}
|
|
108
140
|
|
|
109
141
|
/**
|
|
110
142
|
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|