<commit_before>//
//  StreamCollectionViewLayout.swift
//  Ello
//
//  Created by Sean on 1/26/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//  Big thanks to https://github.com/chiahsien
//  Swiftified and modified https://github.com/chiahsien/CHTCollectionViewWaterfallLayout

@objc
public protocol StreamCollectionViewLayoutDelegate: UICollectionViewDelegate {

    func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize

    func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        heightForItemAtIndexPath indexPath: NSIndexPath,
        numberOfColumns: NSInteger) -> CGFloat

    optional func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        groupForItemAtIndexPath indexPath: NSIndexPath) -> String

    optional func colletionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        insetForSectionAtIndex section: NSInteger) -> UIEdgeInsets

    optional func colletionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        minimumInteritemSpacingForSectionAtIndex section: NSInteger) -> CGFloat

    optional func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        isFullWidthAtIndexPath indexPath: NSIndexPath) -> Bool
}

public class StreamCollectionViewLayout: UICollectionViewLayout {

    enum Direction {
        case ShortestFirst
        case LeftToRight
        case RightToLeft
    }

    var columnCount: Int {
        didSet { invalidateLayout() }
    }

    var minimumColumnSpacing: CGFloat {
        didSet { invalidateLayout() }
    }

    var minimumInteritemSpacing: CGFloat {
        didSet { invalidateLayout() }
    }

    var sectionInset: UIEdgeInsets {
        didSet { invalidateLayout() }
    }

    var itemRenderDirection: Direction {
        didSet { invalidateLayout() }
    }

    weak var delegate: StreamCollectionViewLayoutDelegate? {
        get {
            return collectionView!.delegate as? StreamCollectionViewLayoutDelegate
        }
    }
    var columnHeights = [CGFloat]()
    var sectionItemAttributes = [[UICollectionViewLayoutAttributes]]()
    var allItemAttributes = [UICollectionViewLayoutAttributes]()
    var unionRects = [CGRect]()
    let unionSize = 20

    override init(){
        columnCount = 2
        minimumInteritemSpacing = 10
        minimumColumnSpacing = 10
        sectionInset = UIEdgeInsetsZero
        itemRenderDirection = .ShortestFirst
        super.init()
    }

    required public init?(coder aDecoder: NSCoder) {
        columnCount = 2
        minimumInteritemSpacing = 10
        minimumColumnSpacing = 10
        sectionInset = UIEdgeInsetsZero
        itemRenderDirection = .ShortestFirst
        super.init(coder: aDecoder)
    }

    override public func prepareLayout(){
        super.prepareLayout()

        guard let numberOfSections = self.collectionView?.numberOfSections() else {
            return
        }

        unionRects.removeAll()
        columnHeights.removeAll()
        allItemAttributes.removeAll()
        sectionItemAttributes.removeAll()

        for _ in 0..<columnCount {
            self.columnHeights.append(0)
        }

        for section in 0..<numberOfSections {
            addAttributesForSection(section)
        }

        let itemCounts = allItemAttributes.count
        var index = 0<commit_msg>these should match with the values assigned from StreamViewController<commit_after>//
//  StreamCollectionViewLayout.swift
//  Ello
//
//  Created by Sean on 1/26/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//  Big thanks to https://github.com/chiahsien
//  Swiftified and modified https://github.com/chiahsien/CHTCollectionViewWaterfallLayout

@objc
public protocol StreamCollectionViewLayoutDelegate: UICollectionViewDelegate {

    func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize

    func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        heightForItemAtIndexPath indexPath: NSIndexPath,
        numberOfColumns: NSInteger) -> CGFloat

    optional func collectionView (collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        groupForItemAtIndexPath indexPath: NSIndexPath) -> String

    optional func colletionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        insetForSectionAtIndex section: NSInteger) -> UIEdgeInsets

    optional func colletionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        minimumInteritemSpacingForSectionAtIndex section: NSInteger) -> CGFloat

    optional func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
        isFullWidthAtIndexPath indexPath: NSIndexPath) -> Bool
}

public class StreamCollectionViewLayout: UICollectionViewLayout {

    enum Direction {
        case ShortestFirst
        case LeftToRight
        case RightToLeft
    }

    var columnCount: Int {
        didSet { invalidateLayout() }
    }

    var minimumColumnSpacing: CGFloat {
        didSet { invalidateLayout() }
    }

    var minimumInteritemSpacing: CGFloat {
        didSet { invalidateLayout() }
    }

    var sectionInset: UIEdgeInsets {
        didSet { invalidateLayout() }
    }

    var itemRenderDirection: Direction {
        didSet { invalidateLayout() }
    }

    weak var delegate: StreamCollectionViewLayoutDelegate? {
        get {
            return collectionView!.delegate as? StreamCollectionViewLayoutDelegate
        }
    }
    var columnHeights = [CGFloat]()
    var sectionItemAttributes = [[UICollectionViewLayoutAttributes]]()
    var allItemAttributes = [UICollectionViewLayoutAttributes]()
    var unionRects = [CGRect]()
    let unionSize = 20

    override init(){
        columnCount = 2
        minimumInteritemSpacing = 0
        minimumColumnSpacing = 12
        sectionInset = UIEdgeInsetsZero
        itemRenderDirection = .ShortestFirst
        super.init()
    }

    required public init?(coder aDecoder: NSCoder) {
        columnCount = 2
        minimumInteritemSpacing = 0
        minimumColumnSpacing = 12
        sectionInset = UIEdgeInsetsZero
        itemRenderDirection = .ShortestFirst
        super.init(coder: aDecoder)
    }

    override public func prepareLayout(){
        super.prepareLayout()

        guard let numberOfSections = self.collectionView?.numberOfSections() else {
            return
        }

        unionRects.removeAll()
        columnHeights.removeAll()
        allItemAttributes.removeAll()
        sectionItemAttributes.removeAll()

        for _ in 0..<columnCount {
            self.columnHeights.append(0)
        }

        for section in 0..<numberOfSections {
            addAttributesForSection(section)
        }

        let itemCounts = allItemAttributes.count
        var index = 0
{'fraction_non_alphanumeric': 0.06605055721663496, 'fraction_numerical': 0.006523511823865181, 'mean_word_length': 3.0545454545454547, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 4, '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': '5710240', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1905, 'n_words': 449}