     return cdf.map { $0 > 0 ? f * Float($0 - cdfMin!) : 0.0 }
 }
 
-func mandelbrotColorize(_ imageWidth: Int, _ imageHeight: Int, _ maxIterations: Int, _ gradient: Gradient, _ imageData: inout [PixelColor], _ iterationsHistogram: [Int], _ resultsPerPoint: [CalculationResult]) {
+func mandelbrotColorize(_ imageWidth: Int, _ imageHeight: Int, _ maxIterations: Int, _ gradient: Gradient, _ imageData: inout [PixelColor], _ iterationsHistogram: [Int32], _ resultsPerPoint: [CalculationResult]) {
     let equalizedIterations = equalizeHistogram(iterationsHistogram, maxIterations)
 
     for (pixel, calcResult) in resultsPerPoint.enumerated() {


func go(_ imageWidth: Int, _ imageHeight: Int, _ maxIterations: Int, _ centerX: Double, _ centerY: Double, _ height: Double, _ gradient: Gradient, _ repetitions: Int) -> ([PixelColor], [Double]) {
    // iterationsHistogram: for simplicity we only use indices [1] .. [max_iterations], [0] is unused
    var iterationsHistogram = [Int](repeating: 0, count: maxIterations + 1)

    // For every point store a tuple consisting of the final iteration and (for escaped points)
    // the distance to the next iteration (as value of 0.0 .. 1.0).
    var resultsPerPoint = [CalculationResult](repeating: CalculationResult(iter: 0, distanceToNextIteration: 0.0), count: imageWidth * imageHeight)

    var imageData = [PixelColor](repeating: PixelColor(r: 0, g: 0, b: 0), count: imageWidth * imageHeight)
    var durations = [Double]();

    for _ in 0 ..< repetitions {
        let t1 = Date()

    return (1.0 - t) * a + t * b
}

func cumsum(_ iterationsHistogram: [Int32]) -> [Int32] {
    var cdf = [Int32](repeating: 0, count: iterationsHistogram.count)
    var total: Int32 = 0

    for (i, n) in iterationsHistogram.enumerated() {
        total += n
