From 46025ff965d767e3c8c7784e9bf366dffa0cf904 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 17 Nov 2025 18:19:07 +0100 Subject: [PATCH] chore: silence linter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmark-utils.mjs | 37 +++++++++--------- busy-wait.mjs | 22 +++++++---- fibonacci.mjs | 23 +++++++----- max.mjs | 24 ++++++------ min.mjs | 24 ++++++------ quick-select.mjs | 91 ++++++++++++++++++++++++++------------------- random.mjs | 21 ++++++----- 7 files changed, 136 insertions(+), 106 deletions(-) diff --git a/benchmark-utils.mjs b/benchmark-utils.mjs index 02e2a95..1d622c9 100644 --- a/benchmark-utils.mjs +++ b/benchmark-utils.mjs @@ -1,10 +1,10 @@ import { getRandomValues, randomBytes, randomInt } from 'node:crypto' /** - * - * @param max - * @param min - * @returns + * Generates a random floating-point number between min and max. + * @param {number} max - The maximum value (inclusive). + * @param {number} min - The minimum value (inclusive). + * @returns {number} A random floating-point number between min and max. */ export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) { if (max < min) { @@ -17,11 +17,11 @@ export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) { } /** - * - * @param size - * @param max - * @param numberGenerator - * @returns + * Generates an array of random numbers. + * @param {number} size - The size of the array to generate. + * @param {number} max - The maximum value for generated numbers. + * @param {(max: number, min?: number) => number} numberGenerator - The function to use for generating numbers. + * @returns {Array} An array of random numbers. */ export function generateRandomNumberArray ( size, @@ -36,11 +36,11 @@ export function generateRandomNumberArray ( } /** - * - * @param sizeMax - * @param numberMax - * @param numberGenerator - * @returns + * Generates a random object with numeric values. + * @param {number} sizeMax - The maximum size of the object. + * @param {number} numberMax - The maximum value for generated numbers. + * @param {(max: number, min?: number) => number} numberGenerator - The function to use for generating numbers. + * @returns {object} A random object with numeric properties. */ export function generateRandomObject ( sizeMax = 500, @@ -57,7 +57,7 @@ export function generateRandomObject ( /** * Generate a cryptographically secure random number in the [0,1[ range - * @returns + * @returns {number} A secure random number between 0 (inclusive) and 1 (exclusive). */ export function secureRandom () { return randomBytes(4).readUInt32LE() / 0x100000000 @@ -65,15 +65,16 @@ export function secureRandom () { /** * Generate a cryptographically secure random number in the [0,1[ range - * @returns + * @returns {number} A secure random number between 0 (inclusive) and 1 (exclusive). */ export function secureRandomWithRandomValues () { return getRandomValues(new Uint32Array(1))[0] / 0x100000000 } /** - * @param ms - * @returns + * Asynchronously sleep for a specified number of milliseconds. + * @param {number} ms - The number of milliseconds to sleep. + * @returns {Promise} A promise that resolves after the specified delay. */ export async function sleep (ms) { return await new Promise(resolve => setTimeout(resolve, ms)) diff --git a/busy-wait.mjs b/busy-wait.mjs index 3786e8c..3cbe076 100644 --- a/busy-wait.mjs +++ b/busy-wait.mjs @@ -6,8 +6,10 @@ const timeout = 2000 const interval = 1000 /** - * @param timeoutMs - * @param intervalMs + * Busy wait implementation using divide and conquer strategy with sleep intervals. + * @param {number} timeoutMs - The total timeout in milliseconds. + * @param {number} intervalMs - The interval between checks in milliseconds. + * @returns {Promise} A promise that resolves after the timeout. */ async function divideAndConquerTimeoutBusyWait ( timeoutMs, @@ -22,7 +24,9 @@ async function divideAndConquerTimeoutBusyWait ( } /** - * @param timeoutMs + * Dummy busy wait implementation using performance.now() in a tight loop. + * @param {number} timeoutMs - The timeout in milliseconds. + * @returns {void} */ function dummyTimeoutBusyWait (timeoutMs) { const timeoutTimestampMs = performance.now() + timeoutMs @@ -31,8 +35,10 @@ function dummyTimeoutBusyWait (timeoutMs) { } /** - * @param timeoutMs - * @param intervalMs + * Busy wait implementation using setInterval. + * @param {number} timeoutMs - The total timeout in milliseconds. + * @param {number} intervalMs - The interval between checks in milliseconds. + * @returns {Promise} A promise that resolves after the timeout. */ async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) { await new Promise(resolve => { @@ -49,8 +55,10 @@ async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) { } /** - * @param timeoutMs - * @param intervalMs + * Busy wait implementation using repeated sleep calls. + * @param {number} timeoutMs - The total timeout in milliseconds. + * @param {number} intervalMs - The interval between sleep calls in milliseconds. + * @returns {Promise} A promise that resolves after the timeout. */ async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) { const timeoutTimestampMs = performance.now() + timeoutMs diff --git a/fibonacci.mjs b/fibonacci.mjs index 0ed51b4..c0cc843 100644 --- a/fibonacci.mjs +++ b/fibonacci.mjs @@ -3,8 +3,9 @@ import { bench, group, run } from 'tatami-ng' const number = 30 /** - * @param num - * @returns + * Calculates the Fibonacci number at position num using a loop with array. + * @param {number} num - The position in the Fibonacci sequence. + * @returns {number} The Fibonacci number at the specified position. */ function fibonacciLoop (num) { const fib = [] @@ -17,9 +18,9 @@ function fibonacciLoop (num) { } /** - * - * @param num - * @returns + * Calculates the Fibonacci number at position num using a while loop. + * @param {number} num - The position in the Fibonacci sequence. + * @returns {number} The Fibonacci number at the specified position. */ function fibonacciLoopWhile (num) { let current = 1 @@ -33,8 +34,9 @@ function fibonacciLoopWhile (num) { } /** - * @param num - * @returns + * Calculates the Fibonacci number at position num using recursion. + * @param {number} num - The position in the Fibonacci sequence. + * @returns {number} The Fibonacci number at the specified position. */ function fibonacciRecursion (num) { if (num <= 1) return num @@ -42,9 +44,10 @@ function fibonacciRecursion (num) { } /** - * @param num - * @param memo - * @returns + * Calculates the Fibonacci number at position num using recursion with memoization. + * @param {number} num - The position in the Fibonacci sequence. + * @param {{[key: number]: number}} [memo] - The memoization object to cache results. + * @returns {number} The Fibonacci number at the specified position. */ function fibonacciRecursionMemoization (num, memo) { memo = memo || {} diff --git a/max.mjs b/max.mjs index 23d856e..2b43541 100644 --- a/max.mjs +++ b/max.mjs @@ -6,9 +6,9 @@ const size = 10000 const testArray = generateRandomNumberArray(size) /** - * - * @param values - * @returns + * Finds the maximum value in an array using a loop. + * @param {Array} values - The array of numbers to search. + * @returns {number} The maximum value in the array. */ function loopMax (values) { let maximum = Number.NEGATIVE_INFINITY @@ -19,9 +19,9 @@ function loopMax (values) { } /** - * - * @param values - * @returns + * Finds the maximum value in an array using reduce with Math.max. + * @param {Array} values - The array of numbers to search. + * @returns {number} The maximum value in the array. */ function reduceMathMax (values) { return values.reduce( @@ -31,9 +31,9 @@ function reduceMathMax (values) { } /** - * - * @param values - * @returns + * Finds the maximum value in an array using reduce with ternary operator. + * @param {Array} values - The array of numbers to search. + * @returns {number} The maximum value in the array. */ function reduceTernaryMax (values) { return values.reduce( @@ -43,9 +43,9 @@ function reduceTernaryMax (values) { } /** - * - * @param values - * @returns + * Finds the maximum value in an array by sorting. + * @param {Array} values - The array of numbers to search. + * @returns {number} The maximum value in the array. */ function sortMax (values) { return values.sort((a, b) => b - a)[0] diff --git a/min.mjs b/min.mjs index 8d259fe..2e5e407 100644 --- a/min.mjs +++ b/min.mjs @@ -6,9 +6,9 @@ const size = 10000 const testArray = generateRandomNumberArray(size) /** - * - * @param values - * @returns + * Finds the minimum value in an array using a loop. + * @param {Array} values - The array of numbers to search. + * @returns {number} The minimum value in the array. */ function loopMin (values) { let minimum = Number.POSITIVE_INFINITY @@ -19,9 +19,9 @@ function loopMin (values) { } /** - * - * @param values - * @returns + * Finds the minimum value in an array using reduce with Math.min. + * @param {Array} values - The array of numbers to search. + * @returns {number} The minimum value in the array. */ function reduceMathMin (values) { return values.reduce( @@ -31,9 +31,9 @@ function reduceMathMin (values) { } /** - * - * @param values - * @returns + * Finds the minimum value in an array using reduce with ternary operator. + * @param {Array} values - The array of numbers to search. + * @returns {number} The minimum value in the array. */ function reduceTernaryMin (values) { return values.reduce( @@ -43,9 +43,9 @@ function reduceTernaryMin (values) { } /** - * - * @param values - * @returns + * Finds the minimum value in an array by sorting. + * @param {Array} values - The array of numbers to search. + * @returns {number} The minimum value in the array. */ function sortMin (values) { return values.sort((a, b) => a - b)[0] diff --git a/quick-select.mjs b/quick-select.mjs index b158c6b..645cad2 100644 --- a/quick-select.mjs +++ b/quick-select.mjs @@ -2,9 +2,10 @@ import { randomInt } from 'node:crypto' import { bench, group, run } from 'tatami-ng' /** - * @param numberOfWorkers - * @param maxNumberOfTasksPerWorker - * @returns + * Generates a random tasks map for benchmarking. + * @param {number} numberOfWorkers - The number of workers. + * @param {number} maxNumberOfTasksPerWorker - The maximum number of tasks per worker. + * @returns {Map} A map with worker IDs as keys and task counts as values. */ function generateRandomTasksMap ( numberOfWorkers, @@ -21,8 +22,9 @@ function generateRandomTasksMap ( const tasksMap = generateRandomTasksMap(60, 20) /** - * @param tasksMap - * @returns + * Selects the task with minimum value using array sort. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array} The task entry with the minimum value. */ function arraySortSelect (tasksMap) { const tasksArray = Array.from(tasksMap) @@ -37,8 +39,9 @@ function arraySortSelect (tasksMap) { } /** - * @param tasksMap - * @returns + * Selects the task with minimum value using a loop. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array|number} The task entry with the minimum value. */ function loopSelect (tasksMap) { let minKey @@ -67,12 +70,14 @@ const randomPivotIndexSelect = (leftIndex, rightIndex) => { } /** - * @param array - * @param leftIndex - * @param rightIndex - * @param pivotIndex - * @param compare - * @returns + * Partitions an array for quickselect algorithm. + * @template T + * @param {Array} array - The array to partition. + * @param {number} leftIndex - The left index of the partition range. + * @param {number} rightIndex - The right index of the partition range. + * @param {number} pivotIndex - The index of the pivot element. + * @param {(a: T, b: T) => boolean} compare - The comparison function. + * @returns {number} The final position of the pivot element. */ function partition ( array, @@ -95,8 +100,9 @@ function partition ( } /** - * @param tasksMap - * @returns + * Selects task using quickselect with loop implementation. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array} The task entry with the minimum value. */ function quickSelectLoop (tasksMap) { const tasksArray = Array.from(tasksMap) @@ -107,8 +113,9 @@ function quickSelectLoop (tasksMap) { } /** - * @param tasksMap - * @returns + * Selects task using quickselect with loop and random pivot. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array} The task entry with the minimum value. */ function quickSelectLoopRandomPivot (tasksMap) { const tasksArray = Array.from(tasksMap) @@ -126,8 +133,9 @@ function quickSelectLoopRandomPivot (tasksMap) { } /** - * @param tasksMap - * @returns + * Selects task using quickselect with recursion. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array} The task entry with the minimum value. */ function quickSelectRecursion (tasksMap) { const tasksArray = Array.from(tasksMap) @@ -138,8 +146,9 @@ function quickSelectRecursion (tasksMap) { } /** - * @param tasksMap - * @returns + * Selects task using quickselect with recursion and random pivot. + * @param {Map} tasksMap - The map of tasks to search. + * @returns {Array} The task entry with the minimum value. */ function quickSelectRecursionRandomPivot (tasksMap) { const tasksArray = Array.from(tasksMap) @@ -157,13 +166,15 @@ function quickSelectRecursionRandomPivot (tasksMap) { } /** - * @param array - * @param k - * @param leftIndex - * @param rightIndex - * @param compare - * @param pivotIndexSelect - * @returns + * Quickselect algorithm using loop implementation. + * @template T + * @param {Array} array - The array to search. + * @param {number} k - The k-th element to find. + * @param {number} leftIndex - The left boundary index. + * @param {number} rightIndex - The right boundary index. + * @param {(a: T, b: T) => boolean} compare - The comparison function. + * @param {(leftIndex: number, rightIndex: number) => number} pivotIndexSelect - The pivot selection function. + * @returns {T} The k-th element. */ function selectLoop ( array, @@ -188,13 +199,15 @@ function selectLoop ( } /** - * @param array - * @param k - * @param leftIndex - * @param rightIndex - * @param compare - * @param pivotIndexSelect - * @returns + * Quickselect algorithm using recursion. + * @template T + * @param {Array} array - The array to search. + * @param {number} k - The k-th element to find. + * @param {number} leftIndex - The left boundary index. + * @param {number} rightIndex - The right boundary index. + * @param {(a: T, b: T) => boolean} compare - The comparison function. + * @param {(leftIndex: number, rightIndex: number) => number} pivotIndexSelect - The pivot selection function. + * @returns {T} The k-th element. */ function selectRecursion ( array, @@ -217,9 +230,11 @@ function selectRecursion ( } /** - * @param array - * @param index1 - * @param index2 + * Swaps two elements in an array. + * @param {Array} array - The array containing elements to swap. + * @param {number} index1 - The index of the first element. + * @param {number} index2 - The index of the second element. + * @returns {void} */ function swap (array, index1, index2) { const tmp = array[index1] diff --git a/random.mjs b/random.mjs index 8b4b2a6..f5aac7b 100644 --- a/random.mjs +++ b/random.mjs @@ -9,9 +9,10 @@ import { const maximum = 281474976710655 /** - * @param max - * @param min - * @returns + * Generates a random integer between min and max using Math.random. + * @param {number} max - The maximum value (inclusive). + * @param {number} min - The minimum value (inclusive). + * @returns {number} A random integer between min and max. */ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { if (max < min || max < 0 || min < 0) { @@ -26,9 +27,10 @@ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { } /** - * @param max - * @param min - * @returns + * Generates a cryptographically secure random integer using secureRandom. + * @param {number} max - The maximum value (inclusive). + * @param {number} min - The minimum value (inclusive). + * @returns {number} A secure random integer between min and max. */ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { if (max < min || max < 0 || min < 0) { @@ -43,9 +45,10 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { } /** - * @param max - * @param min - * @returns + * Generates a cryptographically secure random integer using getRandomValues. + * @param {number} max - The maximum value (inclusive). + * @param {number} min - The minimum value (inclusive). + * @returns {number} A secure random integer between min and max. */ function getSecureRandomIntegerWithRandomValues ( max = Number.MAX_SAFE_INTEGER, -- 2.43.0