<commit_before>////
///  CategoryHeaderCellSizeCalculator.swift
//

import FutureKit


public class CategoryHeaderCellSizeCalculator: NSObject {
    private typealias CellJob = (cellItems: [StreamCellItem], width: CGFloat, columnCount: Int, completion: ElloEmptyCompletion)
    private var cellJobs: [CellJob] = []
    private var screenWidth: CGFloat = 0.0
    private var maxWidth: CGFloat = 0.0
    private var columnCount: Int = 1
    private var cellItems: [StreamCellItem] = []
    private var completion: ElloEmptyCompletion = {}

    // MARK: Public

    public func processCells(cellItems: [StreamCellItem], withWidth width: CGFloat, columnCount: Int, completion: ElloEmptyCompletion) {
        let job: CellJob = (cellItems: cellItems, width: width, columnCount: columnCount, completion: completion)
        cellJobs.append(job)
        if cellJobs.count == 1 {
            processJob(job)
        }
    }

    // MARK: Private

    private func processJob(job: CellJob) {
        self.completion = {
            if self.cellJobs.count > 0 {
                self.cellJobs.removeAtIndex(0)
            }
            job.completion()
            if let nextJob = self.cellJobs.safeValue(0) {
                self.processJob(nextJob)
            }
        }
        self.cellItems = job.cellItems
        self.screenWidth = job.width
        self.columnCount = job.columnCount
        loadNext()
    }

    private func loadNext() {
        self.maxWidth = screenWidth
        guard !self.cellItems.isEmpty else {
            completion()
            return
        }

        let item = cellItems.removeAtIndex(0)

        item.calculatedCellHeights.oneColumn = 150
        item.calculatedCellHeights.multiColumn = 150
        loadNext()
    }

    private func oneColumnImageHeight(imageRegion: ImageRegion) -> CGFloat {
        var imageWidth = maxWidth
        if let assetWidth = imageRegion.asset?.oneColumnAttachment?.width {
            imageWidth = min(maxWidth, CGFloat(assetWidth))
        }
        return ceil(imageWidth / StreamImageCellSizeCalculator.aspectRatioForImageRegion(imageRegion))
    }
}<commit_msg>calculate height according to width<commit_after>////
///  CategoryHeaderCellSizeCalculator.swift
//

import FutureKit


public class CategoryHeaderCellSizeCalculator: NSObject {
    static let ratio: CGFloat = 320 / 192

    private typealias CellJob = (cellItems: [StreamCellItem], width: CGFloat, columnCount: Int, completion: ElloEmptyCompletion)
    private var cellJobs: [CellJob] = []
    private var screenWidth: CGFloat = 0.0
    private var columnCount: Int = 1
    private var cellItems: [StreamCellItem] = []
    private var completion: ElloEmptyCompletion = {}

    // MARK: Public

    public func processCells(cellItems: [StreamCellItem], withWidth width: CGFloat, columnCount: Int, completion: ElloEmptyCompletion) {
        let job: CellJob = (cellItems: cellItems, width: width, columnCount: columnCount, completion: completion)
        cellJobs.append(job)
        if cellJobs.count == 1 {
            processJob(job)
        }
    }

    // MARK: Private

    private func processJob(job: CellJob) {
        self.completion = {
            if self.cellJobs.count > 0 {
                self.cellJobs.removeAtIndex(0)
            }
            job.completion()
            if let nextJob = self.cellJobs.safeValue(0) {
                self.processJob(nextJob)
            }
        }
        self.cellItems = job.cellItems
        self.screenWidth = job.width
        self.columnCount = job.columnCount
        loadNext()
    }

    private func loadNext() {
        guard !self.cellItems.isEmpty else {
            completion()
            return
        }

        let item = cellItems.removeAtIndex(0)
        let height = screenWidth / CategoryHeaderCellSizeCalculator.ratio
        item.calculatedCellHeights.oneColumn = height
        item.calculatedCellHeights.multiColumn = height
        loadNext()
    }
}
{'fraction_non_alphanumeric': 0.087515762925599, 'fraction_numerical': 0.007566204287515763, 'mean_word_length': 2.392643284858854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021744', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1075, 'n_words': 259}