<commit_before>///**
/**
 * EasyTables
 * Created by: <NAME> on 1/9/17
 *
 * License: MIT
 */

import Foundation

public class EasyTable {
    
    /**
     This is needed to do updates to the view after rendering
     */
    var tableView: UITableView?
    
    public var sections: [TableSection] = []
    
    public var count: Int {
        get {
            return sections.count
        }
    }
    
    public var isEmpty: Bool {
        get {
            return count == 0
        }
    }
    
    public init() {
        
    }
    
    public init(tableView: UITableView) {
        self.tableView = tableView
    }
    
    
    
    public func section(at: Int) -> TableSection {
        return get(at: at)
    }
    
    public func at(index: Int) -> TableSection {
        return get(at: index)
    }
    
    public func get(at: Int) -> TableSection {
        return sections[at]
    }
    
    public func all() -> [TableSection] {
        return sections
    }
    
    public func add(section: TableSection) {
        sections.append(section)
    }
    
    public func add(section: TableSection, at: Int) {
        sections.insert(section, at: at)
    }
    
    public func remove(at: Int) {
        sections.remove(at: at)
    }
    
    public func remove(section: TableSection) {
        if let index = sections.index(of: section) {
            sections.remove(at: index)
        }
    }
    
    public func row(at: IndexPath) -> TableCellInfo {
        return self.at(index: at.section).row(at: at.row)
    }
    
    public func row(row: Int, section: Int) -> TableCellInfo {
        return self.row(at: IndexPath(row: row, section: section))
    }
    
    public func delete(section: Int) {
        sections.remove(at: section)
    }
    
    public func delete(row: IndexPath) {
        sections[row.section].rows.remove(at: row.row)
    }
    
    /**
     Add rows in the view, inserted with animation
     */
    public func addRowsBelow(indexPath: IndexPath, data: [TableCellInfo]) {
        guard let table = tableView else { return }
        let section = at(index: indexPath.section)
        section.rows.insert(contentsOf: data, at: indexPath.row+1)
        var newRows: [IndexPath] = []
        var newCount = 1
        for _ in data {
            newRows.append(IndexPath(row: indexPath.row+newCount, section: indexPath.section))
            newCount = newCount+1
        }
        table.beginUpdates()
        table.insertRows(at: newRows, with: .fade)
        table.endUpdates()
    }
    
    /**
     Remove rows in the view with animation, counterpart to addRowsBelow
     */
    public func removeRowsBelow(indexPath: IndexPath, numberOfRows: Int) {
        guard let table = tableView else { return }
        var delRows: [IndexPath] = []
        let section = at(index: indexPath.section)
        for i in 1...numberOfRows {
            section.rows.remove(at: indexPath.row+1)
            delRows.append(IndexPath(row: indexPath.row+i, section: indexPath.section))<commit_msg>clearAll added<commit_after>///**
/**
 * EasyTables
 * Created by: <NAME> on 1/9/17
 *
 * License: MIT
 */

import Foundation

public class EasyTable {
    
    /**
     This is needed to do updates to the view after rendering
     */
    var tableView: UITableView?
    
    public var sections: [TableSection] = []
    
    public var count: Int {
        get {
            return sections.count
        }
    }
    
    public var isEmpty: Bool {
        get {
            return count == 0
        }
    }
    
    public init() {
        
    }
    
    public init(tableView: UITableView) {
        self.tableView = tableView
    }
    
    public func section(at: Int) -> TableSection {
        return get(at: at)
    }
    
    public func at(index: Int) -> TableSection {
        return get(at: index)
    }
    
    public func get(at: Int) -> TableSection {
        return sections[at]
    }
    
    public func all() -> [TableSection] {
        return sections
    }
    
    public func add(section: TableSection) {
        sections.append(section)
    }
    
    public func add(section: TableSection, at: Int) {
        sections.insert(section, at: at)
    }
    
    public func remove(at: Int) {
        sections.remove(at: at)
    }
    
    public func remove(section: TableSection) {
        if let index = sections.index(of: section) {
            sections.remove(at: index)
        }
    }
    
    public func row(at: IndexPath) -> TableCellInfo {
        return self.at(index: at.section).row(at: at.row)
    }
    
    public func row(row: Int, section: Int) -> TableCellInfo {
        return self.row(at: IndexPath(row: row, section: section))
    }
    
    public func delete(section: Int) {
        sections.remove(at: section)
    }
    
    public func delete(row: IndexPath) {
        sections[row.section].rows.remove(at: row.row)
    }
    
    public func clearAll() {
        sections = []
    }
    
    /**
     Add rows in the view, inserted with animation
     */
    public func addRowsBelow(indexPath: IndexPath, data: [TableCellInfo]) {
        guard let table = tableView else { return }
        let section = at(index: indexPath.section)
        section.rows.insert(contentsOf: data, at: indexPath.row+1)
        var newRows: [IndexPath] = []
        var newCount = 1
        for _ in data {
            newRows.append(IndexPath(row: indexPath.row+newCount, section: indexPath.section))
            newCount = newCount+1
        }
        table.beginUpdates()
        table.insertRows(at: newRows, with: .fade)
        table.endUpdates()
    }
    
    /**
     Remove rows in the view with animation, counterpart to addRowsBelow
     */
    public func removeRowsBelow(indexPath: IndexPath, numberOfRows: Int) {
        guard let table = tableView else { return }
        var delRows: [IndexPath] = []
        let section = at(index: indexPath.section)
        for i in 1...numberOfRows {
            section.rows.remove(at: indexPath.row+1)
            delRows.append(IndexPath(row: indexPath.row+i, section: indexPath.section))
{'fraction_non_alphanumeric': 0.10477127397934087, 'fraction_numerical': 0.003279226102639777, 'mean_word_length': 1.928468554968795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '783183', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1806, 'n_words': 476}