chore(desp-dev): apply updates
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 19 Nov 2024 15:08:21 +0000 (16:08 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 19 Nov 2024 15:08:21 +0000 (16:08 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
.lintstagedrc.js
benchmark-utils.mjs
busy-wait.mjs
max.mjs
min.mjs
package.json
pnpm-lock.yaml
quick-select.mjs
random.mjs

index 720c26a41467a6890a1eebea9e78ae3fdd904bce..8e1f8dbecafbd65e0dab9902230fbb2a8193ebf5 100644 (file)
@@ -1,8 +1,8 @@
 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'],
 }
index 8e32f90a5eca3bd6923a2fc2b67ee9d346776d3a..02e2a95a1dea4cac03976fc038dddae0bf3e14a7 100644 (file)
@@ -1,21 +1,5 @@
 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
@@ -71,6 +55,22 @@ export function generateRandomObject (
   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
index dd9f6917241a3f38598bf17cdedd4b6f1546149f..3786e8cf25e9bfe0d5ee4effbf246fba585f10a1 100644 (file)
@@ -5,26 +5,6 @@ import { sleep } from './benchmark-utils.mjs'
 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
@@ -41,6 +21,15 @@ async function divideAndConquerTimeoutBusyWait (
   } 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
@@ -59,6 +48,17 @@ async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) {
   })
 }
 
+/**
+ * @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)
diff --git a/max.mjs b/max.mjs
index 12b458c66f30f53438339c7f8034a491685a93f0..23d856e9a2a242bad517150e935ca59df7eb07db 100644 (file)
--- a/max.mjs
+++ b/max.mjs
@@ -23,9 +23,9 @@ function loopMax (values) {
  * @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
   )
 }
@@ -35,9 +35,9 @@ function reduceTernaryMax (values) {
  * @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
   )
 }
diff --git a/min.mjs b/min.mjs
index 44beb09d99571b35062c205ff1ba3ed3df512fa4..8d259febdddcdf4d31c9661c8e711375c03b5e5e 100644 (file)
--- a/min.mjs
+++ b/min.mjs
@@ -23,9 +23,9 @@ function loopMin (values) {
  * @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
   )
 }
@@ -35,9 +35,9 @@ function reduceTernaryMin (values) {
  * @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
   )
 }
index 993f944e54fe442e6fb4531d73e158fcc2de1439..a7a8aa817aedf0a43ea083d409cf22da02ba35d5 100644 (file)
   },
   "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",
index fb1dc6eaba46a6a07f7c82ac161e0ac82d1087aa..4d996267b8b44a464626df3e52715c4cdb07bfe6 100644 (file)
@@ -46,11 +46,11 @@ importers:
         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
@@ -64,8 +64,8 @@ importers:
         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
@@ -142,13 +142,13 @@ packages:
     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':
@@ -167,12 +167,12 @@ packages:
     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':
@@ -195,8 +195,8 @@ packages:
     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':
@@ -288,8 +288,8 @@ packages:
     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'
@@ -695,24 +695,11 @@ packages:
     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==}
@@ -1241,12 +1228,13 @@ packages:
   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}
@@ -1761,10 +1749,10 @@ snapshots:
   '@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
@@ -1774,7 +1762,7 @@ snapshots:
       - '@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
@@ -1800,16 +1788,16 @@ snapshots:
       '@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)':
@@ -1853,7 +1841,7 @@ snapshots:
       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
@@ -1945,7 +1933,7 @@ snapshots:
 
   '@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)
@@ -2470,13 +2458,12 @@ snapshots:
       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
@@ -3018,14 +3005,14 @@ snapshots:
 
   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))
index 411c897df2128402085fac53ef1b7a0277558cee..b158c6b741e602247665690c97cb4a10596022e2 100644 (file)
@@ -20,6 +20,22 @@ function generateRandomTasksMap (
 
 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
@@ -38,22 +54,6 @@ function loopSelect (tasksMap) {
   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
 }
@@ -66,17 +66,6 @@ const randomPivotIndexSelect = (leftIndex, rightIndex) => {
   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
@@ -105,6 +94,68 @@ function partition (
   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
@@ -166,65 +217,14 @@ function selectRecursion (
 }
 
 /**
- * @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', () => {
index b616a7a75bd348eac179f30cc3beee09eacfd669..8b4b2a6c055cb133d7b2ce5c1d98e65ea862abfe 100644 (file)
@@ -13,16 +13,16 @@ const maximum = 281474976710655
  * @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))
 }
 
 /**
@@ -30,19 +30,16 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
  * @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))
 }
 
 /**
@@ -50,16 +47,19 @@ function getSecureRandomIntegerWithRandomValues (
  * @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', () => {