diff --git a/.prettierignore b/.prettierignore index 1938daa..e459c2d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,5 @@ -src/types/data-structures/binary-tree.ts -src/types/data-structures/bst.ts -src/types/data-structures/avl-tree.ts -src/types/data-structures/rb-tree.ts -src/types/data-structures/tree-multiset.ts +src/types/data-structures/binary-tree/binary-tree.ts +src/types/data-structures/binary-tree/bst.ts +src/types/data-structures/binary-tree/avl-tree.ts +src/types/data-structures/binary-tree/rb-tree.ts +src/types/data-structures/binary-tree/tree-multiset.ts diff --git a/package-lock.json b/package-lock.json index e3fe225..3f14577 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,16 @@ { "name": "data-structure-typed", - "version": "1.37.3", + "version": "1.37.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.37.3", + "version": "1.37.9", "license": "MIT", + "dependencies": { + "data-structure-typed": "^1.37.5" + }, "devDependencies": { "@types/benchmark": "^2.1.3", "@types/jest": "^29.5.5", @@ -15,17 +18,17 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.37.2", + "avl-tree-typed": "^1.37.9", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.37.2", - "bst-typed": "^1.37.2", + "binary-tree-typed": "^1.37.9", + "bst-typed": "^1.37.9", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-alias": "^1.1.2", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", - "heap-typed": "^1.37.2", + "heap-typed": "^1.37.9", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", @@ -757,21 +760,21 @@ "dev": true }, "node_modules/@eslint/js": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.51.0.tgz", - "integrity": "sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", + "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.11", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz", - "integrity": "sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA==", + "version": "0.11.13", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", + "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", + "@humanwhocodes/object-schema": "^2.0.1", "debug": "^4.1.1", "minimatch": "^3.0.5" }, @@ -793,9 +796,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", + "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", "dev": true }, "node_modules/@istanbuljs/load-nyc-config": { @@ -1478,9 +1481,9 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", - "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", + "version": "0.3.20", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz", + "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==", "dev": true, "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", @@ -1547,9 +1550,9 @@ } }, "node_modules/@types/babel__core": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.2.tgz", - "integrity": "sha512-pNpr1T1xLUc2l3xJKuPtsEky3ybxN3m4fJkknfIpTCTfIZCDW57oAg+EfCgIIp2rvCe0Wn++/FfodDS4YXxBwA==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.3.tgz", + "integrity": "sha512-54fjTSeSHwfan8AyHWrKbfBWiEUrNTZsUwPTDSNaaP1QDQIZbeNUg3a59E9D+375MzUw/x1vx2/0F5LBz+AeYA==", "dev": true, "dependencies": { "@babel/parser": "^7.20.7", @@ -1560,18 +1563,18 @@ } }, "node_modules/@types/babel__generator": { - "version": "7.6.5", - "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.5.tgz", - "integrity": "sha512-h9yIuWbJKdOPLJTbmSpPzkF67e659PbQDba7ifWm5BJ8xTv+sDmS7rFmywkWOvXedGTivCdeGSIIX8WLcRTz8w==", + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.6.tgz", + "integrity": "sha512-66BXMKb/sUWbMdBNdMvajU7i/44RkrA3z/Yt1c7R5xejt8qh84iU54yUWCtm0QwGJlDcf/gg4zd/x4mpLAlb/w==", "dev": true, "dependencies": { "@babel/types": "^7.0.0" } }, "node_modules/@types/babel__template": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.2.tgz", - "integrity": "sha512-/AVzPICMhMOMYoSx9MoKpGDKdBRsIXMNByh1PXSZoa+v6ZoLa8xxtsT/uLQ/NJm0XVAWl/BvId4MlDeXJaeIZQ==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.3.tgz", + "integrity": "sha512-ciwyCLeuRfxboZ4isgdNZi/tkt06m8Tw6uGbBSBgWrnnZGNXiEyM27xc/PjXGQLqlZ6ylbgHMnm7ccF9tCkOeQ==", "dev": true, "dependencies": { "@babel/parser": "^7.1.0", @@ -1579,24 +1582,24 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.2.tgz", - "integrity": "sha512-ojlGK1Hsfce93J0+kn3H5R73elidKUaZonirN33GSmgTUMpzI/MIFfSpF3haANe3G1bEBS9/9/QEqwTzwqFsKw==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.3.tgz", + "integrity": "sha512-Lsh766rGEFbaxMIDH7Qa+Yha8cMVI3qAK6CHt3OR0YfxOIn5Z54iHiyDRycHrBqeIiqGa20Kpsv1cavfBKkRSw==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" } }, "node_modules/@types/benchmark": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@types/benchmark/-/benchmark-2.1.3.tgz", - "integrity": "sha512-psuUawgwIy/hSjO4AUDiPBJhJx72e3cBL+YzmVK/5ofRJC02R0NmvrSenGRuSmJc++0j95y2T01xKKNz50FGZw==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@types/benchmark/-/benchmark-2.1.4.tgz", + "integrity": "sha512-rVCCileCU5NhP9Ix1e03sIn4gd0mpjh7VNULVQAxzF+9vddk6A5QAHzp2h5kXH8pkv1Ow45fUf3QP3wOEiISvA==", "dev": true }, "node_modules/@types/eslint": { - "version": "8.44.4", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.4.tgz", - "integrity": "sha512-lOzjyfY/D9QR4hY9oblZ76B90MYTB3RrQ4z2vBIJKj9ROCRqdkYl2gSUx1x1a4IWPjKJZLL4Aw1Zfay7eMnmnA==", + "version": "8.44.6", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.6.tgz", + "integrity": "sha512-P6bY56TVmX8y9J87jHNgQh43h6VVU+6H7oN7hgvivV81K2XY8qJZ5vqPy/HdUoVIelii2kChYVzQanlswPWVFw==", "dev": true, "dependencies": { "@types/estree": "*", @@ -1604,9 +1607,9 @@ } }, "node_modules/@types/eslint-scope": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.5.tgz", - "integrity": "sha512-JNvhIEyxVW6EoMIFIvj93ZOywYFatlpu9deeH6eSx6PE3WHYvHaQtmHmQeNw7aA81bYGBPPQqdtBm6b1SsQMmA==", + "version": "3.7.6", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.6.tgz", + "integrity": "sha512-zfM4ipmxVKWdxtDaJ3MP3pBurDXOCoyjvlpE3u6Qzrmw4BPbfm4/ambIeTk/r/J0iq/+2/xp0Fmt+gFvXJY2PQ==", "dev": true, "dependencies": { "@types/eslint": "*", @@ -1614,48 +1617,48 @@ } }, "node_modules/@types/estree": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.2.tgz", - "integrity": "sha512-VeiPZ9MMwXjO32/Xu7+OwflfmeoRwkE/qzndw42gGtgJwZopBnzy2gD//NN1+go1mADzkDcqf/KnFRSjTJ8xJA==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.3.tgz", + "integrity": "sha512-CS2rOaoQ/eAgAfcTfq6amKG7bsN+EMcgGY4FAFQdvSj2y1ixvOZTUA9mOtCai7E1SYu283XNw7urKK30nP3wkQ==", "dev": true }, "node_modules/@types/graceful-fs": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.7.tgz", - "integrity": "sha512-MhzcwU8aUygZroVwL2jeYk6JisJrPl/oov/gsgGCue9mkgl9wjGbzReYQClxiUgFDnib9FuHqTndccKeZKxTRw==", + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.8.tgz", + "integrity": "sha512-NhRH7YzWq8WiNKVavKPBmtLYZHxNY19Hh+az28O/phfp68CF45pMFud+ZzJ8ewnxnC5smIdF3dqFeiSUQ5I+pw==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", + "integrity": "sha512-zONci81DZYCZjiLe0r6equvZut0b+dBRPBN5kBDjsONnutYNtJMoWQ9uR2RkL1gLG9NMTzvf+29e5RFfPbeKhQ==", "dev": true }, "node_modules/@types/istanbul-lib-report": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", - "integrity": "sha512-gPQuzaPR5h/djlAv2apEG1HVOyj1IUs7GpfMZixU0/0KXT3pm64ylHuMUI1/Akh+sq/iikxg6Z2j+fcMDXaaTQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.2.tgz", + "integrity": "sha512-8toY6FgdltSdONav1XtUHl4LN1yTmLza+EuDazb/fEmRNCwjyqNVIQWs2IfC74IqjHkREs/nQ2FWq5kZU9IC0w==", "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "*" } }, "node_modules/@types/istanbul-reports": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.2.tgz", - "integrity": "sha512-kv43F9eb3Lhj+lr/Hn6OcLCs/sSM8bt+fIaP11rCYngfV6NVjzWXJ17owQtDQTL9tQ8WSLUrGsSJ6rJz0F1w1A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.3.tgz", + "integrity": "sha512-1nESsePMBlf0RPRffLZi5ujYh7IH1BWL4y9pr+Bn3cJBdxz+RTP8bUFljLz9HvzhhOSWKdyBZ4DIivdL6rvgZg==", "dev": true, "dependencies": { "@types/istanbul-lib-report": "*" } }, "node_modules/@types/jest": { - "version": "29.5.5", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.5.tgz", - "integrity": "sha512-ebylz2hnsWR9mYvmBFbXJXr+33UPc4+ZdxyDXh5w0FlPBTfCVN3wPL+kuOiQt3xvrK419v7XWeAs+AeOksafXg==", + "version": "29.5.6", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.6.tgz", + "integrity": "sha512-/t9NnzkOpXb4Nfvg17ieHE6EeSjDS2SGSpNYfoLbUAeL/EOueU/RSdOWFpfQTXBEM7BguYW1XQ0EbM+6RlIh6w==", "dev": true, "dependencies": { "expect": "^29.0.0", @@ -1663,9 +1666,9 @@ } }, "node_modules/@types/json-schema": { - "version": "7.0.13", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", - "integrity": "sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==", + "version": "7.0.14", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.14.tgz", + "integrity": "sha512-U3PUjAudAdJBeC2pgN8uTIKgxrb4nlDF3SF0++EldXQvQBGkpFZMSnwQiIoDU77tv45VgNkl/L4ouD+rEomujw==", "dev": true }, "node_modules/@types/json5": { @@ -1675,52 +1678,52 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.6.tgz", - "integrity": "sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==", + "version": "20.8.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.8.tgz", + "integrity": "sha512-YRsdVxq6OaLfmR9Hy816IMp33xOBjfyOgUd77ehqg96CFywxAPbDbXvAsuN2KVg2HOT8Eh6uAfU+l4WffwPVrQ==", "dev": true, "dependencies": { "undici-types": "~5.25.1" } }, "node_modules/@types/semver": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", - "integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ==", "dev": true }, "node_modules/@types/stack-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", - "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.2.tgz", + "integrity": "sha512-g7CK9nHdwjK2n0ymT2CW698FuWJRIx+RP6embAzZ2Qi8/ilIrA1Imt2LVSeHUzKvpoi7BhmmQcXz95eS0f2JXw==", "dev": true }, "node_modules/@types/yargs": { - "version": "17.0.28", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.28.tgz", - "integrity": "sha512-N3e3fkS86hNhtk6BEnc0rj3zcehaxx8QWhCROJkqpl5Zaoi7nAic3jH8q94jVD3zu5LGk+PUB6KAiDmimYOEQw==", + "version": "17.0.29", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.29.tgz", + "integrity": "sha512-nacjqA3ee9zRF/++a3FUY1suHTFKZeHba2n8WeDw9cCVdmzmHpIxyzOJBcpHvvEmS8E9KqWlSnWHUkOrkhWcvA==", "dev": true, "dependencies": { "@types/yargs-parser": "*" } }, "node_modules/@types/yargs-parser": { - "version": "21.0.1", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.1.tgz", - "integrity": "sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==", + "version": "21.0.2", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.2.tgz", + "integrity": "sha512-5qcvofLPbfjmBfKaLfj/+f+Sbd6pN4zl7w7VSVI5uz7m9QZTuB2aZAa2uo1wHFBNN2x6g/SoTkXmd8mQnQF2Cw==", "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.5.tgz", - "integrity": "sha512-JhtAwTRhOUcP96D0Y6KYnwig/MRQbOoLGXTON2+LlyB/N35SP9j1boai2zzwXb7ypKELXMx3DVk9UTaEq1vHEw==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.9.0.tgz", + "integrity": "sha512-lgX7F0azQwRPB7t7WAyeHWVfW1YJ9NIgd9mvGhfQpRY56X6AVf8mwM8Wol+0z4liE7XX3QOt8MN1rUKCfSjRIA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.7.5", - "@typescript-eslint/type-utils": "6.7.5", - "@typescript-eslint/utils": "6.7.5", - "@typescript-eslint/visitor-keys": "6.7.5", + "@typescript-eslint/scope-manager": "6.9.0", + "@typescript-eslint/type-utils": "6.9.0", + "@typescript-eslint/utils": "6.9.0", + "@typescript-eslint/visitor-keys": "6.9.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -1746,15 +1749,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.5.tgz", - "integrity": "sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.9.0.tgz", + "integrity": "sha512-GZmjMh4AJ/5gaH4XF2eXA8tMnHWP+Pm1mjQR2QN4Iz+j/zO04b9TOvJYOX2sCNIQHtRStKTxRY1FX7LhpJT4Gw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.7.5", - "@typescript-eslint/types": "6.7.5", - "@typescript-eslint/typescript-estree": "6.7.5", - "@typescript-eslint/visitor-keys": "6.7.5", + "@typescript-eslint/scope-manager": "6.9.0", + "@typescript-eslint/types": "6.9.0", + "@typescript-eslint/typescript-estree": "6.9.0", + "@typescript-eslint/visitor-keys": "6.9.0", "debug": "^4.3.4" }, "engines": { @@ -1774,13 +1777,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.5.tgz", - "integrity": "sha512-GAlk3eQIwWOJeb9F7MKQ6Jbah/vx1zETSDw8likab/eFcqkjSD7BI75SDAeC5N2L0MmConMoPvTsmkrg71+B1A==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.9.0.tgz", + "integrity": "sha512-1R8A9Mc39n4pCCz9o79qRO31HGNDvC7UhPhv26TovDsWPBDx+Sg3rOZdCELIA3ZmNoWAuxaMOT7aWtGRSYkQxw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.5", - "@typescript-eslint/visitor-keys": "6.7.5" + "@typescript-eslint/types": "6.9.0", + "@typescript-eslint/visitor-keys": "6.9.0" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1791,13 +1794,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.5.tgz", - "integrity": "sha512-Gs0qos5wqxnQrvpYv+pf3XfcRXW6jiAn9zE/K+DlmYf6FcpxeNYN0AIETaPR7rHO4K2UY+D0CIbDP9Ut0U4m1g==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.9.0.tgz", + "integrity": "sha512-XXeahmfbpuhVbhSOROIzJ+b13krFmgtc4GlEuu1WBT+RpyGPIA4Y/eGnXzjbDj5gZLzpAXO/sj+IF/x2GtTMjQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.7.5", - "@typescript-eslint/utils": "6.7.5", + "@typescript-eslint/typescript-estree": "6.9.0", + "@typescript-eslint/utils": "6.9.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1818,9 +1821,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.5.tgz", - "integrity": "sha512-WboQBlOXtdj1tDFPyIthpKrUb+kZf2VroLZhxKa/VlwLlLyqv/PwUNgL30BlTVZV1Wu4Asu2mMYPqarSO4L5ZQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.9.0.tgz", + "integrity": "sha512-+KB0lbkpxBkBSiVCuQvduqMJy+I1FyDbdwSpM3IoBS7APl4Bu15lStPjgBIdykdRqQNYqYNMa8Kuidax6phaEw==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1831,13 +1834,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.5.tgz", - "integrity": "sha512-NhJiJ4KdtwBIxrKl0BqG1Ur+uw7FiOnOThcYx9DpOGJ/Abc9z2xNzLeirCG02Ig3vkvrc2qFLmYSSsaITbKjlg==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.9.0.tgz", + "integrity": "sha512-NJM2BnJFZBEAbCfBP00zONKXvMqihZCrmwCaik0UhLr0vAgb6oguXxLX1k00oQyD+vZZ+CJn3kocvv2yxm4awQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.5", - "@typescript-eslint/visitor-keys": "6.7.5", + "@typescript-eslint/types": "6.9.0", + "@typescript-eslint/visitor-keys": "6.9.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1858,17 +1861,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.5.tgz", - "integrity": "sha512-pfRRrH20thJbzPPlPc4j0UNGvH1PjPlhlCMq4Yx7EGjV7lvEeGX0U6MJYe8+SyFutWgSHsdbJ3BXzZccYggezA==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.9.0.tgz", + "integrity": "sha512-5Wf+Jsqya7WcCO8me504FBigeQKVLAMPmUzYgDbWchINNh1KJbxCgVya3EQ2MjvJMVeXl3pofRmprqX6mfQkjQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.7.5", - "@typescript-eslint/types": "6.7.5", - "@typescript-eslint/typescript-estree": "6.7.5", + "@typescript-eslint/scope-manager": "6.9.0", + "@typescript-eslint/types": "6.9.0", + "@typescript-eslint/typescript-estree": "6.9.0", "semver": "^7.5.4" }, "engines": { @@ -1883,12 +1886,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.7.5", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.5.tgz", - "integrity": "sha512-3MaWdDZtLlsexZzDSdQWsFQ9l9nL8B80Z4fImSpyllFC/KLqWQRdEcB+gGGO+N3Q2uL40EsG66wZLsohPxNXvg==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.9.0.tgz", + "integrity": "sha512-dGtAfqjV6RFOtIP8I0B4ZTBRrlTT8NHHlZZSchQx3qReaoDeXhYM++M4So2AgFK9ZB0emRPA6JI1HkafzA2Ibg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/types": "6.9.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1899,6 +1902,12 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -2396,12 +2405,12 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.37.2", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.37.2.tgz", - "integrity": "sha512-nwQjVhtKeVnMA6J1ZQwgMo/cubZEIhOFXCZfwu/tzKCklr8WTXAdCyysOVuT52SwKhzkdNjjSeAevDhfH7m05g==", + "version": "1.37.9", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.37.9.tgz", + "integrity": "sha512-FC7ezzT3Yw8H65oZgf/3RGYo9gnZRgORzlGGO4PyC19ZeIu0UZMHu1+kT0yEfbIE1qGBb4lnuwk4ia8CitcgLg==", "dev": true, "dependencies": { - "data-structure-typed": "^1.37.2" + "data-structure-typed": "^1.37.9" } }, "node_modules/babel-jest": { @@ -2586,12 +2595,12 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.37.2", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.37.2.tgz", - "integrity": "sha512-bCdPFOAm5eMiuDiJLfnj1g6dR2Ib2p4NLrhTvSzCWVjf/o/LLCjzpS0HfXHZ+sjhqfs7yxthgbW4SeHgDO5MPw==", + "version": "1.37.9", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.37.9.tgz", + "integrity": "sha512-8nCjU4V6ViR8NQfxCBsLRFx5Z8D4jpUIx4NuvjliR1R8YIzL6wMmahemve+UbCUWhZJNG5Dv0kVnnCWIK+T0hw==", "dev": true, "dependencies": { - "data-structure-typed": "^1.37.2" + "data-structure-typed": "^1.37.9" } }, "node_modules/brace-expansion": { @@ -2670,12 +2679,12 @@ } }, "node_modules/bst-typed": { - "version": "1.37.2", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.37.2.tgz", - "integrity": "sha512-6WBCmwIX5ibA5i8B/WyL3aXv4m0Pi2xU/6uPTIHfkQAfBSpdMUxrmwRJ5G6aBBJ6wwZ+KkRKezZj6DbklY2FRA==", + "version": "1.37.9", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.37.9.tgz", + "integrity": "sha512-KUp29JhTbNVdA1ePP7gUdi7uaRpM8DVhve9LMHQSUzxTDtHGc8mFTA+njFY7LLU2Rqtu/vqBgTu7bJRVJbWrPA==", "dev": true, "dependencies": { - "data-structure-typed": "^1.37.2" + "data-structure-typed": "^1.37.9" } }, "node_modules/buffer-from": { @@ -2685,13 +2694,14 @@ "dev": true }, "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", + "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", "dev": true, "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.1", + "set-function-length": "^1.1.1" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -2716,9 +2726,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001549", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001549.tgz", - "integrity": "sha512-qRp48dPYSCYaP+KurZLhDYdVE+yEyht/3NlmcJgVQ2VMGt6JL36ndQ/7rgspdZsJuxDPFIo/OzBT2+GmIJ53BA==", + "version": "1.0.30001553", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001553.tgz", + "integrity": "sha512-N0ttd6TrFfuqKNi+pMgWJTb9qrdJu4JSpgPFLe/lrD19ugC6fZgF0pUewRowDwzdDnb9V41mFcdlYgl/PyKf4A==", "dev": true, "funding": [ { @@ -3027,10 +3037,12 @@ } }, "node_modules/data-structure-typed": { - "version": "1.37.2", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.37.2.tgz", - "integrity": "sha512-eVU6Bd2G2xPkdO3SVqo8R+nUkWrdgDbOTR3OYtoldZbNH6Hp2lbv49goDrMYeFBxbsdJ9+k9bNI6WNTpC728uA==", - "dev": true + "version": "1.37.9", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.37.9.tgz", + "integrity": "sha512-6CUX8ANDv2IsJTB8tbdUrXFgWV1AAPxWdcco1ZRUX8caCM0Ge6Snwfse1G1BF6M8kVEuGO2r4q6zkw1z2DxAtQ==", + "dependencies": { + "data-structure-typed": "^1.37.5" + } }, "node_modules/debug": { "version": "4.3.4", @@ -3110,9 +3122,9 @@ } }, "node_modules/dependency-cruiser": { - "version": "14.1.1", - "resolved": "https://registry.npmjs.org/dependency-cruiser/-/dependency-cruiser-14.1.1.tgz", - "integrity": "sha512-npNLWv11pMH9BW4GBLuA5p6KYOXA9UjVDKQ4DzorEhAac5BS1J23K5I2WpEfkJMpwl9PKMsF4T/GDLSq3pogTw==", + "version": "14.1.2", + "resolved": "https://registry.npmjs.org/dependency-cruiser/-/dependency-cruiser-14.1.2.tgz", + "integrity": "sha512-DlHeyF7LxK+pQdEBS+5AykHhUNOyzhek7QCElcmkWfj/dGxuXudT4SrIn6jVtzOnIhU9GAJ8whqm1MHdLDDCHg==", "dev": true, "dependencies": { "acorn": "8.10.0", @@ -3122,7 +3134,7 @@ "acorn-walk": "8.2.0", "ajv": "8.12.0", "chalk": "5.3.0", - "commander": "11.0.0", + "commander": "11.1.0", "enhanced-resolve": "5.15.0", "figures": "5.0.0", "ignore": "5.2.4", @@ -3155,9 +3167,9 @@ } }, "node_modules/dependency-cruiser/node_modules/commander": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz", - "integrity": "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", "dev": true, "engines": { "node": ">=16" @@ -3212,9 +3224,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.554", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.554.tgz", - "integrity": "sha512-Q0umzPJjfBrrj8unkONTgbKQXzXRrH7sVV7D9ea2yBV3Oaogz991yhbpfvo2LMNkJItmruXTEzVpP9cp7vaIiQ==", + "version": "1.4.565", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.565.tgz", + "integrity": "sha512-XbMoT6yIvg2xzcbs5hCADi0dXBh4//En3oFXmtPX+jiyyiCTiM9DGFT2SLottjpEs9Z8Mh8SqahbR96MaHfuSg==", "dev": true }, "node_modules/emittery": { @@ -3270,26 +3282,26 @@ } }, "node_modules/es-abstract": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.2.tgz", - "integrity": "sha512-YoxfFcDmhjOgWPWsV13+2RNjq1F6UQnfs+8TftwNqtzlmFzEXvlUwdrNrYeaizfjQzRMxkZ6ElWMOJIFKdVqwA==", + "version": "1.22.3", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.3.tgz", + "integrity": "sha512-eiiY8HQeYfYH2Con2berK+To6GrK2RxbPawDkGq4UiCQQfZHb6wX9qQqkbpPqaxQFcl8d9QzZqo0tGE0VcrdwA==", "dev": true, "dependencies": { "array-buffer-byte-length": "^1.0.0", "arraybuffer.prototype.slice": "^1.0.2", "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", + "call-bind": "^1.0.5", "es-set-tostringtag": "^2.0.1", "es-to-primitive": "^1.2.1", "function.prototype.name": "^1.1.6", - "get-intrinsic": "^1.2.1", + "get-intrinsic": "^1.2.2", "get-symbol-description": "^1.0.0", "globalthis": "^1.0.3", "gopd": "^1.0.1", - "has": "^1.0.3", "has-property-descriptors": "^1.0.0", "has-proto": "^1.0.1", "has-symbols": "^1.0.3", + "hasown": "^2.0.0", "internal-slot": "^1.0.5", "is-array-buffer": "^3.0.2", "is-callable": "^1.2.7", @@ -3299,7 +3311,7 @@ "is-string": "^1.0.7", "is-typed-array": "^1.1.12", "is-weakref": "^1.0.2", - "object-inspect": "^1.12.3", + "object-inspect": "^1.13.1", "object-keys": "^1.1.1", "object.assign": "^4.1.4", "regexp.prototype.flags": "^1.5.1", @@ -3313,7 +3325,7 @@ "typed-array-byte-offset": "^1.0.0", "typed-array-length": "^1.0.4", "unbox-primitive": "^1.0.2", - "which-typed-array": "^1.1.11" + "which-typed-array": "^1.1.13" }, "engines": { "node": ">= 0.4" @@ -3329,26 +3341,26 @@ "dev": true }, "node_modules/es-set-tostringtag": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz", - "integrity": "sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.2.tgz", + "integrity": "sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==", "dev": true, "dependencies": { - "get-intrinsic": "^1.1.3", - "has": "^1.0.3", - "has-tostringtag": "^1.0.0" + "get-intrinsic": "^1.2.2", + "has-tostringtag": "^1.0.0", + "hasown": "^2.0.0" }, "engines": { "node": ">= 0.4" } }, "node_modules/es-shim-unscopables": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", - "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.2.tgz", + "integrity": "sha512-J3yBRXCzDu4ULnQwxyToo/OjdMx6akgVC7K6few0a7F/0wLtmKKN7I73AH5T2836UuXRqN7Qg+IIUw/+YJksRw==", "dev": true, "dependencies": { - "has": "^1.0.3" + "hasown": "^2.0.0" } }, "node_modules/es-to-primitive": { @@ -3390,18 +3402,19 @@ } }, "node_modules/eslint": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.51.0.tgz", - "integrity": "sha512-2WuxRZBrlwnXi+/vFSJyjMqrNjtJqiasMzehF0shoLaW7DzS3/9Yvrmq5JiT66+pNjiX4UBnLDiKHcWAr/OInA==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", + "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.51.0", - "@humanwhocodes/config-array": "^0.11.11", + "@eslint/js": "8.52.0", + "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", + "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -3539,26 +3552,26 @@ } }, "node_modules/eslint-plugin-import": { - "version": "2.28.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.28.1.tgz", - "integrity": "sha512-9I9hFlITvOV55alzoKBI+K9q74kv0iKMeY6av5+umsNwayt59fz692daGyjR+oStBQgx6nwR9rXldDev3Clw+A==", + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.29.0.tgz", + "integrity": "sha512-QPOO5NO6Odv5lpoTkddtutccQjysJuFxoPS7fAHO+9m9udNHvTCPSAMW9zGAYj8lAIdr40I8yPCdUYrncXtrwg==", "dev": true, "dependencies": { - "array-includes": "^3.1.6", - "array.prototype.findlastindex": "^1.2.2", - "array.prototype.flat": "^1.3.1", - "array.prototype.flatmap": "^1.3.1", + "array-includes": "^3.1.7", + "array.prototype.findlastindex": "^1.2.3", + "array.prototype.flat": "^1.3.2", + "array.prototype.flatmap": "^1.3.2", "debug": "^3.2.7", "doctrine": "^2.1.0", - "eslint-import-resolver-node": "^0.3.7", + "eslint-import-resolver-node": "^0.3.9", "eslint-module-utils": "^2.8.0", - "has": "^1.0.3", - "is-core-module": "^2.13.0", + "hasown": "^2.0.0", + "is-core-module": "^2.13.1", "is-glob": "^4.0.3", "minimatch": "^3.1.2", - "object.fromentries": "^2.0.6", - "object.groupby": "^1.0.0", - "object.values": "^1.1.6", + "object.fromentries": "^2.0.7", + "object.groupby": "^1.0.1", + "object.values": "^1.1.7", "semver": "^6.3.1", "tsconfig-paths": "^3.14.2" }, @@ -3968,6 +3981,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true, + "bin": { + "flat": "cli.js" + } + }, "node_modules/flat-cache": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.1.1.tgz", @@ -4072,15 +4094,15 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", - "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", + "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", "dev": true, "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", + "function-bind": "^1.1.2", "has-proto": "^1.0.1", - "has-symbols": "^1.0.3" + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -4283,15 +4305,6 @@ "uglify-js": "^3.1.4" } }, - "node_modules/has": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz", - "integrity": "sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==", - "dev": true, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -4311,12 +4324,12 @@ } }, "node_modules/has-property-descriptors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", - "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", + "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", "dev": true, "dependencies": { - "get-intrinsic": "^1.1.1" + "get-intrinsic": "^1.2.2" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -4361,13 +4374,25 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/heap-typed": { - "version": "1.37.2", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.37.2.tgz", - "integrity": "sha512-zQXBfpZdCNnWETGKkxQmd14l8hiIk2HZ1rfmzjCb/OgfLDW3GiKVg5SPcn6FacsTqxLx8Y/ClQzpPeXZCOXtAQ==", + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", "dev": true, "dependencies": { - "data-structure-typed": "^1.37.2" + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/heap-typed": { + "version": "1.37.9", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.37.9.tgz", + "integrity": "sha512-oYkcappLoSb8Zs9gbMaUfIwsm2arykNoQ6gF28x1PQuKa0/a9zonEqqRN6dKlfOT28JIvqhnrSed039YDlZhrQ==", + "dev": true, + "dependencies": { + "data-structure-typed": "^1.37.9" } }, "node_modules/html-escaper": { @@ -4476,13 +4501,13 @@ } }, "node_modules/internal-slot": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.5.tgz", - "integrity": "sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.6.tgz", + "integrity": "sha512-Xj6dv+PsbtwyPpEflsejS+oIZxmMlV44zAhG479uYu89MsjcYOhCFnNyKrkJrihbsiasQyY0afoCl/9BLR65bg==", "dev": true, "dependencies": { - "get-intrinsic": "^1.2.0", - "has": "^1.0.3", + "get-intrinsic": "^1.2.2", + "hasown": "^2.0.0", "side-channel": "^1.0.4" }, "engines": { @@ -4559,12 +4584,12 @@ } }, "node_modules/is-core-module": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz", - "integrity": "sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==", + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", "dev": true, "dependencies": { - "has": "^1.0.3" + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -6520,9 +6545,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.0.tgz", - "integrity": "sha512-HQ4J+ic8hKrgIt3mqk6cVOVrW2ozL4KdvHlqpBv9vDYWx9ysAgENAdvy4FoGF+KFdhR7nQTNm5J0ctAeOwn+3g==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -7306,6 +7331,21 @@ "randombytes": "^2.1.0" } }, + "node_modules/set-function-length": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", + "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.1", + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/set-function-name": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.1.tgz", @@ -7630,9 +7670,9 @@ "dev": true }, "node_modules/terser": { - "version": "5.21.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.21.0.tgz", - "integrity": "sha512-WtnFKrxu9kaoXuiZFSGrcAvvBqAdmKx0SFNmVNYdJamMu9yyN3I/QF0FbH4QcqJQ+y1CJnzxGIKH0cSj+FGYRw==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.22.0.tgz", + "integrity": "sha512-hHZVLgRA2z4NWcN6aS5rQDc+7Dcy58HOf2zbYwmFcQ+ua3h6eEFf5lIDKTzbWwlazPyOZsFQO8V80/IjVNExEw==", "dev": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", @@ -8428,12 +8468,13 @@ } }, "node_modules/webpack-merge": { - "version": "5.9.0", - "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.9.0.tgz", - "integrity": "sha512-6NbRQw4+Sy50vYNTw7EyOn41OZItPiXB8GNv3INSoe3PSFaHJEz3SHTrYVaRm2LilNGnFUzh0FAwqPEmU/CwDg==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.10.0.tgz", + "integrity": "sha512-+4zXKdx7UnO+1jaN4l2lHVD+mFvnlZQP/6ljaJVb4SZiwIKeUnrT5l0gkT8z+n4hKpC+jpOv6O9R+gLtag7pSA==", "dev": true, "dependencies": { "clone-deep": "^4.0.1", + "flat": "^5.0.2", "wildcard": "^2.0.0" }, "engines": { @@ -8513,13 +8554,13 @@ } }, "node_modules/which-typed-array": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.11.tgz", - "integrity": "sha512-qe9UWWpkeG5yzZ0tNYxDmd7vo58HDBc39mZ0xWWpolAGADdFOzkfamWLDxkOWcvHQKVmdTyQdLD4NOfjLWTKew==", + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.13.tgz", + "integrity": "sha512-P5Nra0qjSncduVPEAr7xhoF5guty49ArDTwzJ/yNuPIbZppyRxFQsRCWrocxIY+CnMVG+qfbU2FmDKyvSGClow==", "dev": true, "dependencies": { "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", + "call-bind": "^1.0.4", "for-each": "^0.3.3", "gopd": "^1.0.1", "has-tostringtag": "^1.0.0" diff --git a/package.json b/package.json index 2fb8b95..53428ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.37.3", + "version": "1.37.9", "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.", "main": "dist/index.js", "module": "lib/index.js", @@ -27,16 +27,16 @@ "fix:src": "npm run lint:src && npm run format:src", "fix:test": "npm run lint:test && npm run format:test", "fix": "npm run fix:src && npm run fix:test", - "update:individuals": "npm i avl-tree-typed binary-tree-typed bst-typed heap-typed --save-dev", - "install:all-individuals": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev", + "update:subs": "npm i avl-tree-typed binary-tree-typed bst-typed heap-typed --save-dev", + "install:all-subs": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev", "test": "jest", "check:deps": "dependency-cruiser src", "changelog": "auto-changelog", "coverage:badge": "istanbul-badges-readme", - "ci": "env && git fetch --tags && npm run lint && npm run build && npm run update:individuals && npm run test && npm run changelog", - "publish:individuals": "sh scripts/publish_all_subs.sh", + "ci": "env && git fetch --tags && npm run lint && npm run build && npm run update:subs && npm run test && npm run changelog", + "publish:subs": "sh scripts/publish_all_subs.sh", "publish:docs": "sh scripts/publish_docs.sh", - "publish:all": "npm run ci && npm publish && npm run publish:individuals && npm run publish:docs" + "publish:all": "npm run ci && npm publish && npm run publish:subs && npm run publish:docs" }, "repository": { "type": "git", @@ -58,17 +58,17 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.37.2", + "avl-tree-typed": "^1.37.9", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.37.2", - "bst-typed": "^1.37.2", + "binary-tree-typed": "^1.37.9", + "bst-typed": "^1.37.9", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-alias": "^1.1.2", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", - "heap-typed": "^1.37.2", + "heap-typed": "^1.37.9", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", @@ -225,5 +225,8 @@ "tarjan", "Tarjan", "Tarjan's" - ] + ], + "dependencies": { + "data-structure-typed": "^1.37.5" + } } diff --git a/scripts/config.json b/scripts/config.json new file mode 100644 index 0000000..06383c9 --- /dev/null +++ b/scripts/config.json @@ -0,0 +1,5 @@ +{ + "sourceDir": "/Users/revone/projects/data-structure-typed", + "individualsDir": "/Users/revone/projects/data-structure-typed-individuals", + "docsDir": "/Users/revone/projects/data-structure-typed-docs" +} diff --git a/scripts/publish_all_subs.sh b/scripts/publish_all_subs.sh index 8ea802d..7b7da2f 100755 --- a/scripts/publish_all_subs.sh +++ b/scripts/publish_all_subs.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Read the version variable from config.json +source_dir_default=$(jq -r .sourceDir ./scripts/config.json) + +individuals_dir_default=$(jq -r .individualsDir ./scripts/config.json) + # Function to prompt for a directory path with a default value prompt_for_directory() { local message="$1" @@ -9,10 +14,12 @@ prompt_for_directory() { } # Prompt for the source directory path -source_dir=$(prompt_for_directory "Enter the source directory" "/Users/revone/projects/data-structure-typed") +#source_dir=$(prompt_for_directory "Enter the source directory" "$source_dir_default") +source_dir="$source_dir_default" # Prompt for the destination directory path -individuals_dir=$(prompt_for_directory "Enter the destination directory" "/Users/revone/projects/data-structure-typed-individuals") +#individuals_dir=$(prompt_for_directory "Enter the destination directory" "$individuals_dir_default") +individuals_dir="$individuals_dir_default" # Read the version variable from package.json diff --git a/scripts/publish_docs.sh b/scripts/publish_docs.sh index 414b02b..71b1853 100755 --- a/scripts/publish_docs.sh +++ b/scripts/publish_docs.sh @@ -1,5 +1,11 @@ #!/bin/bash + +# Read the version variable from config.json +source_dir_default=$(jq -r .sourceDir ./scripts/config.json) + +docs_dir_default=$(jq -r .docsDir ./scripts/config.json) + # Function to prompt for a directory path with a default value prompt_for_directory() { local message="$1" @@ -9,10 +15,12 @@ prompt_for_directory() { } # Prompt for the source directory path -source_dir=$(prompt_for_directory "Enter the source directory" "/Users/revone/projects/data-structure-typed") +#source_dir=$(prompt_for_directory "Enter the source directory" "$source_dir_default") +source_dir="$source_dir_default" -# Prompt for the destination directory path -docs_dir=$(prompt_for_directory "Enter the destination directory" "/Users/revone/projects/data-structure-typed-docs") +# Prompt for the docs directory path +#docs_dir=$(prompt_for_directory "Enter the docs directory" "$docs_dir_default") +docs_dir="$docs_dir_default" # Check if jq is installed and install it if needed if ! command -v jq &> /dev/null; then diff --git a/src/data-structures/binary-tree/binary-indexed-tree.ts b/src/data-structures/binary-tree/binary-indexed-tree.ts index b83b265..da9dae0 100644 --- a/src/data-structures/binary-tree/binary-indexed-tree.ts +++ b/src/data-structures/binary-tree/binary-indexed-tree.ts @@ -5,72 +5,294 @@ * @copyright Copyright (c) 2022 Tyler Zeng * @license MIT License */ +import {getMSB} from '../../utils'; + export class BinaryIndexedTree { + protected readonly _freq: number; + protected readonly _max: number; + /** - * The constructor initializes an array with a specified length and fills it with zeros. - * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The - * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array. - * The size of the sum tree array is `n + 1` because + * The constructor initializes the properties of an object, including default frequency, maximum + * value, a freqMap data structure, the most significant bit, and the count of negative frequencies. + * @param - - `frequency`: The default frequency value. It is optional and has a default + * value of 0. */ - constructor(n: number) { - this._sumTree = new Array(n + 1).fill(0); + constructor({frequency = 0, max}: {frequency?: number; max: number}) { + this._freq = frequency; + this._max = max; + this._freqMap = {0: 0}; + this._msb = getMSB(max); + this._negativeCount = frequency < 0 ? max : 0; } - private _sumTree: number[]; + protected _freqMap: Record; - get sumTree(): number[] { - return this._sumTree; + get freqMap(): Record { + return this._freqMap; } - static lowBit(x: number) { - return x & -x; + set freqMap(value: Record) { + this._freqMap = value; + } + + protected _msb: number; + + get msb(): number { + return this._msb; + } + + set msb(value: number) { + this._msb = value; + } + + protected _negativeCount: number; + + get negativeCount(): number { + return this._negativeCount; + } + + set negativeCount(value: number) { + this._negativeCount = value; + } + + get freq(): number { + return this._freq; + } + + get max(): number { + return this._max; } /** - * The update function updates the values in a binary indexed tree by adding a delta value to the specified index and - * its ancestors. - * @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be - * updated. - * @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element - * at index "i" in the "_sumTree" array. + * The function "readSingle" reads a single number from a specified index. + * @param {number} index - The `index` parameter is a number that represents the index of an element in a + * collection or array. + * @returns a number. */ - update(i: number, delta: number) { - while (i < this._sumTree.length) { - this._sumTree[i] += delta; - i += BinaryIndexedTree.lowBit(i); + readSingle(index: number): number { + this._checkIndex(index); + return this._readSingle(index); + } + + /** + * The "update" function updates the value at a given index by adding a delta and triggers a callback + * to notify of the change. + * @param {number} position - The `index` parameter represents the index of the element that needs to be + * updated in the data structure. + * @param {number} change - The "delta" parameter represents the change in value that needs to be + * applied to the frequency at the specified index. + */ + update(position: number, change: number): void { + this._checkIndex(position); + const freqCur = this._readSingle(position); + + this._update(position, change); + this._updateNegativeCount(freqCur, freqCur + change); + } + + /** + * The function "writeSingle" checks the index and writes a single value with a given frequency. + * @param {number} index - The `index` parameter is a number that represents the index of an element. It + * is used to identify the specific element that needs to be written. + * @param {number} freq - The `freq` parameter represents the frequency value that needs to be + * written. + */ + writeSingle(index: number, freq: number): void { + this._checkIndex(index); + this._writeSingle(index, freq); + } + + /** + * The read function takes a count parameter, checks if it is an integer, and returns the result of + * calling the _read function with the count parameter clamped between 0 and the maximum value. + * @param {number} count - The `count` parameter is a number that represents the number of items to + * read. + * @returns a number. + */ + read(count: number): number { + if (!Number.isInteger(count)) { + throw new Error('Invalid count'); + } + return this._read(Math.max(Math.min(count, this.max), 0)); + } + + /** + * The function returns the lower bound of a non-descending sequence that sums up to a given number. + * @param {number} sum - The `sum` parameter is a number that represents the target sum that we want + * to find in the sequence. + * @returns The lowerBound function is returning a number. + */ + lowerBound(sum: number): number { + if (this.negativeCount > 0) { + throw new Error('Sequence is not non-descending'); + } + return this._binarySearch(sum, (x, y) => x < y); + } + + /** + * The upperBound function returns the index of the first element in a sequence that is greater than + * or equal to a given sum. + * @param {number} sum - The "sum" parameter is a number that represents the target sum that we want + * to find in the sequence. + * @returns The upperBound function is returning a number. + */ + upperBound(sum: number): number { + if (this.negativeCount > 0) { + throw new Error('Must not be descending'); + } + return this._binarySearch(sum, (x, y) => x <= y); + } + + /** + * The function returns the value of a specific index in a freqMap data structure, or a default value if + * the index is not found. + * @param {number} index - The `index` parameter is a number that represents the index of a node in a + * freqMap data structure. + * @returns a number. + */ + protected _getFrequency(index: number): number { + if (index in this.freqMap) { + return this.freqMap[index]; + } + + return this.freq * (index & -index); + } + + /** + * The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array. + * @param {number} index - The index parameter is a number that represents the index of the freqMap + * element that needs to be updated. + * @param {number} delta - The `delta` parameter represents the change in value that needs to be + * added to the freqMap at the specified `index`. + */ + protected _updateFrequency(index: number, delta: number): void { + this.freqMap[index] = this._getFrequency(index) + delta; + } + + /** + * The function checks if the given index is valid and within the range. + * @param {number} index - The parameter "index" is of type number and represents the index value + * that needs to be checked. + */ + protected _checkIndex(index: number): void { + if (!Number.isInteger(index)) { + throw new Error('Invalid index: Index must be an integer.'); + } + if (index < 0 || index >= this.max) { + throw new Error('Index out of range: Index must be within the range [0, this.max).'); } } /** - * The function calculates the prefix sum of an array using a binary indexed tree. - * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the - * array for which we want to calculate the prefix sum. - * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index - * `i`. + * The function calculates the sum of elements in an array up to a given index using a binary indexed + * freqMap. + * @param {number} index - The `index` parameter is a number that represents the index of an element in a + * data structure. + * @returns a number. */ - getPrefixSum(i: number) { - let sum = 0; - while (i > 0) { - sum += this._sumTree[i]; - i -= BinaryIndexedTree.lowBit(i); + protected _readSingle(index: number): number { + index = index + 1; + let sum = this._getFrequency(index); + const z = index - (index & -index); + + index--; + + while (index !== z) { + sum -= this._getFrequency(index); + index -= index & -index; } + return sum; } /** - * The function `getRangeSum` calculates the sum of a range of numbers in an array. - * @param {number} start - The start parameter is the starting index of the range for which we want to calculate the - * sum. - * @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate - * the sum. - * @returns the sum of the elements in the range specified by the start and end indices. + * The function `_updateNegativeCount` updates a counter based on changes in frequency values. + * @param {number} freqCur - The current frequency value. + * @param {number} freqNew - The freqNew parameter represents the new frequency value. */ - getRangeSum(start: number, end: number): number { - if (!(0 <= start && start <= end && end <= this._sumTree.length)) throw 'Index out of bounds'; - return this.getPrefixSum(end) - this.getPrefixSum(start); + protected _updateNegativeCount(freqCur: number, freqNew: number): void { + if (freqCur < 0 && freqNew >= 0) { + this.negativeCount--; + } else if (freqCur >= 0 && freqNew < 0) { + this.negativeCount++; + } } - protected _setSumTree(value: number[]) { - this._sumTree = value; + /** + * The `_update` function updates the values in a binary indexed freqMap starting from a given index and + * propagating the changes to its parent nodes. + * @param {number} index - The `index` parameter is a number that represents the index of the element in + * the data structure that needs to be updated. + * @param {number} delta - The `delta` parameter represents the change in value that needs to be + * applied to the elements in the data structure. + */ + protected _update(index: number, delta: number): void { + index = index + 1; + + while (index <= this.max) { + this._updateFrequency(index, delta); + index += index & -index; + } + } + + /** + * The `_writeSingle` function updates the frequency at a specific index and triggers a callback if + * the frequency has changed. + * @param {number} index - The `index` parameter is a number that represents the index of the element + * being modified or accessed. + * @param {number} freq - The `freq` parameter represents the new frequency value that needs to be + * written to the specified index `index`. + */ + protected _writeSingle(index: number, freq: number): void { + const freqCur = this._readSingle(index); + + this._update(index, freq - freqCur); + this._updateNegativeCount(freqCur, freq); + } + + /** + * The `_read` function calculates the sum of values in a binary freqMap up to a given count. + * @param {number} count - The `count` parameter is a number that represents the number of elements + * to read from the freqMap. + * @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the + * range from `count` to 1. + */ + protected _read(count: number): number { + let index = count; + let sum = 0; + while (index) { + sum += this._getFrequency(index); + index -= index & -index; + } + + return sum; + } + + /** + * The function `_binarySearch` performs a binary search to find the largest number that satisfies a given + * condition. + * @param {number} sum - The sum parameter is a number that represents the target sum value. + * @param before - The `before` parameter is a function that takes two numbers `x` and `y` as + * arguments and returns a boolean value. It is used to determine if `x` is less than or equal to + * `y`. The purpose of this function is to compare two numbers and determine their order. + * @returns the value of the variable "left". + */ + protected _binarySearch(sum: number, before: (x: number, y: number) => boolean): number { + let left = 0; + let right = this.msb << 1; + let sumT = sum; + + while (right > left + 1) { + const middle = (left + right) >> 1; + const sumM = this._getFrequency(middle); + + if (middle <= this.max && before(sumM, sumT)) { + sumT -= sumM; + left = middle; + } else { + right = middle; + } + } + return left; } } diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 7de5b1c..e654f31 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -134,7 +134,7 @@ export class BinaryTree = BinaryTreeNode> */ constructor(options?: BinaryTreeOptions) { if (options !== undefined) { - const { iterationType = IterationType.ITERATIVE } = options; + const {iterationType = IterationType.ITERATIVE} = options; this._loopType = iterationType; } } @@ -191,7 +191,7 @@ export class BinaryTree = BinaryTreeNode> * @returns {N} - The destination node after the swap. */ protected _swap(srcNode: N, destNode: N): N { - const { key, val } = destNode; + const {key, val} = destNode; const tempNode = this.createNode(key, val); if (tempNode) { @@ -322,7 +322,6 @@ export class BinaryTree = BinaryTreeNode> return keysOrNodes.length === this.addMany(keysOrNodes, data).length; } - /** * The `delete` function removes a node from a binary search tree and returns the deleted node along * with the parent node that needs to be balanced. diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 82ff5df..f9bd32b 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -25,7 +25,6 @@ export class BSTNode = BSTNodeNested< } export class BST = BSTNode> extends BinaryTree implements IBinaryTree { - /** * The constructor function initializes a binary search tree object with an optional comparator * function. @@ -144,7 +143,12 @@ export class BST = BSTNode> extends BinaryTree * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values. */ - override addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd = true, iterationType = this.iterationType): (N | null | undefined)[] { + override addMany( + keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], + data?: N['val'][], + isBalanceAdd = true, + iterationType = this.iterationType + ): (N | null | undefined)[] { // TODO this addMany function is inefficient, it should be optimized function hasNoNull(arr: (BinaryTreeNodeKey | null)[] | (N | null)[]): arr is BinaryTreeNodeKey[] | N[] { return arr.indexOf(null) === -1; @@ -230,7 +234,12 @@ export class BST = BSTNode> extends BinaryTree * @returns either the first node that matches the given nodeProperty and callback, or null if no * matching node is found. */ - override get(nodeProperty: BinaryTreeNodeKey | N, callback: MapCallback = this._defaultCallbackByKey,beginRoot = this.root, iterationType = this.iterationType): N | null { + override get( + nodeProperty: BinaryTreeNodeKey | N, + callback: MapCallback = this._defaultCallbackByKey, + beginRoot = this.root, + iterationType = this.iterationType + ): N | null { return this.getNodes(nodeProperty, callback, true, beginRoot, iterationType)[0] ?? null; } diff --git a/src/data-structures/heap/heap.ts b/src/data-structures/heap/heap.ts index 09cc63c..55bbbf1 100644 --- a/src/data-structures/heap/heap.ts +++ b/src/data-structures/heap/heap.ts @@ -5,8 +5,7 @@ * @license MIT License */ -import type {Comparator} from '../../types'; -import {DFSOrderPattern} from '../../types'; +import type {Comparator, DFSOrderPattern} from '../../types'; export class Heap { protected nodes: E[] = []; diff --git a/src/types/data-structures/avl-tree.ts b/src/types/data-structures/binary-tree/avl-tree.ts similarity index 94% rename from src/types/data-structures/avl-tree.ts rename to src/types/data-structures/binary-tree/avl-tree.ts index 16f86f7..611a467 100644 --- a/src/types/data-structures/avl-tree.ts +++ b/src/types/data-structures/binary-tree/avl-tree.ts @@ -1,4 +1,4 @@ -import {AVLTreeNode} from '../../data-structures'; +import {AVLTreeNode} from '../../../data-structures'; import {BSTOptions} from './bst'; export type AVLTreeNodeNested = AVLTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/src/types/data-structures/doubly-linked-list.ts b/src/types/data-structures/binary-tree/binary-indexed-tree.ts similarity index 100% rename from src/types/data-structures/doubly-linked-list.ts rename to src/types/data-structures/binary-tree/binary-indexed-tree.ts diff --git a/src/types/data-structures/binary-tree.ts b/src/types/data-structures/binary-tree/binary-tree.ts similarity index 80% rename from src/types/data-structures/binary-tree.ts rename to src/types/data-structures/binary-tree/binary-tree.ts index e392a52..4d0e908 100644 --- a/src/types/data-structures/binary-tree.ts +++ b/src/types/data-structures/binary-tree/binary-tree.ts @@ -1,4 +1,4 @@ -import {BinaryTreeNode} from '../../data-structures/binary-tree'; +import {BinaryTreeNode} from '../../../data-structures'; /** * Enum representing different loop types. @@ -22,26 +22,14 @@ export enum FamilyPosition { MAL_NODE = 'MAL_NODE' } -export type BinaryTreeNodePropertyName = 'key' | 'val'; - -export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName; - export type BinaryTreeNodeKey = number; export type BFSCallback = (node: N, level?: number) => any; export type BFSCallbackReturn = ReturnType>; -export type BinaryTreeNodeProperty> = - | N['val'] - | N - | number - | BinaryTreeNodeKey; export type BinaryTreeDeletedResult = { deleted: N | null | undefined; needBalanced: N | null }; -export type BinaryTreeNodeProperties> = - BinaryTreeNodeProperty[]; - export type BinaryTreeNodeNested = BinaryTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> export type BinaryTreeOptions = { iterationType?: IterationType } diff --git a/src/types/data-structures/bst.ts b/src/types/data-structures/binary-tree/bst.ts similarity index 88% rename from src/types/data-structures/bst.ts rename to src/types/data-structures/binary-tree/bst.ts index 88bb72a..5d60225 100644 --- a/src/types/data-structures/bst.ts +++ b/src/types/data-structures/binary-tree/bst.ts @@ -1,4 +1,4 @@ -import {BSTNode} from '../../data-structures/binary-tree'; +import {BSTNode} from '../../../data-structures'; import type {BinaryTreeNodeKey, BinaryTreeOptions} from './binary-tree'; export type BSTComparator = (a: BinaryTreeNodeKey, b: BinaryTreeNodeKey) => number; @@ -9,5 +9,3 @@ export type BSTNodeNested = BSTNode = RBTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -export type RBTreeOptions = BinaryTreeOptions & {} \ No newline at end of file +export type RBTreeOptions = BinaryTreeOptions & {} diff --git a/src/types/data-structures/segment-tree.ts b/src/types/data-structures/binary-tree/segment-tree.ts similarity index 100% rename from src/types/data-structures/segment-tree.ts rename to src/types/data-structures/binary-tree/segment-tree.ts diff --git a/src/types/data-structures/tree-multiset.ts b/src/types/data-structures/binary-tree/tree-multiset.ts similarity index 94% rename from src/types/data-structures/tree-multiset.ts rename to src/types/data-structures/binary-tree/tree-multiset.ts index 47c26a4..ad14629 100644 --- a/src/types/data-structures/tree-multiset.ts +++ b/src/types/data-structures/binary-tree/tree-multiset.ts @@ -1,4 +1,4 @@ -import {TreeMultisetNode} from '../../data-structures/binary-tree'; +import {TreeMultisetNode} from '../../../data-structures'; import {AVLTreeOptions} from './avl-tree'; export type TreeMultisetNodeNested = TreeMultisetNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/src/types/data-structures/abstract-graph.ts b/src/types/data-structures/graph/abstract-graph.ts similarity index 100% rename from src/types/data-structures/abstract-graph.ts rename to src/types/data-structures/graph/abstract-graph.ts diff --git a/src/types/data-structures/directed-graph.ts b/src/types/data-structures/graph/directed-graph.ts similarity index 100% rename from src/types/data-structures/directed-graph.ts rename to src/types/data-structures/graph/directed-graph.ts diff --git a/src/types/data-structures/graph/index.ts b/src/types/data-structures/graph/index.ts new file mode 100644 index 0000000..4ff9af0 --- /dev/null +++ b/src/types/data-structures/graph/index.ts @@ -0,0 +1,3 @@ +export * from './abstract-graph'; +export * from './map-graph'; +export * from './directed-graph'; diff --git a/src/types/data-structures/map-graph.ts b/src/types/data-structures/graph/map-graph.ts similarity index 100% rename from src/types/data-structures/map-graph.ts rename to src/types/data-structures/graph/map-graph.ts diff --git a/src/types/data-structures/heap.ts b/src/types/data-structures/graph/undirected-graph.ts similarity index 100% rename from src/types/data-structures/heap.ts rename to src/types/data-structures/graph/undirected-graph.ts diff --git a/src/types/data-structures/singly-linked-list.ts b/src/types/data-structures/hash/coordinate-map.ts similarity index 100% rename from src/types/data-structures/singly-linked-list.ts rename to src/types/data-structures/hash/coordinate-map.ts diff --git a/src/types/data-structures/hash/coordinate-set.ts b/src/types/data-structures/hash/coordinate-set.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/hash/coordinate-set.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/hash/hash-map.ts b/src/types/data-structures/hash/hash-map.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/hash/hash-map.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/hash/hash-table.ts b/src/types/data-structures/hash/hash-table.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/hash/hash-table.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/hash.ts b/src/types/data-structures/hash/index.ts similarity index 100% rename from src/types/data-structures/hash.ts rename to src/types/data-structures/hash/index.ts diff --git a/src/types/data-structures/hash/tree-map.ts b/src/types/data-structures/hash/tree-map.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/hash/tree-map.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/hash/tree-set.ts b/src/types/data-structures/hash/tree-set.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/hash/tree-set.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/heap/heap.ts b/src/types/data-structures/heap/heap.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/heap/heap.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/heap/index.ts b/src/types/data-structures/heap/index.ts new file mode 100644 index 0000000..0126870 --- /dev/null +++ b/src/types/data-structures/heap/index.ts @@ -0,0 +1 @@ +export * from './heap'; diff --git a/src/types/data-structures/heap/max-heap.ts b/src/types/data-structures/heap/max-heap.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/heap/max-heap.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/heap/min-heap.ts b/src/types/data-structures/heap/min-heap.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/heap/min-heap.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/index.ts b/src/types/data-structures/index.ts index 8ad00d7..4083893 100644 --- a/src/types/data-structures/index.ts +++ b/src/types/data-structures/index.ts @@ -1,17 +1,11 @@ export * from './binary-tree'; -export * from './bst'; -export * from './avl-tree'; -export * from './segment-tree'; -export * from './tree-multiset'; -export * from './abstract-graph'; -export * from './map-graph'; -export * from './rb-tree'; -export * from './directed-graph'; +export * from './graph'; +export * from './linked-list'; export * from './heap'; -export * from './singly-linked-list'; -export * from './doubly-linked-list'; -export * from './navigator'; +export * from './matrix'; export * from './hash'; - -export type MapCallback = (node: N) => any; -export type MapCallbackReturn = ReturnType>; +export * from './priority-queue'; +export * from './queue'; +export * from './stack'; +export * from './tree'; +export * from './trie'; diff --git a/src/types/data-structures/linked-list/doubly-linked-list.ts b/src/types/data-structures/linked-list/doubly-linked-list.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/linked-list/doubly-linked-list.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/linked-list/index.ts b/src/types/data-structures/linked-list/index.ts new file mode 100644 index 0000000..0bdd0b6 --- /dev/null +++ b/src/types/data-structures/linked-list/index.ts @@ -0,0 +1,2 @@ +export * from './singly-linked-list'; +export * from './doubly-linked-list'; diff --git a/src/types/data-structures/linked-list/singly-linked-list.ts b/src/types/data-structures/linked-list/singly-linked-list.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/linked-list/singly-linked-list.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/linked-list/skip-linked-list.ts b/src/types/data-structures/linked-list/skip-linked-list.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/linked-list/skip-linked-list.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/matrix/index.ts b/src/types/data-structures/matrix/index.ts new file mode 100644 index 0000000..8716d60 --- /dev/null +++ b/src/types/data-structures/matrix/index.ts @@ -0,0 +1 @@ +export * from './navigator'; diff --git a/src/types/data-structures/matrix/matrix.ts b/src/types/data-structures/matrix/matrix.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/matrix/matrix.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/matrix/matrix2d.ts b/src/types/data-structures/matrix/matrix2d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/matrix/matrix2d.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/navigator.ts b/src/types/data-structures/matrix/navigator.ts similarity index 100% rename from src/types/data-structures/navigator.ts rename to src/types/data-structures/matrix/navigator.ts diff --git a/src/types/data-structures/matrix/vector2d.ts b/src/types/data-structures/matrix/vector2d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/matrix/vector2d.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/priority-queue/index.ts b/src/types/data-structures/priority-queue/index.ts new file mode 100644 index 0000000..abfb1a8 --- /dev/null +++ b/src/types/data-structures/priority-queue/index.ts @@ -0,0 +1,3 @@ +export * from './priority-queue'; +export * from './min-priority-queue'; +export * from './max-priority-queue'; diff --git a/src/types/data-structures/priority-queue/max-priority-queue.ts b/src/types/data-structures/priority-queue/max-priority-queue.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/priority-queue/max-priority-queue.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/priority-queue/min-priority-queue.ts b/src/types/data-structures/priority-queue/min-priority-queue.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/priority-queue/min-priority-queue.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/priority-queue/priority-queue.ts b/src/types/data-structures/priority-queue/priority-queue.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/priority-queue/priority-queue.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/queue/deque.ts b/src/types/data-structures/queue/deque.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/queue/deque.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/queue/index.ts b/src/types/data-structures/queue/index.ts new file mode 100644 index 0000000..42a184f --- /dev/null +++ b/src/types/data-structures/queue/index.ts @@ -0,0 +1,2 @@ +export * from './queue'; +export * from './deque'; diff --git a/src/types/data-structures/queue/queue.ts b/src/types/data-structures/queue/queue.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/queue/queue.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/stack/index.ts b/src/types/data-structures/stack/index.ts new file mode 100644 index 0000000..d39a8e6 --- /dev/null +++ b/src/types/data-structures/stack/index.ts @@ -0,0 +1 @@ +export * from './stack'; diff --git a/src/types/data-structures/stack/stack.ts b/src/types/data-structures/stack/stack.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/stack/stack.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/tree/index.ts b/src/types/data-structures/tree/index.ts new file mode 100644 index 0000000..50842b5 --- /dev/null +++ b/src/types/data-structures/tree/index.ts @@ -0,0 +1 @@ +export * from './tree'; diff --git a/src/types/data-structures/tree/tree.ts b/src/types/data-structures/tree/tree.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/tree/tree.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/data-structures/trie/index.ts b/src/types/data-structures/trie/index.ts new file mode 100644 index 0000000..8d6f206 --- /dev/null +++ b/src/types/data-structures/trie/index.ts @@ -0,0 +1 @@ +export * from './trie'; diff --git a/src/types/data-structures/trie/trie.ts b/src/types/data-structures/trie/trie.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/types/data-structures/trie/trie.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/types/helpers.ts b/src/types/helpers.ts index f1991de..35c570b 100644 --- a/src/types/helpers.ts +++ b/src/types/helpers.ts @@ -1,4 +1,9 @@ export type Comparator = (a: T, b: T) => number; -// export enum DFSOrderPattern {'pre' = 'pre', 'in' = 'in', 'post' = 'post'} export type DFSOrderPattern = 'pre' | 'in' | 'post'; + +export type MapCallback = (node: N) => any; + +export type MapCallbackReturn = ReturnType>; + +export enum CP {lt = 'lt', eq = 'eq', gt = 'gt'} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 392d7e4..37fed27 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -77,3 +77,10 @@ export const trampolineAsync = (fn: TrlAsyncFn) => { {cont} ); }; + +export const getMSB = (value: number): number => { + if (value <= 0) { + return 0; + } + return 1 << (31 - Math.clz32(value)); +}; diff --git a/test/config.js b/test/config.js new file mode 100644 index 0000000..1b96349 --- /dev/null +++ b/test/config.js @@ -0,0 +1,4 @@ +'use strict'; +Object.defineProperty(exports, '__esModule', {value: true}); +exports.isDebugTest = void 0; +exports.isDebugTest = false; diff --git a/test/types/index.js b/test/types/index.js new file mode 100644 index 0000000..c040865 --- /dev/null +++ b/test/types/index.js @@ -0,0 +1,29 @@ +'use strict'; +var __createBinding = + (this && this.__createBinding) || + (Object.create + ? function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { + enumerable: true, + get: function () { + return m[k]; + } + }; + } + Object.defineProperty(o, k2, desc); + } + : function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; + }); +var __exportStar = + (this && this.__exportStar) || + function (m, exports) { + for (var p in m) + if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); + }; +Object.defineProperty(exports, '__esModule', {value: true}); +__exportStar(require('./utils'), exports); diff --git a/test/types/utils/big-o.js b/test/types/utils/big-o.js new file mode 100644 index 0000000..38813da --- /dev/null +++ b/test/types/utils/big-o.js @@ -0,0 +1,2 @@ +'use strict'; +Object.defineProperty(exports, '__esModule', {value: true}); diff --git a/test/types/utils/index.js b/test/types/utils/index.js new file mode 100644 index 0000000..a48da0c --- /dev/null +++ b/test/types/utils/index.js @@ -0,0 +1,29 @@ +'use strict'; +var __createBinding = + (this && this.__createBinding) || + (Object.create + ? function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { + enumerable: true, + get: function () { + return m[k]; + } + }; + } + Object.defineProperty(o, k2, desc); + } + : function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; + }); +var __exportStar = + (this && this.__exportStar) || + function (m, exports) { + for (var p in m) + if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); + }; +Object.defineProperty(exports, '__esModule', {value: true}); +__exportStar(require('./big-o'), exports); diff --git a/test/unit/data-structures/binary-tree/binary-index-tree.test.ts b/test/unit/data-structures/binary-tree/binary-index-tree.test.ts new file mode 100644 index 0000000..1e43598 --- /dev/null +++ b/test/unit/data-structures/binary-tree/binary-index-tree.test.ts @@ -0,0 +1,284 @@ +import {BinaryIndexedTree} from '../../../../src'; +import {isDebugTest} from '../../../config'; + +const isDebug = isDebugTest; + +describe('BinaryIndexedTree simple', () => { + let bit: BinaryIndexedTree; + + beforeEach(() => { + //Create a new BinaryIndexedTree instance before each test case + bit = new BinaryIndexedTree({frequency: 0, max: 10}); // Modify the value of max as needed + }); + + it('should initialize correctly', () => { + expect(bit.freq).toBe(0); + expect(bit.max).toBe(10); + expect(bit.freqMap).toEqual({0: 0}); // Modify the initialized record value according to the actual situation + // More initialization checks can be added + }); + + it('should read a single value correctly', () => { + // Test the function of reading a single value + bit.writeSingle(5, 5); //Write test data + expect(bit.readSingle(5)).toBe(5); // Read and verify + }); + + it('should update a value correctly', () => { + // Test the ability to update a single value + bit.writeSingle(5, 5); //Write test data + bit.update(5, 2); // update value + expect(bit.readSingle(5)).toBe(7); // Verify the updated value + }); + + it('should find lower bound correctly', () => { + //Test the function of finding the lower bound + bit.writeSingle(2, 10); + bit.writeSingle(5, 20); + bit.writeSingle(8, 30); + expect(bit.lowerBound(15)).toBe(5); // Find and verify the lower bound + }); + + it('should find upper bound correctly', () => { + //Test the function of finding the upper bound + bit.writeSingle(2, 10); + bit.writeSingle(5, 20); + bit.writeSingle(8, 30); + expect(bit.upperBound(25)).toBe(5); // Find and verify the upper bound + }); +}); + +describe('BinaryIndexedTree', () => { + const frequency = 999; + const max = 10; + let bit: BinaryIndexedTree; + + beforeEach(function () { + bit = new BinaryIndexedTree({frequency, max}); + }); + it('should validate the index', function () { + expect(() => bit.readSingle(-1)).toThrow('Index out of range'); + expect(() => bit.readSingle(10)).toThrow('Index out of range'); + }); + + it('should read a single frequency correctly', function () { + for (let i = 0; i < max; i++) { + expect(bit.readSingle(i)).toBe(frequency); + } + }); + it('should validate the index', function () { + expect(() => bit.update(-1, 100)).toThrow('Index out of range'); + expect(() => bit.update(10, 100)).toThrow('Index out of range'); + }); + it('should frequency and max', function () { + const frequency = 200; + const max = 1000; + const bit = new BinaryIndexedTree({frequency, max}); + + expect(bit.freq).toBe(frequency); + expect(bit.max).toBe(max); + }); + + it('should update the frequency with the given delta', function () { + for (let i = 0; i < max; i++) { + bit.update(i, i * 2); + } + for (let i = 0; i < max; i++) { + expect(bit.readSingle(i)).toBe(i * 2 + frequency); + } + }); + it('should validate the index', function () { + expect(() => bit.writeSingle(-1, 100)).toThrow('Index out of range'); + expect(() => bit.writeSingle(10, 100)).toThrow('Index out of range'); + }); + + it('should writeSingle to be correctly invoked', function () { + for (let i = 0; i < max; i++) { + bit.writeSingle(i, i * 2); + } + for (let i = 0; i < max; i++) { + expect(bit.readSingle(i)).toBe(i * 2); + } + }); + + it('should read the frequency', function () { + for (let c = 0; c <= max; c++) { + expect(bit.read(c)).toBe(c * frequency); + } + }); + + const values = [-5, 0, 5, 10, 95, 100, 1000]; + it('should find the upper-bound index', function () { + loopUpperBoundTests(bit, values); + }); + + it('should find the lower-bound index', function () { + loopLowerBoundTests(bit, values); + }); +}); + +describe('designated values', function () { + const array = [1, 8, 6, 10, 7, 9, 0, 2, 6, 3]; + const sumArray = (sum => array.map(value => (sum += value)))(0); + let bit: BinaryIndexedTree; + + beforeEach(function () { + bit = new BinaryIndexedTree({max: array.length}); + array.forEach((value, i) => bit.writeSingle(i, value)); + }); + + describe('readSingle', function () { + it('should read a single frequency correctly', function () { + array.forEach((value, i) => { + expect(bit.readSingle(i)).toBe(array[i]); + }); + }); + }); + + describe('update', function () { + it('should update the frequency with the given delta', function () { + array.forEach((value, i) => bit.update(i, value + i)); + array.forEach((value, i) => { + expect(bit.readSingle(i)).toBe(array[i] * 2 + i); + }); + }); + }); + + describe('writeSingle', function () { + it('should write a single frequency correctly', function () { + array.forEach((value, i) => bit.writeSingle(i, value + i)); + array.forEach((value, i) => { + expect(bit.readSingle(i)).toBe(array[i] + i); + }); + }); + }); + + describe('read', function () { + it('should read the cumulative frequency correctly', function () { + expect(bit.read(0)).toBe(0); + sumArray.forEach((sum, i) => { + expect(bit.read(i + 1)).toBe(sum); + }); + }); + }); + + const values = [-5, 0, 15, 25, 43, 53, 100]; + + describe('upperBound', function () { + it('should find the upper-bound index', function () { + loopUpperBoundTests(bit, values); + }); + }); + + describe('lowerBound', function () { + it('should find the lower-bound index', function () { + loopLowerBoundTests(bit, values); + }); + }); +}); + +describe('descending sequence', function () { + const array = [1, 8, -6, 10, 7, 9, 0, -2, 6, 3]; + let bit: BinaryIndexedTree; + + beforeEach(function () { + bit = new BinaryIndexedTree({max: array.length}); + array.forEach((value, i) => bit.writeSingle(i, value)); + }); + + it('should have a correct negativeCount property', function () { + expect(bit.negativeCount).toBe(2); + bit.update(2, 6); + expect(bit.negativeCount).toBe(1); + bit.update(7, 3); + expect(bit.negativeCount).toBe(0); + bit.update(8, -7); + expect(bit.negativeCount).toBe(1); + }); + + const values = [-5, 0, 15, 25, 43, 53, 100]; + + describe('upperBound', function () { + it('should validate the non-descending', function () { + expect(() => bit.upperBound(20)).toThrow('Must not be descending'); + bit.update(2, 12); + bit.update(7, 4); + loopUpperBoundTests(bit, values); + }); + }); + + describe('BinaryIndexedTree lowerBound', function () { + it('should validate the non-descending', function () { + expect(() => bit.lowerBound(20)).toThrow('Sequence is not non-descending'); + bit.update(2, 12); + bit.update(7, 4); + loopLowerBoundTests(bit, values); + }); + }); +}); + +describe('BinaryIndexedTree additional tests', () => { + it('should handle read method correctly', () => { + const bit = new BinaryIndexedTree({max: 10}); + bit.writeSingle(2, 10); + bit.writeSingle(5, 20); + bit.writeSingle(8, 30); + expect(bit.read(5)).toBe(10); // Ensure read method accumulates correctly + }); + + it('should handle consecutive operations', () => { + const bit = new BinaryIndexedTree({max: 10}); + bit.writeSingle(2, 10); + bit.update(2, 5); + expect(bit.readSingle(2)).toBe(15); + bit.writeSingle(5, 20); + expect(bit.readSingle(5)).toBe(20); + expect(bit.lowerBound(15)).toBe(2); + }); + + it('should handle frequent increment updates', () => { + const bit = new BinaryIndexedTree({max: 10}); + for (let i = 0; i < 10; i++) { + bit.update(2, 5); + } + expect(bit.readSingle(2)).toBe(50); + }); + + it('should handle edge cases', () => { + const bit = new BinaryIndexedTree({max: 10}); + bit.writeSingle(9, 100); + expect(bit.readSingle(9)).toBe(100); + expect(bit.lowerBound(200)).toBe(10); + }); +}); +function loopUpperBoundTests(bit: BinaryIndexedTree, values: number[]) { + for (const value of values) { + const index = bit.upperBound(value); + if (index > 0) { + expect(bit.read(index)).toBeLessThanOrEqual(value); + } else { + expect(index).toBe(0); + } + if (index < bit.max) { + expect(bit.read(index + 1)).toBeGreaterThan(value); + } else { + expect(index).toBe(bit.max); + } + } +} + +function loopLowerBoundTests(bit: BinaryIndexedTree, values: number[]) { + for (const value of values) { + const index = bit.lowerBound(value); + if (index > 0) { + expect(bit.read(index)).toBeLessThan(value); + } else { + expect(index).toBe(0); + } + if (index < bit.max) { + expect(bit.read(index + 1)).toBeGreaterThanOrEqual(value); + } else { + expect(index).toBe(bit.max); + } + } +} diff --git a/test/utils/big-o.js b/test/utils/big-o.js new file mode 100644 index 0000000..099b7ec --- /dev/null +++ b/test/utils/big-o.js @@ -0,0 +1,212 @@ +'use strict'; +Object.defineProperty(exports, '__esModule', {value: true}); +exports.logBigOMetrics = exports.logBigOMetricsWrap = exports.bigO = exports.magnitude = void 0; +var config_1 = require('../config'); + +var isDebug = config_1.isDebugTest; +var orderReducedBy = 2; // reduction of bigO's order compared to the baseline bigO +exports.magnitude = { + CONSTANT: Math.floor(Number.MAX_SAFE_INTEGER / Math.pow(10, orderReducedBy)), + LOG_N: Math.pow(10, 9 - orderReducedBy), + LINEAR: Math.pow(10, 6 - orderReducedBy), + N_LOG_N: Math.pow(10, 5 - orderReducedBy), + SQUARED: Math.pow(10, 4 - orderReducedBy), + CUBED: Math.pow(10, 3 - orderReducedBy), + FACTORIAL: 20 - orderReducedBy +}; +exports.bigO = { + CONSTANT: exports.magnitude.CONSTANT / 100000, + LOG_N: Math.log2(exports.magnitude.LOG_N) / 1000, + LINEAR: exports.magnitude.LINEAR / 1000, + N_LOG_N: (exports.magnitude.N_LOG_N * Math.log2(exports.magnitude.LOG_N)) / 1000, + SQUARED: Math.pow(exports.magnitude.SQUARED, 2) / 1000, + CUBED: Math.pow(exports.magnitude.SQUARED, 3) / 1000, + FACTORIAL: 10000 +}; +function findPotentialN(input) { + var longestArray = []; + var mostProperties = {}; + function recurse(obj) { + if (Array.isArray(obj)) { + if (obj.length > longestArray.length) { + longestArray = obj; + } + } else if (typeof obj === 'object' && obj !== null) { + var keys = Object.keys(obj); + if (keys.length > Object.keys(mostProperties).length) { + mostProperties = obj; + } + keys.forEach(function (key) { + recurse(obj[key]); + }); + } + } + if (Array.isArray(input)) { + input.forEach(function (item) { + recurse(item); + }); + } else { + recurse(input); + } + // return [longestArray, mostProperties] : [any[], { [key: string]: any }]; + return Math.max(longestArray.length, Object.keys(mostProperties).length); +} +function linearRegression(x, y) { + var n = x.length; + var sumX = x.reduce(function (acc, val) { + return acc + val; + }, 0); + var sumY = y.reduce(function (acc, val) { + return acc + val; + }, 0); + var sumXSquared = x.reduce(function (acc, val) { + return acc + Math.pow(val, 2); + }, 0); + var sumXY = x.reduce(function (acc, val, i) { + return acc + val * y[i]; + }, 0); + var slope = (n * sumXY - sumX * sumY) / (n * sumXSquared - Math.pow(sumX, 2)); + var intercept = (sumY - slope * sumX) / n; + var yHat = x.map(function (val) { + return slope * val + intercept; + }); + var totalVariation = y + .map(function (val, i) { + return Math.pow(val - yHat[i], 2); + }) + .reduce(function (acc, val) { + return acc + val; + }, 0); + var explainedVariation = y + .map(function (val) { + return Math.pow(val - sumY / n, 2); + }) + .reduce(function (acc, val) { + return acc + val; + }, 0); + var rSquared = 1 - totalVariation / explainedVariation; + return {slope: slope, intercept: intercept, rSquared: rSquared}; +} +function estimateBigO(runtimes, dataSizes) { + // Make sure the input runtimes and data sizes have the same length + if (runtimes.length !== dataSizes.length) { + return 'Lengths of input arrays do not match'; + } + // Create an array to store the computational complexity of each data point + var complexities = []; + // Traverse different possible complexities + var complexitiesToCheck = [ + 'O(1)', + 'O(log n)', + 'O(n)', + 'O(n log n)', + 'O(n^2)' // squared time complexity + ]; + var _loop_1 = function (complexity) { + // Calculate data points for fitting + var fittedData = dataSizes.map(function (size) { + if (complexity === 'O(1)') { + return 1; // constant time complexity + } else if (complexity === 'O(log n)') { + return Math.log(size); + } else if (complexity === 'O(n)') { + return size; + } else if (complexity === 'O(n log n)') { + return size * Math.log(size); + } else if (complexity === 'O(n^2)') { + return Math.pow(size, 2); + } else { + return Math.pow(size, 10); + } + }); + // Fit the data points using linear regression analysis + var regressionResult = linearRegression(fittedData, runtimes); + // Check the R-squared value of the fit. It is usually considered a valid fit if it is greater than 0.9. + if (regressionResult.rSquared >= 0.9) { + complexities.push(complexity); + } + }; + for (var _i = 0, complexitiesToCheck_1 = complexitiesToCheck; _i < complexitiesToCheck_1.length; _i++) { + var complexity = complexitiesToCheck_1[_i]; + _loop_1(complexity); + } + // If there is no valid fitting result, return "cannot estimate", otherwise return the estimated time complexity + if (complexities.length === 0) { + return 'Unable to estimate'; + } else { + return complexities.join(' or '); + } +} +var methodLogs = new Map(); +function logBigOMetricsWrap(fn, args, fnName) { + var startTime = performance.now(); + var result = fn(args); + var endTime = performance.now(); + var runTime = endTime - startTime; + var methodName = ''.concat(fnName); + if (!methodLogs.has(methodName)) { + methodLogs.set(methodName, []); + } + var methodLog = methodLogs.get(methodName); + var maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args); + if (methodLog) { + methodLog.push([runTime, maxDataSize]); + if (methodLog.length >= 20) { + isDebug && console.log('triggered', methodName, methodLog); + var bigO_1 = estimateBigO( + methodLog.map(function (_a) { + var runTime = _a[0]; + return runTime; + }), + methodLog.map(function (_a) { + var runTime = _a[0]; + return runTime; + }) + ); + isDebug && console.log('Estimated Big O: '.concat(bigO_1)); + methodLogs.delete(methodName); + } + } + return result; +} +exports.logBigOMetricsWrap = logBigOMetricsWrap; +function logBigOMetrics(target, propertyKey, descriptor) { + var originalMethod = descriptor.value; + descriptor.value = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var startTime = performance.now(); + var result = originalMethod.apply(this, args); + var endTime = performance.now(); + var runTime = endTime - startTime; + var methodName = ''.concat(target.constructor.name, '.').concat(propertyKey); + if (!methodLogs.has(methodName)) { + methodLogs.set(methodName, []); + } + var methodLog = methodLogs.get(methodName); + var maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args); + if (methodLog) { + methodLog.push([runTime, maxDataSize]); + if (methodLog.length >= 20) { + isDebug && console.log('triggered', methodName, methodLog); + var bigO_2 = estimateBigO( + methodLog.map(function (_a) { + var runTime = _a[0]; + return runTime; + }), + methodLog.map(function (_a) { + var runTime = _a[0]; + return runTime; + }) + ); + isDebug && console.log('Estimated Big O: '.concat(bigO_2)); + methodLogs.delete(methodName); + } + } + return result; + }; + return descriptor; +} +exports.logBigOMetrics = logBigOMetrics; diff --git a/test/utils/index.js b/test/utils/index.js new file mode 100644 index 0000000..9a9d3e3 --- /dev/null +++ b/test/utils/index.js @@ -0,0 +1,30 @@ +'use strict'; +var __createBinding = + (this && this.__createBinding) || + (Object.create + ? function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { + enumerable: true, + get: function () { + return m[k]; + } + }; + } + Object.defineProperty(o, k2, desc); + } + : function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; + }); +var __exportStar = + (this && this.__exportStar) || + function (m, exports) { + for (var p in m) + if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); + }; +Object.defineProperty(exports, '__esModule', {value: true}); +__exportStar(require('./number'), exports); +__exportStar(require('./big-o'), exports); diff --git a/test/utils/number.js b/test/utils/number.js new file mode 100644 index 0000000..75aee0a --- /dev/null +++ b/test/utils/number.js @@ -0,0 +1,14 @@ +'use strict'; +Object.defineProperty(exports, '__esModule', {value: true}); +exports.getMSB = exports.getRandomInt = void 0; +function getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} +exports.getRandomInt = getRandomInt; +var getMSB = function (value) { + if (value <= 0) { + return 0; + } + return 1 << (31 - Math.clz32(value)); +}; +exports.getMSB = getMSB;