<commit_before>import Foundation

@available(*, deprecated, renamed: "TableItem")
public typealias Item = TableItem

/// A type that represent an item to be displayed
/// defining the `drawer` and the `height`
public protocol TableItem: class, AnyEquatable {

    /// The `drawer` of the item
    static var drawer: AnyCellDrawer { get }

    /// The `height` of the item
    var height: Height? { get }
}

public extension TableItem where Self: Equatable {
    func equals(_ other: Any?) -> Bool {
        if let other = other as? Self {
            return other == self
        }
        return false
    }
}

// swiftlint:disable:next identifier_name
private var ItemTableViewManagerKey: UInt8 = 0

extension TableItem {

    public internal(set) var manager: TableViewManager? {
        get {
            return objc_getAssociatedObject(self, &ItemTableViewManagerKey) as? TableViewManager
        }
        set(newValue) {
            objc_setAssociatedObject(self,
                                     &ItemTableViewManagerKey,
                                     newValue as AnyObject,
                                     objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
        }
    }
}

extension TableItem {

    public func equals(_ other: Any?) -> Bool {
        if let other = other as AnyObject? {
            return other === self
        }
        return false
    }

    /// Dynamic height with an estimate value of 44.0
    public var height: Height? {
        return .dynamic(44.0)
    }

    /// Returns the `section` of the `item`
    ///
    /// - returns: The `section` of the `item` or `nil` if not present
    public var section: TableSection? {
        guard let indexPath = indexPath else { return nil }
        return manager?.sections[indexPath.section]
    }

    /// Returns the `indexPath` of the `item`
    ///
    /// - returns: The `indexPath` of the `item` or `nil` if not present
    public var indexPath: IndexPath? {
        guard let manager = manager else { return nil }
        for section in manager.sections {
            guard
                let sectionIndex = section.index,
                let rowIndex = section.items.index(of: self) else { continue }
            return IndexPath(row: rowIndex, section: sectionIndex)
        }
        return nil
    }

    /// Returns the `cell` of the `item`, if visibile
    public var cell: UITableViewCell? {
        guard let indexPath = indexPath else { return nil }
        return manager?.tableView.cellForRow(at: indexPath)
    }

    /// Reload the `item` with an `animation`
    ///
    /// - parameter animation: A constant that indicates how the reloading is to be animated
    public func reload(with animation: UITableViewRowAnimation = .automatic) {
        guard let indexPath = indexPath else { return }
        let section = manager?.sections[indexPath.section]
        section?.items.callback?(.updates([indexPath.row]))
    }

    /// Force redraw the `item` without reloading it
    /// The `draw` method of `CellDrawer` get called if the `cell` is visible
    public func redraw() {
        guard let cell = cell else { return }
        Self.drawer.draw(cell, self)
    }

}

public extension Collection where Self.Iterator.Element == TableItem {
    /// Return the index of the `element` inside a collection of items
    func index(of element: TableItem) -> Self.Index? {
        return index(where: { $0 === element })
    }
}
<commit_msg>Fix documentations<commit_after>import Foundation

@available(*, deprecated, renamed: "TableItem")
public typealias Item = TableItem

/// A type that represent an item to be displayed
/// defining the `drawer` and the `height`
public protocol TableItem: class, AnyEquatable {

    /// The `drawer` of the item
    static var drawer: AnyCellDrawer { get }

    /// The `height` of the item
    var height: Height? { get }
}

public extension TableItem where Self: Equatable {
    func equals(_ other: Any?) -> Bool {
        if let other = other as? Self {
            return other == self
        }
        return false
    }
}

// swiftlint:disable:next identifier_name
private var ItemTableViewManagerKey: UInt8 = 0

extension TableItem {

    public internal(set) var manager: TableViewManager? {
        get {
            return objc_getAssociatedObject(self, &ItemTableViewManagerKey) as? TableViewManager
        }
        set(newValue) {
            objc_setAssociatedObject(self,
                                     &ItemTableViewManagerKey,
                                     newValue as AnyObject,
                                     objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
        }
    }
}

extension TableItem {

    public func equals(_ other: Any?) -> Bool {
        if let other = other as AnyObject? {
            return other === self
        }
        return false
    }

    /// Dynamic height with an estimate value of 44.0
    public var height: Height? {
        return .dynamic(44.0)
    }

    /// Returns the `section` of the `item`
    ///
    /// - returns: The `section` of the `item` or `nil` if not present
    public var section: TableSection? {
        guard let indexPath = indexPath else { return nil }
        return manager?.sections[indexPath.section]
    }

    /// Returns the `indexPath` of the `item`
    ///
    /// - returns: The `indexPath` of the `item` or `nil` if not present
    public var indexPath: IndexPath? {
        guard let manager = manager else { return nil }
        for section in manager.sections {
            guard
                let sectionIndex = section.index,
                let rowIndex = section.items.index(of: self) else { continue }
            return IndexPath(row: rowIndex, section: sectionIndex)
        }
        return nil
    }

    /// Returns the `cell` of the `item`, if visibile
    public var cell: UITableViewCell? {
        guard let indexPath = indexPath else { return nil }
        return manager?.tableView.cellForRow(at: indexPath)
    }

    /// Reload the `item` with an `animation`
    ///
    /// - parameter animation: A constant that indicates how the reloading is to be animated
    public func reload(with animation: UITableViewRowAnimation = .automatic) {
        guard let indexPath = indexPath else { return }
        let section = manager?.sections[indexPath.section]
        section?.items.callback?(.updates([indexPath.row]))
    }

    /// Redraw the associated `cell` of the `item` without reloading it
    /// The `draw` method of `CellDrawer` get called if the `cell` is visible
    public func redraw() {
        guard let cell = cell else { return }
        Self.drawer.draw(cell, self)
    }

}

public extension Collection where Self.Iterator.Element == TableItem {
    /// Return the index of the `element` inside a collection of items
    func index(of element: TableItem) -> Self.Index? {
        return index(where: { $0 === element })
    }
}

{'fraction_non_alphanumeric': 0.09298296274906151, 'fraction_numerical': 0.0025989026855327752, 'mean_word_length': 2.158686730506156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985875', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1823, 'n_words': 650}