<commit_before>import UIKit

extension UIView {
    func anchor() -> Anchor { return Anchor(view: self) }
    
    var top: NSLayoutAnchor { return topAnchor }
    var left: NSLayoutAnchor { return leftAnchor }
    var bottom: NSLayoutAnchor { return bottomAnchor }
    var right: NSLayoutAnchor { return rightAnchor }
    var height: NSLayoutDimension { return heightAnchor }
    var width: NSLayoutDimension { return widthAnchor }
    var centerX: NSLayoutXAxisAnchor { return centerXAnchor }
    var centerY: NSLayoutYAxisAnchor { return centerYAnchor }
}

struct Anchor {
    let view: UIView
    let top: NSLayoutConstraint?
    let left: NSLayoutConstraint?
    let bottom: NSLayoutConstraint?
    let right: NSLayoutConstraint?
    let height: NSLayoutConstraint?
    let width: NSLayoutConstraint?
    let centerX: NSLayoutConstraint?
    let centerY: NSLayoutConstraint?
    
    private enum Edge {
        case Top
        case Left
        case Bottom
        case Right
        case Height
        case Width
        case CenterX
        case CenterY
    }
    
    init(view: UIView) {
        self.view = view
        top = nil
        left = nil
        bottom = nil
        right = nil
        height = nil
        width = nil
        centerX = nil
        centerY = nil
    }
    
    init(view: UIView,
         top: NSLayoutConstraint?,
         left: NSLayoutConstraint?,
         bottom: NSLayoutConstraint?,
         right: NSLayoutConstraint?,
         height: NSLayoutConstraint?,
         width: NSLayoutConstraint?,
         centerX: NSLayoutConstraint?,
         centerY: NSLayoutConstraint?)
    {
        self.view = view
        self.top = top
        self.left = left
        self.bottom = bottom
        self.right = right
        self.height = height
        self.width = width
        self.centerX = centerX
        self.centerY = centerY
    }
    
    private func update(edge edge: Edge, constraint: NSLayoutConstraint) -> Anchor {
        var top = self.top
        var left = self.left
        var bottom = self.bottom
        var right = self.right
        var height = self.height
        var width = self.width
        var centerX = self.centerX
        var centerY = self.centerY
        
        switch edge {
        case .Top: top = constraint
        case .Left: left = constraint
        case .Bottom: bottom = constraint
        case .Right: right = constraint
        case .Height: height = constraint
        case .Width: width = constraint
        case .CenterX: centerX = constraint
        case .CenterY: centerY = constraint
        }
        
        return Anchor(
            view: self.view,
            top: top,
            left: left,
            bottom: bottom,
            right: right,
            height: height,
            width: width,
            centerX: centerX,
            centerY: centerY)
    }
    
    func top(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Top, constraint: view.topAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func left(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Left, constraint: view.leftAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func bottom(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Bottom, constraint: view.bottomAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func right(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Right, constraint: view.rightAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func height(constant c: CGFloat) -> Anchor {
        return update(edge: .Height, constraint: view.heightAnchor.constraintEqualToConstant(c))
    }
    
    func height(to dimension: NSLayoutDimension, multiplier m: CGFloat = 1) -> Anchor {
        return update(edge: .Height, constraint: view.heightAnchor.constraintEqualToAnchor(dimension, multiplier: m))
    }
    
    func width(constant c: CGFloat) -> Anchor {
        return update(edge: .Width, constraint: view.widthAnchor.constraintEqualToConstant(c))
    }
    
    func width(to dimension: NSLayoutDimension, multiplier m: CGFloat = 1) -> Anchor {
        return update(edge: .Width, constraint: view.widthAnchor.constraintEqualToAnchor(dimension, multiplier: m))
    }
    
    func centerX(to axis: NSLayoutXAxisAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .CenterX, constraint: view.centerXAnchor.constraintEqualToAnchor(axis, constant: c))
    }
    
    func centerY(to axis: NSLayoutYAxisAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .CenterY, constraint: view.centerYAnchor.constraintEqualToAnchor(axis, constant: c))
    }
    
    func activate() -> Anchor {
        view.translatesAutoresizingMaskIntoConstraints = false
        let constraints = [top, left, bottom, right, height, width, centerX, centerY].flatMap({ $0 })
        NSLayoutConstraint.activateConstraints(constraints)
        return self
    }
}<commit_msg>Add superview equal to anchors<commit_after>import UIKit

extension UIView {
    func anchor() -> Anchor { return Anchor(view: self) }
    
    var top: NSLayoutAnchor { return topAnchor }
    var left: NSLayoutAnchor { return leftAnchor }
    var bottom: NSLayoutAnchor { return bottomAnchor }
    var right: NSLayoutAnchor { return rightAnchor }
    var height: NSLayoutDimension { return heightAnchor }
    var width: NSLayoutDimension { return widthAnchor }
    var centerX: NSLayoutXAxisAnchor { return centerXAnchor }
    var centerY: NSLayoutYAxisAnchor { return centerYAnchor }
}

struct Anchor {
    let view: UIView
    let top: NSLayoutConstraint?
    let left: NSLayoutConstraint?
    let bottom: NSLayoutConstraint?
    let right: NSLayoutConstraint?
    let height: NSLayoutConstraint?
    let width: NSLayoutConstraint?
    let centerX: NSLayoutConstraint?
    let centerY: NSLayoutConstraint?
    
    private enum Edge {
        case Top
        case Left
        case Bottom
        case Right
        case Height
        case Width
        case CenterX
        case CenterY
    }
    
    init(view: UIView) {
        self.view = view
        top = nil
        left = nil
        bottom = nil
        right = nil
        height = nil
        width = nil
        centerX = nil
        centerY = nil
    }
    
    init(view: UIView,
         top: NSLayoutConstraint?,
         left: NSLayoutConstraint?,
         bottom: NSLayoutConstraint?,
         right: NSLayoutConstraint?,
         height: NSLayoutConstraint?,
         width: NSLayoutConstraint?,
         centerX: NSLayoutConstraint?,
         centerY: NSLayoutConstraint?)
    {
        self.view = view
        self.top = top
        self.left = left
        self.bottom = bottom
        self.right = right
        self.height = height
        self.width = width
        self.centerX = centerX
        self.centerY = centerY
    }
    
    private func update(edge edge: Edge, constraint: NSLayoutConstraint) -> Anchor {
        var top = self.top
        var left = self.left
        var bottom = self.bottom
        var right = self.right
        var height = self.height
        var width = self.width
        var centerX = self.centerX
        var centerY = self.centerY
        
        switch edge {
        case .Top: top = constraint
        case .Left: left = constraint
        case .Bottom: bottom = constraint
        case .Right: right = constraint
        case .Height: height = constraint
        case .Width: width = constraint
        case .CenterX: centerX = constraint
        case .CenterY: centerY = constraint
        }
        
        return Anchor(
            view: self.view,
            top: top,
            left: left,
            bottom: bottom,
            right: right,
            height: height,
            width: width,
            centerX: centerX,
            centerY: centerY)
    }
    
    // MARK: Anchor to superview edges
    func topToSuperview(constant c: CGFloat = 0) -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return top(to: superview.top, constant: c)
    }
    
    func leftToSuperview(constant c: CGFloat = 0) -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return left(to: superview.left, constant: c)
    }
    
    func bottomToSuperview(constant c: CGFloat = 0) -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return bottom(to: superview.bottom, constant: c)
    }
    
    func rightToSuperview(constant c: CGFloat = 0) -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return right(to: superview.right, constant: c)
    }
    
    // MARK: Anchor to superview axises
    func centerXToSuperview() -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return centerX(to: superview.centerX)
    }
    
    func centerYToSuperview() -> Anchor {
        guard let superview = view.superview else {
            return self
        }
        return centerY(to: superview.centerY)
    }
    
    // MARK: Anchor to edges
    func top(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Top, constraint: view.topAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func left(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Left, constraint: view.leftAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func bottom(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Bottom, constraint: view.bottomAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    func right(to edge: NSLayoutAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .Right, constraint: view.rightAnchor.constraintEqualToAnchor(edge, constant: c))
    }
    
    // MARK: Anchor to dimensions
    func height(constant c: CGFloat) -> Anchor {
        return update(edge: .Height, constraint: view.heightAnchor.constraintEqualToConstant(c))
    }
    
    func height(to dimension: NSLayoutDimension, multiplier m: CGFloat = 1) -> Anchor {
        return update(edge: .Height, constraint: view.heightAnchor.constraintEqualToAnchor(dimension, multiplier: m))
    }
    
    func width(constant c: CGFloat) -> Anchor {
        return update(edge: .Width, constraint: view.widthAnchor.constraintEqualToConstant(c))
    }
    
    func width(to dimension: NSLayoutDimension, multiplier m: CGFloat = 1) -> Anchor {
        return update(edge: .Width, constraint: view.widthAnchor.constraintEqualToAnchor(dimension, multiplier: m))
    }
    
    // MAKR: Anchor to axises
    func centerX(to axis: NSLayoutXAxisAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .CenterX, constraint: view.centerXAnchor.constraintEqualToAnchor(axis, constant: c))
    }
    
    func centerY(to axis: NSLayoutYAxisAnchor, constant c: CGFloat = 0) -> Anchor {
        return update(edge: .CenterY, constraint: view.centerYAnchor.constraintEqualToAnchor(axis, constant: c))
    }
    
    func activate() -> Anchor {
        view.translatesAutoresizingMaskIntoConstraints = false
        let constraints = [top, left, bottom, right, height, width, centerX, centerY].flatMap({ $0 })
        NSLayoutConstraint.activateConstraints(constraints)
        return self
    }
}
{'fraction_non_alphanumeric': 0.08359824727210241, 'fraction_numerical': 0.0018901967522983074, 'mean_word_length': 2.2423398328690807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '4509951', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3186, 'n_words': 938}