1 import { CircularArray
} from
'./circular-array'
2 import type { WorkerChoiceStrategyOptions
} from
'./pools/selection-strategies/selection-strategies-types'
3 import type { TasksUsage
} from
'./pools/worker'
6 * An intentional empty function.
8 export const EMPTY_FUNCTION
: () => void = Object.freeze(() => {
9 /* Intentionally empty */
13 * Initial tasks usage statistics.
15 export const INITIAL_TASKS_USAGE
: TasksUsage
= {
19 runTimeHistory
: new CircularArray(),
26 * Default worker choice strategy options.
28 export const DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
: WorkerChoiceStrategyOptions
=
34 * Compute the median of the given data set.
36 * @param dataSet - Data set.
37 * @returns The median of the given data set.
39 export const median
= (dataSet
: number[]): number => {
40 if (Array.isArray(dataSet
) && dataSet
.length
=== 1) {
43 const sortedDataSet
= dataSet
.slice().sort((a
, b
) => a
- b
)
44 const middleIndex
= Math.floor(sortedDataSet
.length
/ 2)
45 if (sortedDataSet
.length
% 2 === 0) {
46 return sortedDataSet
[middleIndex
/ 2]
48 return (sortedDataSet
[middleIndex
- 1] + sortedDataSet
[middleIndex
]) / 2