umt 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/module/Array/generateNumberArray.js +13 -7
- package/module/Array/generateNumberArray.js.map +1 -1
- package/module/Array/getArraysCommon.js +21 -3
- package/module/Array/getArraysCommon.js.map +1 -1
- package/module/Array/groupBy.js +1 -1
- package/module/Array/groupBy.js.map +1 -1
- package/module/Array/index.d.ts +2 -0
- package/module/Array/index.js +2 -0
- package/module/Array/index.js.map +1 -1
- package/module/Array/ultraNumberSort.js +2 -2
- package/module/Array/ultraNumberSort.js.map +1 -1
- package/module/Array/uniqBy.d.ts +7 -0
- package/module/Array/uniqBy.js +19 -0
- package/module/Array/uniqBy.js.map +1 -0
- package/module/Array/unique.d.ts +6 -0
- package/module/Array/unique.js +9 -0
- package/module/Array/unique.js.map +1 -0
- package/module/Color/rgbaToHsla.js +1 -1
- package/module/Color/rgbaToHsla.js.map +1 -1
- package/module/Crypto/decodeBase32.d.ts +7 -0
- package/module/Crypto/decodeBase32.js +27 -0
- package/module/Crypto/decodeBase32.js.map +1 -0
- package/module/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/Crypto/decodeBase32ToString.js +11 -0
- package/module/Crypto/decodeBase32ToString.js.map +1 -0
- package/module/Crypto/decodeBase58.d.ts +7 -0
- package/module/Crypto/decodeBase58.js +34 -0
- package/module/Crypto/decodeBase58.js.map +1 -0
- package/module/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/Crypto/decodeBase58ToString.js +11 -0
- package/module/Crypto/decodeBase58ToString.js.map +1 -0
- package/module/Crypto/encodeBase32.d.ts +7 -0
- package/module/Crypto/encodeBase32.js +28 -0
- package/module/Crypto/encodeBase32.js.map +1 -0
- package/module/Crypto/encodeBase58.d.ts +7 -0
- package/module/Crypto/encodeBase58.js +29 -0
- package/module/Crypto/encodeBase58.js.map +1 -0
- package/module/Crypto/index.d.ts +6 -0
- package/module/Crypto/index.js +7 -0
- package/module/Crypto/index.js.map +1 -0
- package/module/DataStructure/index.d.ts +1 -0
- package/module/DataStructure/index.js +2 -0
- package/module/DataStructure/index.js.map +1 -0
- package/module/DataStructure/priorityQueue.d.ts +241 -0
- package/module/DataStructure/priorityQueue.js +327 -0
- package/module/DataStructure/priorityQueue.js.map +1 -0
- package/module/Date/birthday.js +14 -6
- package/module/Date/birthday.js.map +1 -1
- package/module/Date/isLeapYear.js +3 -0
- package/module/Date/isLeapYear.js.map +1 -1
- package/module/Error/index.d.ts +1 -0
- package/module/Error/index.js +1 -0
- package/module/Error/index.js.map +1 -1
- package/module/Error/retry.d.ts +37 -0
- package/module/Error/retry.js +47 -0
- package/module/Error/retry.js.map +1 -0
- package/module/IP/getIpClass.js +1 -1
- package/module/IP/getIpClass.js.map +1 -1
- package/module/IP/getNetworkAddress.js +2 -2
- package/module/IP/getNetworkAddress.js.map +1 -1
- package/module/IP/ipToBinaryString.js +2 -2
- package/module/IP/ipToBinaryString.js.map +1 -1
- package/module/IP/subnetMaskToCidr.js +1 -1
- package/module/IP/subnetMaskToCidr.js.map +1 -1
- package/module/Math/calculator/core.js +21 -13
- package/module/Math/calculator/core.js.map +1 -1
- package/module/Math/calculator/literalExpression.js +19 -7
- package/module/Math/calculator/literalExpression.js.map +1 -1
- package/module/Math/correlationCoefficient.d.ts +11 -0
- package/module/Math/correlationCoefficient.js +40 -0
- package/module/Math/correlationCoefficient.js.map +1 -0
- package/module/Math/division.js +3 -3
- package/module/Math/division.js.map +1 -1
- package/module/Math/gcd.js +26 -4
- package/module/Math/gcd.js.map +1 -1
- package/module/Math/index.d.ts +3 -0
- package/module/Math/index.js +3 -0
- package/module/Math/index.js.map +1 -1
- package/module/Math/mode.d.ts +10 -0
- package/module/Math/mode.js +31 -0
- package/module/Math/mode.js.map +1 -0
- package/module/Math/percentile.d.ts +11 -0
- package/module/Math/percentile.js +31 -0
- package/module/Math/percentile.js.map +1 -0
- package/module/Math/standardDeviation.js +4 -2
- package/module/Math/standardDeviation.js.map +1 -1
- package/module/Object/has.js +1 -2
- package/module/Object/has.js.map +1 -1
- package/module/Object/index.d.ts +4 -0
- package/module/Object/index.js +4 -0
- package/module/Object/index.js.map +1 -1
- package/module/Object/isEmpty.d.ts +6 -0
- package/module/Object/isEmpty.js +20 -0
- package/module/Object/isEmpty.js.map +1 -0
- package/module/Object/merge.d.ts +8 -0
- package/module/Object/merge.js +10 -0
- package/module/Object/merge.js.map +1 -0
- package/module/Object/mergeDeep.d.ts +8 -0
- package/module/Object/mergeDeep.js +37 -0
- package/module/Object/mergeDeep.js.map +1 -0
- package/module/Object/omit.d.ts +7 -0
- package/module/Object/omit.js +14 -0
- package/module/Object/omit.js.map +1 -0
- package/module/Object/pickDeep.d.ts +2 -2
- package/module/Object/pickDeep.js +4 -4
- package/module/Object/pickDeep.js.map +1 -1
- package/module/Simple/Date/dayOfWeekSimple.js +3 -3
- package/module/Simple/Date/dayOfWeekSimple.js.map +1 -1
- package/module/String/camelCase.d.ts +6 -0
- package/module/String/camelCase.js +12 -0
- package/module/String/camelCase.js.map +1 -0
- package/module/String/escapeHtml.d.ts +6 -0
- package/module/String/escapeHtml.js +19 -0
- package/module/String/escapeHtml.js.map +1 -0
- package/module/String/formatString/applyFormatter.d.ts +25 -0
- package/module/String/formatString/applyFormatter.js +71 -0
- package/module/String/formatString/applyFormatter.js.map +1 -0
- package/module/String/formatString/defaultFormatters.d.ts +24 -0
- package/module/String/formatString/defaultFormatters.js +59 -0
- package/module/String/formatString/defaultFormatters.js.map +1 -0
- package/module/String/formatString/detectMode.d.ts +26 -0
- package/module/String/formatString/detectMode.js +61 -0
- package/module/String/formatString/detectMode.js.map +1 -0
- package/module/String/formatString/getValue.d.ts +27 -0
- package/module/String/formatString/getValue.js +56 -0
- package/module/String/formatString/getValue.js.map +1 -0
- package/module/String/formatString/index.d.ts +91 -0
- package/module/String/formatString/index.js +38 -0
- package/module/String/formatString/index.js.map +1 -0
- package/module/String/fuzzySearch.d.ts +14 -0
- package/module/String/fuzzySearch.js +27 -0
- package/module/String/fuzzySearch.js.map +1 -0
- package/module/String/index.d.ts +9 -0
- package/module/String/index.js +9 -0
- package/module/String/index.js.map +1 -1
- package/module/String/kebabCase.d.ts +6 -0
- package/module/String/kebabCase.js +22 -0
- package/module/String/kebabCase.js.map +1 -0
- package/module/String/levenshteinDistance.d.ts +8 -0
- package/module/String/levenshteinDistance.js +38 -0
- package/module/String/levenshteinDistance.js.map +1 -0
- package/module/String/slugify.d.ts +10 -0
- package/module/String/slugify.js +21 -0
- package/module/String/slugify.js.map +1 -0
- package/module/String/stringSimilarity.d.ts +8 -0
- package/module/String/stringSimilarity.js +23 -0
- package/module/String/stringSimilarity.js.map +1 -0
- package/module/String/truncate.d.ts +12 -0
- package/module/String/truncate.js +21 -0
- package/module/String/truncate.js.map +1 -0
- package/module/String/unescapeHtml.d.ts +17 -0
- package/module/String/unescapeHtml.js +45 -0
- package/module/String/unescapeHtml.js.map +1 -0
- package/module/Validate/core/index.js +0 -1
- package/module/Validate/core/index.js.map +1 -1
- package/module/Validate/index.d.ts +1 -0
- package/module/Validate/index.js +1 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/isDeepEqual.d.ts +28 -0
- package/module/Validate/isDeepEqual.js +148 -0
- package/module/Validate/isDeepEqual.js.map +1 -0
- package/module/Validate/isDouble.js +1 -1
- package/module/Validate/isDouble.js.map +1 -1
- package/module/Validate/isNode.js +1 -0
- package/module/Validate/isNode.js.map +1 -1
- package/module/Validate/isNumber.js +1 -1
- package/module/Validate/isNumber.js.map +1 -1
- package/module/Validate/isValueNaN.js +1 -1
- package/module/Validate/isValueNaN.js.map +1 -1
- package/module/Validate/number/even.js +7 -1
- package/module/Validate/number/even.js.map +1 -1
- package/module/Validate/number/odd.js +7 -1
- package/module/Validate/number/odd.js.map +1 -1
- package/module/Validate/string/email.js +20 -2
- package/module/Validate/string/email.js.map +1 -1
- package/module/es5/Array/generateNumberArray.js +15 -9
- package/module/es5/Array/getArraysCommon.js +39 -4
- package/module/es5/Array/groupBy.js +1 -1
- package/module/es5/Array/index.d.ts +2 -0
- package/module/es5/Array/index.js +22 -0
- package/module/es5/Array/ultraNumberSort.js +2 -2
- package/module/es5/Array/uniqBy.d.ts +7 -0
- package/module/es5/Array/uniqBy.js +36 -0
- package/module/es5/Array/unique.d.ts +6 -0
- package/module/es5/Array/unique.js +20 -0
- package/module/es5/Color/rgbaToHsla.js +1 -1
- package/module/es5/Crypto/decodeBase32.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32.js +44 -0
- package/module/es5/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32ToString.js +16 -0
- package/module/es5/Crypto/decodeBase58.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58.js +63 -0
- package/module/es5/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58ToString.js +16 -0
- package/module/es5/Crypto/encodeBase32.d.ts +7 -0
- package/module/es5/Crypto/encodeBase32.js +45 -0
- package/module/es5/Crypto/encodeBase58.d.ts +7 -0
- package/module/es5/Crypto/encodeBase58.js +55 -0
- package/module/es5/Crypto/index.d.ts +6 -0
- package/module/es5/Crypto/index.js +71 -0
- package/module/es5/DataStructure/index.d.ts +1 -0
- package/module/es5/DataStructure/index.js +16 -0
- package/module/es5/DataStructure/priorityQueue.d.ts +241 -0
- package/module/es5/DataStructure/priorityQueue.js +405 -0
- package/module/es5/Date/birthday.js +17 -3
- package/module/es5/Date/isLeapYear.js +3 -0
- package/module/es5/Error/index.d.ts +1 -0
- package/module/es5/Error/index.js +11 -0
- package/module/es5/Error/retry.d.ts +37 -0
- package/module/es5/Error/retry.js +88 -0
- package/module/es5/IP/getIpClass.js +1 -1
- package/module/es5/IP/getNetworkAddress.js +2 -2
- package/module/es5/IP/ipToBinaryString.js +2 -2
- package/module/es5/IP/subnetMaskToCidr.js +1 -1
- package/module/es5/Math/calculator/core.js +17 -9
- package/module/es5/Math/calculator/literalExpression.js +19 -6
- package/module/es5/Math/correlationCoefficient.d.ts +11 -0
- package/module/es5/Math/correlationCoefficient.js +63 -0
- package/module/es5/Math/division.js +3 -3
- package/module/es5/Math/gcd.js +43 -5
- package/module/es5/Math/index.d.ts +3 -0
- package/module/es5/Math/index.js +33 -0
- package/module/es5/Math/mode.d.ts +10 -0
- package/module/es5/Math/mode.js +67 -0
- package/module/es5/Math/percentile.d.ts +11 -0
- package/module/es5/Math/percentile.js +42 -0
- package/module/es5/Math/standardDeviation.js +4 -2
- package/module/es5/Object/has.js +1 -1
- package/module/es5/Object/index.d.ts +4 -0
- package/module/es5/Object/index.js +44 -0
- package/module/es5/Object/isEmpty.d.ts +6 -0
- package/module/es5/Object/isEmpty.js +26 -0
- package/module/es5/Object/merge.d.ts +8 -0
- package/module/es5/Object/merge.js +18 -0
- package/module/es5/Object/mergeDeep.d.ts +8 -0
- package/module/es5/Object/mergeDeep.js +46 -0
- package/module/es5/Object/omit.d.ts +7 -0
- package/module/es5/Object/omit.js +29 -0
- package/module/es5/Object/pickDeep.d.ts +2 -2
- package/module/es5/Object/pickDeep.js +4 -4
- package/module/es5/Simple/Date/dayOfWeekSimple.js +3 -3
- package/module/es5/String/camelCase.d.ts +6 -0
- package/module/es5/String/camelCase.js +18 -0
- package/module/es5/String/escapeHtml.d.ts +6 -0
- package/module/es5/String/escapeHtml.js +27 -0
- package/module/es5/String/formatString/applyFormatter.d.ts +25 -0
- package/module/es5/String/formatString/applyFormatter.js +100 -0
- package/module/es5/String/formatString/defaultFormatters.d.ts +24 -0
- package/module/es5/String/formatString/defaultFormatters.js +79 -0
- package/module/es5/String/formatString/detectMode.d.ts +26 -0
- package/module/es5/String/formatString/detectMode.js +60 -0
- package/module/es5/String/formatString/getValue.d.ts +27 -0
- package/module/es5/String/formatString/getValue.js +85 -0
- package/module/es5/String/formatString/index.d.ts +91 -0
- package/module/es5/String/formatString/index.js +152 -0
- package/module/es5/String/fuzzySearch.d.ts +14 -0
- package/module/es5/String/fuzzySearch.js +50 -0
- package/module/es5/String/index.d.ts +9 -0
- package/module/es5/String/index.js +99 -0
- package/module/es5/String/kebabCase.d.ts +6 -0
- package/module/es5/String/kebabCase.js +26 -0
- package/module/es5/String/levenshteinDistance.d.ts +8 -0
- package/module/es5/String/levenshteinDistance.js +58 -0
- package/module/es5/String/slugify.d.ts +10 -0
- package/module/es5/String/slugify.js +18 -0
- package/module/es5/String/stringSimilarity.d.ts +8 -0
- package/module/es5/String/stringSimilarity.js +30 -0
- package/module/es5/String/truncate.d.ts +12 -0
- package/module/es5/String/truncate.js +27 -0
- package/module/es5/String/unescapeHtml.d.ts +17 -0
- package/module/es5/String/unescapeHtml.js +51 -0
- package/module/es5/Validate/core/index.js +0 -1
- package/module/es5/Validate/index.d.ts +1 -0
- package/module/es5/Validate/index.js +11 -0
- package/module/es5/Validate/isDeepEqual.d.ts +28 -0
- package/module/es5/Validate/isDeepEqual.js +232 -0
- package/module/es5/Validate/isDouble.js +1 -1
- package/module/es5/Validate/isNode.js +1 -0
- package/module/es5/Validate/isNumber.js +1 -1
- package/module/es5/Validate/isValueNaN.js +1 -1
- package/module/es5/Validate/number/even.js +4 -0
- package/module/es5/Validate/number/odd.js +4 -0
- package/module/es5/Validate/string/email.js +26 -1
- package/module/es5/index.d.ts +2 -0
- package/module/es5/index.js +22 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/es5/types/index.d.ts +1 -0
- package/module/es5/types/index.js +11 -0
- package/module/es5/types/logic/deepPartial.d.ts +37 -0
- package/module/es5/types/logic/deepPartial.js +5 -0
- package/module/es5/types/logic/deepRequired.d.ts +37 -0
- package/module/es5/types/logic/deepRequired.js +5 -0
- package/module/es5/types/logic/index.d.ts +3 -0
- package/module/es5/types/logic/index.js +33 -0
- package/module/es5/types/logic/unionToIntersection.d.ts +12 -0
- package/module/es5/types/logic/unionToIntersection.js +5 -0
- package/module/es5/types/object/index.d.ts +1 -0
- package/module/es5/types/object/index.js +11 -0
- package/module/es5/types/object/pickDeep.d.ts +13 -1
- package/module/es5/types/object/shallowObjectValue.d.ts +9 -0
- package/module/es5/types/object/shallowObjectValue.js +5 -0
- package/module/es5/types/string/formatString/formatData.d.ts +17 -0
- package/module/es5/types/string/formatString/formatData.js +5 -0
- package/module/es5/types/string/formatString/formatOptions.d.ts +21 -0
- package/module/es5/types/string/formatString/formatOptions.js +5 -0
- package/module/es5/types/string/formatString/formatString.d.ts +4 -0
- package/module/es5/types/string/formatString/formatString.js +49 -0
- package/module/es5/types/string/formatString/formatValue.d.ts +15 -0
- package/module/es5/types/string/formatString/formatValue.js +5 -0
- package/module/es5/types/string/formatString/formatter.d.ts +13 -0
- package/module/es5/types/string/formatString/formatter.js +5 -0
- package/module/es5/types/string/formatString/index.d.ts +5 -0
- package/module/es5/types/string/formatString/index.js +60 -0
- package/module/es5/types/string/index.d.ts +1 -0
- package/module/es5/types/string/index.js +16 -0
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -0
- package/module/index.js.map +1 -1
- package/module/types/index.d.ts +1 -0
- package/module/types/index.js +1 -0
- package/module/types/index.js.map +1 -1
- package/module/types/logic/deepPartial.d.ts +37 -0
- package/module/types/logic/deepPartial.js +36 -0
- package/module/types/logic/deepPartial.js.map +1 -0
- package/module/types/logic/deepRequired.d.ts +37 -0
- package/module/types/logic/deepRequired.js +2 -0
- package/module/types/logic/deepRequired.js.map +1 -0
- package/module/types/logic/index.d.ts +3 -0
- package/module/types/logic/index.js +3 -0
- package/module/types/logic/index.js.map +1 -1
- package/module/types/logic/unionToIntersection.d.ts +12 -0
- package/module/types/logic/unionToIntersection.js +2 -0
- package/module/types/logic/unionToIntersection.js.map +1 -0
- package/module/types/object/index.d.ts +1 -0
- package/module/types/object/index.js +1 -0
- package/module/types/object/index.js.map +1 -1
- package/module/types/object/pickDeep.d.ts +13 -1
- package/module/types/object/shallowObjectValue.d.ts +9 -0
- package/module/types/object/shallowObjectValue.js +2 -0
- package/module/types/object/shallowObjectValue.js.map +1 -0
- package/module/types/string/formatString/formatData.d.ts +17 -0
- package/module/types/string/formatString/formatData.js +2 -0
- package/module/types/string/formatString/formatData.js.map +1 -0
- package/module/types/string/formatString/formatOptions.d.ts +21 -0
- package/module/types/string/formatString/formatOptions.js +2 -0
- package/module/types/string/formatString/formatOptions.js.map +1 -0
- package/module/types/string/formatString/formatString.d.ts +4 -0
- package/module/types/string/formatString/formatString.js +5 -0
- package/module/types/string/formatString/formatString.js.map +1 -0
- package/module/types/string/formatString/formatValue.d.ts +15 -0
- package/module/types/string/formatString/formatValue.js +2 -0
- package/module/types/string/formatString/formatValue.js.map +1 -0
- package/module/types/string/formatString/formatter.d.ts +13 -0
- package/module/types/string/formatString/formatter.js +2 -0
- package/module/types/string/formatString/formatter.js.map +1 -0
- package/module/types/string/formatString/index.d.ts +5 -0
- package/module/types/string/formatString/index.js +6 -0
- package/module/types/string/formatString/index.js.map +1 -0
- package/module/types/string/index.d.ts +1 -0
- package/module/types/string/index.js +2 -0
- package/module/types/string/index.js.map +1 -0
- package/package.json +40 -41
- package/module/String/formatString.d.ts +0 -13
- package/module/String/formatString.js +0 -18
- package/module/String/formatString.js.map +0 -1
- package/module/es5/String/formatString.d.ts +0 -13
- package/module/es5/String/formatString.js +0 -26
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string or Uint8Array to Base58 format
|
|
3
|
+
* @param {string | Uint8Array} input - The input to encode
|
|
4
|
+
* @returns {string} Base58 encoded string
|
|
5
|
+
* @example encodeBase58("Hello"); // "9Ajdvzr"
|
|
6
|
+
*/
|
|
7
|
+
export const encodeBase58 = (input) => {
|
|
8
|
+
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
9
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
10
|
+
let encoded = "";
|
|
11
|
+
let bigNumber = BigInt(0);
|
|
12
|
+
for (const byte of bytes) {
|
|
13
|
+
bigNumber = bigNumber * BigInt(256) + BigInt(byte);
|
|
14
|
+
}
|
|
15
|
+
while (bigNumber > 0) {
|
|
16
|
+
const remainder = Number(bigNumber % BigInt(58));
|
|
17
|
+
encoded = alphabet[remainder] + encoded;
|
|
18
|
+
bigNumber /= BigInt(58);
|
|
19
|
+
}
|
|
20
|
+
let leadingZeros = 0;
|
|
21
|
+
for (const byte of bytes) {
|
|
22
|
+
if (byte !== 0) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
leadingZeros++;
|
|
26
|
+
}
|
|
27
|
+
return "1".repeat(leadingZeros) + encoded;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=encodeBase58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeBase58.js","sourceRoot":"","sources":["../../src/Crypto/encodeBase58.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAU,EAAE;IACjE,MAAM,QAAQ,GAAG,4DAA4D,CAAC;IAC9E,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtE,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,SAAS,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACjD,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;QACxC,SAAS,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACf,MAAM;QACR,CAAC;QACD,YAAY,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./priorityQueue";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DataStructure/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A priority queue implementation using a binary heap.
|
|
3
|
+
* Higher priority values are dequeued first.
|
|
4
|
+
*
|
|
5
|
+
* ## Features
|
|
6
|
+
* - **enqueue(value, priority)**: Add element with priority
|
|
7
|
+
* - **enqueueBack(value)**: Add element to the back with lowest priority
|
|
8
|
+
* - **dequeue()**: Remove and return highest priority element
|
|
9
|
+
* - **peek()**: View highest priority element without removing
|
|
10
|
+
* - **peekPriority()**: View highest priority value
|
|
11
|
+
* - **size**: Get number of elements
|
|
12
|
+
* - **isEmpty**: Check if queue is empty
|
|
13
|
+
* - **clear()**: Remove all elements
|
|
14
|
+
* - **toArray()**: Get all elements as array
|
|
15
|
+
* - **toArrayWithPriorities()**: Get all elements with priorities
|
|
16
|
+
*
|
|
17
|
+
* ## Time Complexity
|
|
18
|
+
* - enqueue: O(log n)
|
|
19
|
+
* - enqueueBack: O(log n)
|
|
20
|
+
* - dequeue: O(log n)
|
|
21
|
+
* - peek: O(1)
|
|
22
|
+
* - peekPriority: O(1)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const queue = new PriorityQueue<string>();
|
|
27
|
+
* queue.enqueue("low", 1);
|
|
28
|
+
* queue.enqueue("high", 3);
|
|
29
|
+
* queue.enqueue("medium", 2);
|
|
30
|
+
*
|
|
31
|
+
* console.log(queue.dequeue()); // "high"
|
|
32
|
+
* console.log(queue.dequeue()); // "medium"
|
|
33
|
+
* console.log(queue.dequeue()); // "low"
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Initialize with elements
|
|
39
|
+
* const queue = new PriorityQueue([
|
|
40
|
+
* { value: "task1", priority: 1 },
|
|
41
|
+
* { value: "task2", priority: 3 },
|
|
42
|
+
* { value: "task3", priority: 2 }
|
|
43
|
+
* ]);
|
|
44
|
+
*
|
|
45
|
+
* console.log(queue.peek()); // "task2"
|
|
46
|
+
* console.log(queue.peekPriority()); // 3
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of elements stored in the queue
|
|
50
|
+
*/
|
|
51
|
+
export declare class PriorityQueue<T> {
|
|
52
|
+
private heap;
|
|
53
|
+
private minPriority;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new PriorityQueue instance.
|
|
56
|
+
* @param initialElements - Optional array of initial elements with priorities
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const queue = new PriorityQueue<string>();
|
|
60
|
+
* // or
|
|
61
|
+
* const queue = new PriorityQueue([
|
|
62
|
+
* { value: "item1", priority: 10 },
|
|
63
|
+
* { value: "item2", priority: 5 }
|
|
64
|
+
* ]);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
constructor(initialElements?: Array<{
|
|
68
|
+
value: T;
|
|
69
|
+
priority: number;
|
|
70
|
+
}>);
|
|
71
|
+
/**
|
|
72
|
+
* Returns the number of elements in the queue.
|
|
73
|
+
* @returns The number of elements in the queue
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const queue = new PriorityQueue<string>();
|
|
77
|
+
* queue.enqueue("item", 1);
|
|
78
|
+
* console.log(queue.size); // 1
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
get size(): number;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the queue is empty.
|
|
84
|
+
* @returns True if the queue is empty, false otherwise
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const queue = new PriorityQueue<string>();
|
|
88
|
+
* console.log(queue.isEmpty); // true
|
|
89
|
+
* queue.enqueue("item", 1);
|
|
90
|
+
* console.log(queue.isEmpty); // false
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
get isEmpty(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Adds an element to the queue with a specified priority.
|
|
96
|
+
* Higher priority values are dequeued first.
|
|
97
|
+
* @param value - The value to add
|
|
98
|
+
* @param priority - The priority value (higher values have higher priority)
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const queue = new PriorityQueue<string>();
|
|
102
|
+
* queue.enqueue("low", 1);
|
|
103
|
+
* queue.enqueue("high", 10);
|
|
104
|
+
* queue.enqueue("medium", 5);
|
|
105
|
+
* console.log(queue.dequeue()); // "high"
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
enqueue(value: T, priority: number): void;
|
|
109
|
+
/**
|
|
110
|
+
* Adds an element to the end of the queue with lowest priority.
|
|
111
|
+
* This element will be dequeued last (FIFO for equal lowest priority).
|
|
112
|
+
*
|
|
113
|
+
* @param value - The value to add
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const queue = new PriorityQueue<string>();
|
|
117
|
+
* queue.enqueue("high", 10);
|
|
118
|
+
* queue.enqueue("medium", 5);
|
|
119
|
+
* queue.enqueueBack("back1");
|
|
120
|
+
* queue.enqueueBack("back2");
|
|
121
|
+
* console.log(queue.dequeue()); // "high"
|
|
122
|
+
* console.log(queue.dequeue()); // "medium"
|
|
123
|
+
* console.log(queue.dequeue()); // "back1"
|
|
124
|
+
* console.log(queue.dequeue()); // "back2"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
enqueueBack(value: T): void;
|
|
128
|
+
/**
|
|
129
|
+
* Removes and returns the element with the highest priority.
|
|
130
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const queue = new PriorityQueue<string>();
|
|
134
|
+
* queue.enqueue("low", 1);
|
|
135
|
+
* queue.enqueue("high", 10);
|
|
136
|
+
* console.log(queue.dequeue()); // "high"
|
|
137
|
+
* console.log(queue.dequeue()); // "low"
|
|
138
|
+
* console.log(queue.dequeue()); // undefined
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
dequeue(): T | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the element with the highest priority without removing it.
|
|
144
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const queue = new PriorityQueue<string>();
|
|
148
|
+
* queue.enqueue("low", 1);
|
|
149
|
+
* queue.enqueue("high", 10);
|
|
150
|
+
* console.log(queue.peek()); // "high"
|
|
151
|
+
* console.log(queue.size); // 2 (element not removed)
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
peek(): T | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the priority of the element with the highest priority.
|
|
157
|
+
* @returns The highest priority value, or undefined if queue is empty
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const queue = new PriorityQueue<string>();
|
|
161
|
+
* queue.enqueue("low", 1);
|
|
162
|
+
* queue.enqueue("high", 10);
|
|
163
|
+
* console.log(queue.peekPriority()); // 10
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
peekPriority(): number | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Removes all elements from the queue.
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const queue = new PriorityQueue<string>();
|
|
172
|
+
* queue.enqueue("item1", 1);
|
|
173
|
+
* queue.enqueue("item2", 2);
|
|
174
|
+
* console.log(queue.size); // 2
|
|
175
|
+
* queue.clear();
|
|
176
|
+
* console.log(queue.size); // 0
|
|
177
|
+
* console.log(queue.isEmpty); // true
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
clear(): void;
|
|
181
|
+
/**
|
|
182
|
+
* Returns an array of all elements in the queue (without removing them).
|
|
183
|
+
* The order is not guaranteed to be sorted by priority.
|
|
184
|
+
* @returns Array of all elements in the queue
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const queue = new PriorityQueue<string>();
|
|
188
|
+
* queue.enqueue("low", 1);
|
|
189
|
+
* queue.enqueue("high", 10);
|
|
190
|
+
* queue.enqueue("medium", 5);
|
|
191
|
+
* console.log(queue.toArray()); // ["high", "medium", "low"] (order may vary)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
toArray(): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Returns an array of all elements with their priorities.
|
|
197
|
+
* The order is not guaranteed to be sorted by priority.
|
|
198
|
+
* @returns Array of all elements with their priorities
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const queue = new PriorityQueue<string>();
|
|
202
|
+
* queue.enqueue("low", 1);
|
|
203
|
+
* queue.enqueue("high", 10);
|
|
204
|
+
* console.log(queue.toArrayWithPriorities());
|
|
205
|
+
* // [{ value: "high", priority: 10 }, { value: "low", priority: 1 }] (order may vary)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
toArrayWithPriorities(): Array<{
|
|
209
|
+
value: T;
|
|
210
|
+
priority: number;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Updates the minimum priority when adding elements.
|
|
214
|
+
* @param priority - The priority being added
|
|
215
|
+
*/
|
|
216
|
+
private updateMinPriorityOnAdd;
|
|
217
|
+
/**
|
|
218
|
+
* Updates the minimum priority from all elements (used in constructor).
|
|
219
|
+
*/
|
|
220
|
+
private updateMinPriority;
|
|
221
|
+
/**
|
|
222
|
+
* Builds a max heap from the current heap array.
|
|
223
|
+
*/
|
|
224
|
+
private buildHeap;
|
|
225
|
+
/**
|
|
226
|
+
* Moves an element up the heap to maintain heap property.
|
|
227
|
+
* @param index - The index of the element to move up
|
|
228
|
+
*/
|
|
229
|
+
private heapifyUp;
|
|
230
|
+
/**
|
|
231
|
+
* Moves an element down the heap to maintain heap property.
|
|
232
|
+
* @param index - The index of the element to move down
|
|
233
|
+
*/
|
|
234
|
+
private heapifyDown;
|
|
235
|
+
/**
|
|
236
|
+
* Swaps two elements in the heap.
|
|
237
|
+
* @param i - First index
|
|
238
|
+
* @param j - Second index
|
|
239
|
+
*/
|
|
240
|
+
private swap;
|
|
241
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A priority queue implementation using a binary heap.
|
|
3
|
+
* Higher priority values are dequeued first.
|
|
4
|
+
*
|
|
5
|
+
* ## Features
|
|
6
|
+
* - **enqueue(value, priority)**: Add element with priority
|
|
7
|
+
* - **enqueueBack(value)**: Add element to the back with lowest priority
|
|
8
|
+
* - **dequeue()**: Remove and return highest priority element
|
|
9
|
+
* - **peek()**: View highest priority element without removing
|
|
10
|
+
* - **peekPriority()**: View highest priority value
|
|
11
|
+
* - **size**: Get number of elements
|
|
12
|
+
* - **isEmpty**: Check if queue is empty
|
|
13
|
+
* - **clear()**: Remove all elements
|
|
14
|
+
* - **toArray()**: Get all elements as array
|
|
15
|
+
* - **toArrayWithPriorities()**: Get all elements with priorities
|
|
16
|
+
*
|
|
17
|
+
* ## Time Complexity
|
|
18
|
+
* - enqueue: O(log n)
|
|
19
|
+
* - enqueueBack: O(log n)
|
|
20
|
+
* - dequeue: O(log n)
|
|
21
|
+
* - peek: O(1)
|
|
22
|
+
* - peekPriority: O(1)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const queue = new PriorityQueue<string>();
|
|
27
|
+
* queue.enqueue("low", 1);
|
|
28
|
+
* queue.enqueue("high", 3);
|
|
29
|
+
* queue.enqueue("medium", 2);
|
|
30
|
+
*
|
|
31
|
+
* console.log(queue.dequeue()); // "high"
|
|
32
|
+
* console.log(queue.dequeue()); // "medium"
|
|
33
|
+
* console.log(queue.dequeue()); // "low"
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Initialize with elements
|
|
39
|
+
* const queue = new PriorityQueue([
|
|
40
|
+
* { value: "task1", priority: 1 },
|
|
41
|
+
* { value: "task2", priority: 3 },
|
|
42
|
+
* { value: "task3", priority: 2 }
|
|
43
|
+
* ]);
|
|
44
|
+
*
|
|
45
|
+
* console.log(queue.peek()); // "task2"
|
|
46
|
+
* console.log(queue.peekPriority()); // 3
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of elements stored in the queue
|
|
50
|
+
*/
|
|
51
|
+
export class PriorityQueue {
|
|
52
|
+
heap = [];
|
|
53
|
+
minPriority = 0;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new PriorityQueue instance.
|
|
56
|
+
* @param initialElements - Optional array of initial elements with priorities
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const queue = new PriorityQueue<string>();
|
|
60
|
+
* // or
|
|
61
|
+
* const queue = new PriorityQueue([
|
|
62
|
+
* { value: "item1", priority: 10 },
|
|
63
|
+
* { value: "item2", priority: 5 }
|
|
64
|
+
* ]);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
constructor(initialElements) {
|
|
68
|
+
if (initialElements) {
|
|
69
|
+
this.heap = [...initialElements];
|
|
70
|
+
this.updateMinPriority();
|
|
71
|
+
this.buildHeap();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns the number of elements in the queue.
|
|
76
|
+
* @returns The number of elements in the queue
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const queue = new PriorityQueue<string>();
|
|
80
|
+
* queue.enqueue("item", 1);
|
|
81
|
+
* console.log(queue.size); // 1
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
get size() {
|
|
85
|
+
return this.heap.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the queue is empty.
|
|
89
|
+
* @returns True if the queue is empty, false otherwise
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const queue = new PriorityQueue<string>();
|
|
93
|
+
* console.log(queue.isEmpty); // true
|
|
94
|
+
* queue.enqueue("item", 1);
|
|
95
|
+
* console.log(queue.isEmpty); // false
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
get isEmpty() {
|
|
99
|
+
return this.heap.length === 0;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Adds an element to the queue with a specified priority.
|
|
103
|
+
* Higher priority values are dequeued first.
|
|
104
|
+
* @param value - The value to add
|
|
105
|
+
* @param priority - The priority value (higher values have higher priority)
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const queue = new PriorityQueue<string>();
|
|
109
|
+
* queue.enqueue("low", 1);
|
|
110
|
+
* queue.enqueue("high", 10);
|
|
111
|
+
* queue.enqueue("medium", 5);
|
|
112
|
+
* console.log(queue.dequeue()); // "high"
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
enqueue(value, priority) {
|
|
116
|
+
this.heap.push({ value, priority });
|
|
117
|
+
this.updateMinPriorityOnAdd(priority);
|
|
118
|
+
this.heapifyUp(this.heap.length - 1);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Adds an element to the end of the queue with lowest priority.
|
|
122
|
+
* This element will be dequeued last (FIFO for equal lowest priority).
|
|
123
|
+
*
|
|
124
|
+
* @param value - The value to add
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const queue = new PriorityQueue<string>();
|
|
128
|
+
* queue.enqueue("high", 10);
|
|
129
|
+
* queue.enqueue("medium", 5);
|
|
130
|
+
* queue.enqueueBack("back1");
|
|
131
|
+
* queue.enqueueBack("back2");
|
|
132
|
+
* console.log(queue.dequeue()); // "high"
|
|
133
|
+
* console.log(queue.dequeue()); // "medium"
|
|
134
|
+
* console.log(queue.dequeue()); // "back1"
|
|
135
|
+
* console.log(queue.dequeue()); // "back2"
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
enqueueBack(value) {
|
|
139
|
+
const newPriority = this.minPriority - 1;
|
|
140
|
+
this.heap.push({ value, priority: newPriority });
|
|
141
|
+
this.minPriority = newPriority;
|
|
142
|
+
this.heapifyUp(this.heap.length - 1);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes and returns the element with the highest priority.
|
|
146
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const queue = new PriorityQueue<string>();
|
|
150
|
+
* queue.enqueue("low", 1);
|
|
151
|
+
* queue.enqueue("high", 10);
|
|
152
|
+
* console.log(queue.dequeue()); // "high"
|
|
153
|
+
* console.log(queue.dequeue()); // "low"
|
|
154
|
+
* console.log(queue.dequeue()); // undefined
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
dequeue() {
|
|
158
|
+
if (this.heap.length === 0) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (this.heap.length === 1) {
|
|
162
|
+
return this.heap.pop()?.value;
|
|
163
|
+
}
|
|
164
|
+
const result = this.heap[0].value;
|
|
165
|
+
// biome-ignore lint/style/noNonNullAssertion: pop() cannot return undefined when heap.length > 1
|
|
166
|
+
this.heap[0] = this.heap.pop();
|
|
167
|
+
this.heapifyDown(0);
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns the element with the highest priority without removing it.
|
|
172
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const queue = new PriorityQueue<string>();
|
|
176
|
+
* queue.enqueue("low", 1);
|
|
177
|
+
* queue.enqueue("high", 10);
|
|
178
|
+
* console.log(queue.peek()); // "high"
|
|
179
|
+
* console.log(queue.size); // 2 (element not removed)
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
peek() {
|
|
183
|
+
return this.heap[0]?.value;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns the priority of the element with the highest priority.
|
|
187
|
+
* @returns The highest priority value, or undefined if queue is empty
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const queue = new PriorityQueue<string>();
|
|
191
|
+
* queue.enqueue("low", 1);
|
|
192
|
+
* queue.enqueue("high", 10);
|
|
193
|
+
* console.log(queue.peekPriority()); // 10
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
peekPriority() {
|
|
197
|
+
return this.heap[0]?.priority;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Removes all elements from the queue.
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const queue = new PriorityQueue<string>();
|
|
204
|
+
* queue.enqueue("item1", 1);
|
|
205
|
+
* queue.enqueue("item2", 2);
|
|
206
|
+
* console.log(queue.size); // 2
|
|
207
|
+
* queue.clear();
|
|
208
|
+
* console.log(queue.size); // 0
|
|
209
|
+
* console.log(queue.isEmpty); // true
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
clear() {
|
|
213
|
+
this.heap = [];
|
|
214
|
+
this.minPriority = 0;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns an array of all elements in the queue (without removing them).
|
|
218
|
+
* The order is not guaranteed to be sorted by priority.
|
|
219
|
+
* @returns Array of all elements in the queue
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const queue = new PriorityQueue<string>();
|
|
223
|
+
* queue.enqueue("low", 1);
|
|
224
|
+
* queue.enqueue("high", 10);
|
|
225
|
+
* queue.enqueue("medium", 5);
|
|
226
|
+
* console.log(queue.toArray()); // ["high", "medium", "low"] (order may vary)
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
toArray() {
|
|
230
|
+
return this.heap.map((item) => item.value);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns an array of all elements with their priorities.
|
|
234
|
+
* The order is not guaranteed to be sorted by priority.
|
|
235
|
+
* @returns Array of all elements with their priorities
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const queue = new PriorityQueue<string>();
|
|
239
|
+
* queue.enqueue("low", 1);
|
|
240
|
+
* queue.enqueue("high", 10);
|
|
241
|
+
* console.log(queue.toArrayWithPriorities());
|
|
242
|
+
* // [{ value: "high", priority: 10 }, { value: "low", priority: 1 }] (order may vary)
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
toArrayWithPriorities() {
|
|
246
|
+
return [...this.heap];
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Updates the minimum priority when adding elements.
|
|
250
|
+
* @param priority - The priority being added
|
|
251
|
+
*/
|
|
252
|
+
updateMinPriorityOnAdd(priority) {
|
|
253
|
+
if (this.heap.length === 1 || priority < this.minPriority) {
|
|
254
|
+
this.minPriority = priority;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Updates the minimum priority from all elements (used in constructor).
|
|
259
|
+
*/
|
|
260
|
+
updateMinPriority() {
|
|
261
|
+
if (this.heap.length === 0) {
|
|
262
|
+
this.minPriority = 0;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.minPriority = Math.min(...this.heap.map((item) => item.priority));
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Builds a max heap from the current heap array.
|
|
269
|
+
*/
|
|
270
|
+
buildHeap() {
|
|
271
|
+
for (let index = Math.floor(this.heap.length / 2) - 1; index >= 0; index--) {
|
|
272
|
+
this.heapifyDown(index);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Moves an element up the heap to maintain heap property.
|
|
277
|
+
* @param index - The index of the element to move up
|
|
278
|
+
*/
|
|
279
|
+
heapifyUp(index) {
|
|
280
|
+
let currentIndex = index;
|
|
281
|
+
while (currentIndex > 0) {
|
|
282
|
+
const parentIndex = Math.floor((currentIndex - 1) / 2);
|
|
283
|
+
if (this.heap[currentIndex].priority <= this.heap[parentIndex].priority) {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
this.swap(currentIndex, parentIndex);
|
|
287
|
+
currentIndex = parentIndex;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Moves an element down the heap to maintain heap property.
|
|
292
|
+
* @param index - The index of the element to move down
|
|
293
|
+
*/
|
|
294
|
+
heapifyDown(index) {
|
|
295
|
+
let currentIndex = index;
|
|
296
|
+
while (true) {
|
|
297
|
+
const leftChild = 2 * currentIndex + 1;
|
|
298
|
+
const rightChild = 2 * currentIndex + 2;
|
|
299
|
+
let largest = currentIndex;
|
|
300
|
+
if (leftChild < this.heap.length &&
|
|
301
|
+
this.heap[leftChild].priority > this.heap[largest].priority) {
|
|
302
|
+
largest = leftChild;
|
|
303
|
+
}
|
|
304
|
+
if (rightChild < this.heap.length &&
|
|
305
|
+
this.heap[rightChild].priority > this.heap[largest].priority) {
|
|
306
|
+
largest = rightChild;
|
|
307
|
+
}
|
|
308
|
+
if (largest === currentIndex) {
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
this.swap(currentIndex, largest);
|
|
312
|
+
currentIndex = largest;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Swaps two elements in the heap.
|
|
317
|
+
* @param i - First index
|
|
318
|
+
* @param j - Second index
|
|
319
|
+
*/
|
|
320
|
+
swap(index, index_) {
|
|
321
|
+
[this.heap[index], this.heap[index_]] = [
|
|
322
|
+
this.heap[index_],
|
|
323
|
+
this.heap[index],
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=priorityQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priorityQueue.js","sourceRoot":"","sources":["../../src/DataStructure/priorityQueue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,OAAO,aAAa;IAChB,IAAI,GAA0C,EAAE,CAAC;IACjD,WAAW,GAAG,CAAC,CAAC;IAExB;;;;;;;;;;;;OAYG;IACH,YAAY,eAAuD;QACjE,IAAI,eAAe,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC;YACjC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;OAUG;IACH,IAA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C7B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAC5D,CAAC;gBACD,OAAO,GAAG,UAAU,CAAC;YACvB,CAAC;YAED,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;gBAC7B,MAAM;YACR,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YACjC,YAAY,GAAG,OAAO,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,IAAI,CAAC,KAAa,EAAE,MAAc;QACxC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG;YACtC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACjB,CAAC;IACJ,CAAC;CACF"}
|
package/module/Date/birthday.js
CHANGED
|
@@ -12,11 +12,19 @@ import { now } from "../Date/now";
|
|
|
12
12
|
export const birthday = (year, mon, day, timeDifference = 9) => {
|
|
13
13
|
const birthdayDate = new Date(newDateInt(year, mon, day));
|
|
14
14
|
const nowTime = now(timeDifference);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const currentYear = nowTime.getFullYear();
|
|
16
|
+
const birthYear = birthdayDate.getFullYear();
|
|
17
|
+
// Calculate base age
|
|
18
|
+
let age = currentYear - birthYear;
|
|
19
|
+
// Check if birthday hasn't occurred this year yet
|
|
20
|
+
const thisYearBirthday = new Date(currentYear, birthdayDate.getMonth(), birthdayDate.getDate());
|
|
21
|
+
if (nowTime < thisYearBirthday) {
|
|
22
|
+
age -= 1;
|
|
23
|
+
}
|
|
24
|
+
// Handle future birthdays (should return 0 or non-negative)
|
|
25
|
+
if (age < 0) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return age;
|
|
21
29
|
};
|
|
22
30
|
//# sourceMappingURL=birthday.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"birthday.js","sourceRoot":"","sources":["../../src/Date/birthday.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAY,EACZ,GAAM,EACN,GAAkB,EAClB,iBAA+B,CAAC,EAChC,EAAE;IACF,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,MAAM,
|
|
1
|
+
{"version":3,"file":"birthday.js","sourceRoot":"","sources":["../../src/Date/birthday.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAY,EACZ,GAAM,EACN,GAAkB,EAClB,iBAA+B,CAAC,EAChC,EAAE;IACF,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAE7C,qBAAqB;IACrB,IAAI,GAAG,GAAG,WAAW,GAAG,SAAS,CAAC;IAElC,kDAAkD;IAClD,MAAM,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