export default {
+ '*.json': ['biome format --no-errors-on-unmatched --write'],
'*.{js,jsx,cjs,mjs}': [
'biome format --no-errors-on-unmatched --write',
'eslint --cache --fix',
],
'*.{md,yml,yaml}': ['prettier --cache --write'],
- '*.json': ['biome format --no-errors-on-unmatched --write'],
}
import { getRandomValues, randomBytes, randomInt } from 'node:crypto'
-/**
- * Generate a cryptographically secure random number in the [0,1[ range
- * @returns
- */
-export function secureRandom () {
- return randomBytes(4).readUInt32LE() / 0x100000000
-}
-
-/**
- * Generate a cryptographically secure random number in the [0,1[ range
- * @returns
- */
-export function secureRandomWithRandomValues () {
- return getRandomValues(new Uint32Array(1))[0] / 0x100000000
-}
-
/**
*
* @param max
return object
}
+/**
+ * Generate a cryptographically secure random number in the [0,1[ range
+ * @returns
+ */
+export function secureRandom () {
+ return randomBytes(4).readUInt32LE() / 0x100000000
+}
+
+/**
+ * Generate a cryptographically secure random number in the [0,1[ range
+ * @returns
+ */
+export function secureRandomWithRandomValues () {
+ return getRandomValues(new Uint32Array(1))[0] / 0x100000000
+}
+
/**
* @param ms
* @returns
const timeout = 2000
const interval = 1000
-/**
- * @param timeoutMs
- */
-function dummyTimeoutBusyWait (timeoutMs) {
- const timeoutTimestampMs = performance.now() + timeoutMs
- // eslint-disable-next-line no-empty
- do {} while (performance.now() < timeoutTimestampMs)
-}
-
-/**
- * @param timeoutMs
- * @param intervalMs
- */
-async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) {
- const timeoutTimestampMs = performance.now() + timeoutMs
- do {
- await sleep(intervalMs)
- } while (performance.now() < timeoutTimestampMs)
-}
-
/**
* @param timeoutMs
* @param intervalMs
} while (count <= tries)
}
+/**
+ * @param timeoutMs
+ */
+function dummyTimeoutBusyWait (timeoutMs) {
+ const timeoutTimestampMs = performance.now() + timeoutMs
+ // eslint-disable-next-line no-empty
+ do {} while (performance.now() < timeoutTimestampMs)
+}
+
/**
* @param timeoutMs
* @param intervalMs
})
}
+/**
+ * @param timeoutMs
+ * @param intervalMs
+ */
+async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) {
+ const timeoutTimestampMs = performance.now() + timeoutMs
+ do {
+ await sleep(intervalMs)
+ } while (performance.now() < timeoutTimestampMs)
+}
+
group('Busy wait', () => {
bench('dummyTimeoutBusyWait', () => {
dummyTimeoutBusyWait(timeout)
* @param values
* @returns
*/
-function reduceTernaryMax (values) {
+function reduceMathMax (values) {
return values.reduce(
- (maximum, num) => (maximum > num ? maximum : num),
+ (maximum, num) => Math.max(maximum, num),
Number.NEGATIVE_INFINITY
)
}
* @param values
* @returns
*/
-function reduceMathMax (values) {
+function reduceTernaryMax (values) {
return values.reduce(
- (maximum, num) => Math.max(maximum, num),
+ (maximum, num) => (maximum > num ? maximum : num),
Number.NEGATIVE_INFINITY
)
}
* @param values
* @returns
*/
-function reduceTernaryMin (values) {
+function reduceMathMin (values) {
return values.reduce(
- (minimum, num) => (minimum < num ? minimum : num),
+ (minimum, num) => Math.min(minimum, num),
Number.POSITIVE_INFINITY
)
}
* @param values
* @returns
*/
-function reduceMathMin (values) {
+function reduceTernaryMin (values) {
return values.reduce(
- (minimum, num) => Math.min(minimum, num),
+ (minimum, num) => (minimum < num ? minimum : num),
Number.POSITIVE_INFINITY
)
}
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
- "@commitlint/cli": "^19.5.0",
- "@commitlint/config-conventional": "^19.5.0",
+ "@commitlint/cli": "^19.6.0",
+ "@commitlint/config-conventional": "^19.6.0",
"@eslint/js": "^9.15.0",
"eslint": "^9.15.0",
"eslint-define-config": "^2.1.0",
"eslint-plugin-jsdoc": "^50.5.0",
- "eslint-plugin-perfectionist": "^3.9.1",
+ "eslint-plugin-perfectionist": "^4.0.1",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
"neostandard": "^0.11.8",
specifier: ^1.9.4
version: 1.9.4
'@commitlint/cli':
- specifier: ^19.5.0
- version: 19.5.0(@types/node@22.9.0)(typescript@5.5.4)
+ specifier: ^19.6.0
+ version: 19.6.0(@types/node@22.9.0)(typescript@5.5.4)
'@commitlint/config-conventional':
- specifier: ^19.5.0
- version: 19.5.0
+ specifier: ^19.6.0
+ version: 19.6.0
'@eslint/js':
specifier: ^9.15.0
version: 9.15.0
specifier: ^50.5.0
version: 50.5.0(eslint@9.15.0(jiti@1.21.6))
eslint-plugin-perfectionist:
- specifier: ^3.9.1
- version: 3.9.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
+ specifier: ^4.0.1
+ version: 4.0.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
husky:
specifier: ^9.1.7
version: 9.1.7
cpu: [x64]
os: [win32]
- '@commitlint/cli@19.5.0':
- resolution: {integrity: sha512-gaGqSliGwB86MDmAAKAtV9SV1SHdmN8pnGq4EJU4+hLisQ7IFfx4jvU4s+pk6tl0+9bv6yT+CaZkufOinkSJIQ==}
+ '@commitlint/cli@19.6.0':
+ resolution: {integrity: sha512-v17BgGD9w5KnthaKxXnEg6KLq6DYiAxyiN44TpiRtqyW8NSq+Kx99mkEG8Qo6uu6cI5eMzMojW2muJxjmPnF8w==}
engines: {node: '>=v18'}
hasBin: true
- '@commitlint/config-conventional@19.5.0':
- resolution: {integrity: sha512-OBhdtJyHNPryZKg0fFpZNOBM1ZDbntMvqMuSmpfyP86XSfwzGw4CaoYRG4RutUPg0BTK07VMRIkNJT6wi2zthg==}
+ '@commitlint/config-conventional@19.6.0':
+ resolution: {integrity: sha512-DJT40iMnTYtBtUfw9ApbsLZFke1zKh6llITVJ+x9mtpHD08gsNXaIRqHTmwTZL3dNX5+WoyK7pCN/5zswvkBCQ==}
engines: {node: '>=v18'}
'@commitlint/config-validator@19.5.0':
resolution: {integrity: sha512-yNy088miE52stCI3dhG/vvxFo9e4jFkU1Mj3xECfzp/bIS/JUay4491huAlVcffOoMK1cd296q0W92NlER6r3A==}
engines: {node: '>=v18'}
- '@commitlint/is-ignored@19.5.0':
- resolution: {integrity: sha512-0XQ7Llsf9iL/ANtwyZ6G0NGp5Y3EQ8eDQSxv/SRcfJ0awlBY4tHFAvwWbw66FVUaWICH7iE5en+FD9TQsokZ5w==}
+ '@commitlint/is-ignored@19.6.0':
+ resolution: {integrity: sha512-Ov6iBgxJQFR9koOupDPHvcHU9keFupDgtB3lObdEZDroiG4jj1rzky60fbQozFKVYRTUdrBGICHG0YVmRuAJmw==}
engines: {node: '>=v18'}
- '@commitlint/lint@19.5.0':
- resolution: {integrity: sha512-cAAQwJcRtiBxQWO0eprrAbOurtJz8U6MgYqLz+p9kLElirzSCc0vGMcyCaA1O7AqBuxo11l1XsY3FhOFowLAAg==}
+ '@commitlint/lint@19.6.0':
+ resolution: {integrity: sha512-LRo7zDkXtcIrpco9RnfhOKeg8PAnE3oDDoalnrVU/EVaKHYBWYL1DlRR7+3AWn0JiBqD8yKOfetVxJGdEtZ0tg==}
engines: {node: '>=v18'}
'@commitlint/load@19.5.0':
resolution: {integrity: sha512-CU/GscZhCUsJwcKTJS9Ndh3AKGZTNFIOoQB2n8CmFnizE0VnEuJoum+COW+C1lNABEeqk6ssfc1Kkalm4bDklA==}
engines: {node: '>=v18'}
- '@commitlint/rules@19.5.0':
- resolution: {integrity: sha512-hDW5TPyf/h1/EufSHEKSp6Hs+YVsDMHazfJ2azIk9tHPXS6UqSz1dIRs1gpqS3eMXgtkT7JH6TW4IShdqOwhAw==}
+ '@commitlint/rules@19.6.0':
+ resolution: {integrity: sha512-1f2reW7lbrI0X0ozZMesS/WZxgPa4/wi56vFuJENBmed6mWq5KsheN/nxqnl/C23ioxpPO/PL6tXpiiFy5Bhjw==}
engines: {node: '>=v18'}
'@commitlint/to-lines@19.5.0':
resolution: {integrity: sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==}
engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0}
- '@stylistic/eslint-plugin@2.10.1':
- resolution: {integrity: sha512-U+4yzNXElTf9q0kEfnloI9XbOyD4cnEQCxjUI94q0+W++0GAEQvJ/slwEj9lwjDHfGADRSr+Tco/z0XJvmDfCQ==}
+ '@stylistic/eslint-plugin@2.11.0':
+ resolution: {integrity: sha512-PNRHbydNG5EH8NK4c+izdJlxajIR6GxcUhzsYNRsn6Myep4dsZt0qFCz3rCPnkvgO5FYibDcMqgNHUT+zvjYZw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
peerDependencies:
eslint: '>=8.40.0'
peerDependencies:
eslint: '>=8.23.0'
- eslint-plugin-perfectionist@3.9.1:
- resolution: {integrity: sha512-9WRzf6XaAxF4Oi5t/3TqKP5zUjERhasHmLFHin2Yw6ZAp/EP/EVA2dr3BhQrrHWCm5SzTMZf0FcjDnBkO2xFkA==}
+ eslint-plugin-perfectionist@4.0.1:
+ resolution: {integrity: sha512-D7AmBw98rdfqf9wR3JTF1eLZpKmmG4jXRUSPzl2s5vVzUVSLz8pJx0RhWN6x/aHVjcJkeFBe/P4SCQWM+PdKkA==}
engines: {node: ^18.0.0 || >=20.0.0}
peerDependencies:
- astro-eslint-parser: ^1.0.2
eslint: '>=8.0.0'
- svelte: '>=3.0.0'
- svelte-eslint-parser: ^0.41.1
- vue-eslint-parser: '>=9.0.0'
- peerDependenciesMeta:
- astro-eslint-parser:
- optional: true
- svelte:
- optional: true
- svelte-eslint-parser:
- optional: true
- vue-eslint-parser:
- optional: true
eslint-plugin-promise@7.1.0:
resolution: {integrity: sha512-8trNmPxdAy3W620WKDpaS65NlM5yAumod6XeC4LOb+jxlkG4IVcp68c6dXY2ev+uT4U1PtG57YDV6EGAXN0GbQ==}
ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
- natural-compare-lite@1.4.0:
- resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==}
-
natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
+ natural-orderby@5.0.0:
+ resolution: {integrity: sha512-kKHJhxwpR/Okycz4HhQKKlhWe4ASEfPgkSWNmKFHd7+ezuQlxkA5cM3+XkBPvm1gmHen3w53qsYAv+8GwRrBlg==}
+ engines: {node: '>=18'}
+
neostandard@0.11.8:
resolution: {integrity: sha512-gKgvK0EDlA0x7F1hMu/UdPCRtSSG4d9CBxVym4PMWoHz8+a1ffEz2fPU5FMH3RUqzL1ACvroUMiywMGWZSY+Mw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@biomejs/cli-win32-x64@1.9.4':
optional: true
- '@commitlint/cli@19.5.0(@types/node@22.9.0)(typescript@5.5.4)':
+ '@commitlint/cli@19.6.0(@types/node@22.9.0)(typescript@5.5.4)':
dependencies:
'@commitlint/format': 19.5.0
- '@commitlint/lint': 19.5.0
+ '@commitlint/lint': 19.6.0
'@commitlint/load': 19.5.0(@types/node@22.9.0)(typescript@5.5.4)
'@commitlint/read': 19.5.0
'@commitlint/types': 19.5.0
- '@types/node'
- typescript
- '@commitlint/config-conventional@19.5.0':
+ '@commitlint/config-conventional@19.6.0':
dependencies:
'@commitlint/types': 19.5.0
conventional-changelog-conventionalcommits: 7.0.2
'@commitlint/types': 19.5.0
chalk: 5.3.0
- '@commitlint/is-ignored@19.5.0':
+ '@commitlint/is-ignored@19.6.0':
dependencies:
'@commitlint/types': 19.5.0
semver: 7.6.3
- '@commitlint/lint@19.5.0':
+ '@commitlint/lint@19.6.0':
dependencies:
- '@commitlint/is-ignored': 19.5.0
+ '@commitlint/is-ignored': 19.6.0
'@commitlint/parse': 19.5.0
- '@commitlint/rules': 19.5.0
+ '@commitlint/rules': 19.6.0
'@commitlint/types': 19.5.0
'@commitlint/load@19.5.0(@types/node@22.9.0)(typescript@5.5.4)':
lodash.mergewith: 4.6.2
resolve-from: 5.0.0
- '@commitlint/rules@19.5.0':
+ '@commitlint/rules@19.6.0':
dependencies:
'@commitlint/ensure': 19.5.0
'@commitlint/message': 19.5.0
'@pkgr/core@0.1.1': {}
- '@stylistic/eslint-plugin@2.10.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)':
+ '@stylistic/eslint-plugin@2.11.0(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)':
dependencies:
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
eslint: 9.15.0(jiti@1.21.6)
minimatch: 9.0.5
semver: 7.6.3
- eslint-plugin-perfectionist@3.9.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4):
+ eslint-plugin-perfectionist@4.0.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4):
dependencies:
'@typescript-eslint/types': 8.15.0
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
eslint: 9.15.0(jiti@1.21.6)
- minimatch: 9.0.5
- natural-compare-lite: 1.4.0
+ natural-orderby: 5.0.0
transitivePeerDependencies:
- supports-color
- typescript
ms@2.1.3: {}
- natural-compare-lite@1.4.0: {}
-
natural-compare@1.4.0: {}
+ natural-orderby@5.0.0: {}
+
neostandard@0.11.8(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4):
dependencies:
'@humanwhocodes/gitignore-to-minimatch': 1.0.2
- '@stylistic/eslint-plugin': 2.10.1(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
+ '@stylistic/eslint-plugin': 2.11.0(eslint@9.15.0(jiti@1.21.6))(typescript@5.5.4)
eslint: 9.15.0(jiti@1.21.6)
eslint-plugin-n: 17.13.2(eslint@9.15.0(jiti@1.21.6))
eslint-plugin-promise: 7.1.0(eslint@9.15.0(jiti@1.21.6))
const tasksMap = generateRandomTasksMap(60, 20)
+/**
+ * @param tasksMap
+ * @returns
+ */
+function arraySortSelect (tasksMap) {
+ const tasksArray = Array.from(tasksMap)
+ return tasksArray.sort((a, b) => {
+ if (a[1] < b[1]) {
+ return -1
+ } else if (a[1] > b[1]) {
+ return 1
+ }
+ return 0
+ })[0]
+}
+
/**
* @param tasksMap
* @returns
return [minKey, minValue]
}
-/**
- * @param tasksMap
- * @returns
- */
-function arraySortSelect (tasksMap) {
- const tasksArray = Array.from(tasksMap)
- return tasksArray.sort((a, b) => {
- if (a[1] < b[1]) {
- return -1
- } else if (a[1] > b[1]) {
- return 1
- }
- return 0
- })[0]
-}
-
const defaultComparator = (a, b) => {
return a < b
}
return randomInt(leftIndex, rightIndex)
}
-/**
- * @param array
- * @param index1
- * @param index2
- */
-function swap (array, index1, index2) {
- const tmp = array[index1]
- array[index1] = array[index2]
- array[index2] = tmp
-}
-
/**
* @param array
* @param leftIndex
return storeIndex
}
+/**
+ * @param tasksMap
+ * @returns
+ */
+function quickSelectLoop (tasksMap) {
+ const tasksArray = Array.from(tasksMap)
+
+ return selectLoop(tasksArray, 0, 0, tasksArray.length - 1, (a, b) => {
+ return a[1] < b[1]
+ })
+}
+
+/**
+ * @param tasksMap
+ * @returns
+ */
+function quickSelectLoopRandomPivot (tasksMap) {
+ const tasksArray = Array.from(tasksMap)
+
+ return selectLoop(
+ tasksArray,
+ 0,
+ 0,
+ tasksArray.length - 1,
+ (a, b) => {
+ return a[1] < b[1]
+ },
+ randomPivotIndexSelect
+ )
+}
+
+/**
+ * @param tasksMap
+ * @returns
+ */
+function quickSelectRecursion (tasksMap) {
+ const tasksArray = Array.from(tasksMap)
+
+ return selectRecursion(tasksArray, 0, 0, tasksArray.length - 1, (a, b) => {
+ return a[1] < b[1]
+ })
+}
+
+/**
+ * @param tasksMap
+ * @returns
+ */
+function quickSelectRecursionRandomPivot (tasksMap) {
+ const tasksArray = Array.from(tasksMap)
+
+ return selectRecursion(
+ tasksArray,
+ 0,
+ 0,
+ tasksArray.length - 1,
+ (a, b) => {
+ return a[1] < b[1]
+ },
+ randomPivotIndexSelect
+ )
+}
+
/**
* @param array
* @param k
}
/**
- * @param tasksMap
- * @returns
- */
-function quickSelectLoop (tasksMap) {
- const tasksArray = Array.from(tasksMap)
-
- return selectLoop(tasksArray, 0, 0, tasksArray.length - 1, (a, b) => {
- return a[1] < b[1]
- })
-}
-
-/**
- * @param tasksMap
- * @returns
- */
-function quickSelectLoopRandomPivot (tasksMap) {
- const tasksArray = Array.from(tasksMap)
-
- return selectLoop(
- tasksArray,
- 0,
- 0,
- tasksArray.length - 1,
- (a, b) => {
- return a[1] < b[1]
- },
- randomPivotIndexSelect
- )
-}
-
-/**
- * @param tasksMap
- * @returns
- */
-function quickSelectRecursion (tasksMap) {
- const tasksArray = Array.from(tasksMap)
-
- return selectRecursion(tasksArray, 0, 0, tasksArray.length - 1, (a, b) => {
- return a[1] < b[1]
- })
-}
-
-/**
- * @param tasksMap
- * @returns
+ * @param array
+ * @param index1
+ * @param index2
*/
-function quickSelectRecursionRandomPivot (tasksMap) {
- const tasksArray = Array.from(tasksMap)
-
- return selectRecursion(
- tasksArray,
- 0,
- 0,
- tasksArray.length - 1,
- (a, b) => {
- return a[1] < b[1]
- },
- randomPivotIndexSelect
- )
+function swap (array, index1, index2) {
+ const tmp = array[index1]
+ array[index1] = array[index2]
+ array[index2] = tmp
}
group('Quick select', () => {
* @param min
* @returns
*/
-function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
+function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
}
max = Math.floor(max)
if (min !== 0) {
min = Math.ceil(min)
- return Math.floor(secureRandom() * (max - min + 1)) + min
+ return Math.floor(Math.random() * (max - min + 1)) + min
}
- return Math.floor(secureRandom() * (max + 1))
+ return Math.floor(Math.random() * (max + 1))
}
/**
* @param min
* @returns
*/
-function getSecureRandomIntegerWithRandomValues (
- max = Number.MAX_SAFE_INTEGER,
- min = 0
-) {
+function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
}
max = Math.floor(max)
if (min !== 0) {
min = Math.ceil(min)
- return Math.floor(secureRandomWithRandomValues() * (max - min + 1)) + min
+ return Math.floor(secureRandom() * (max - min + 1)) + min
}
- return Math.floor(secureRandomWithRandomValues() * (max + 1))
+ return Math.floor(secureRandom() * (max + 1))
}
/**
* @param min
* @returns
*/
-function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
+function getSecureRandomIntegerWithRandomValues (
+ max = Number.MAX_SAFE_INTEGER,
+ min = 0
+) {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
}
max = Math.floor(max)
if (min !== 0) {
min = Math.ceil(min)
- return Math.floor(Math.random() * (max - min + 1)) + min
+ return Math.floor(secureRandomWithRandomValues() * (max - min + 1)) + min
}
- return Math.floor(Math.random() * (max + 1))
+ return Math.floor(secureRandomWithRandomValues() * (max + 1))
}
group('Random Integer Generator', () => {