integer-sorting/radix-sort

View on GitHub
src/array/core/cumulativeHistogram.js

Summary

Maintainability
A
0 mins
Test Coverage
import assert from 'assert';

import accumulate from './accumulate.js';
import histogram from './histogram.js';

/**
 * O(M+N) time where N=j-i and M = ch.length - offset.
 */
const cumulativeHistogram = (array, i, j, ch, offset) => {
    assert(Number.isInteger(offset));
    assert(i >= 0 && i <= j && j <= array.length);
    histogram(array, i, j, ch, offset); // O(N)
    accumulate(ch, offset, ch.length); // O(M)
};

export default cumulativeHistogram;