<commit_before>//
//  YGNodeRef.swift
//  FluentYogaKit
//
//  Created by <NAME> on 5/29/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import yoga

// MARK: - YGNodeRef -

fileprivate var YGNodeLayoutContext: [Int: YGLayoutElement] = [:]

fileprivate let YGNodeMeasureFunc: YGMeasureFunc = { (node: YGNodeRef?, width: Float, widthMode: YGMeasureMode, height: Float, heightMode: YGMeasureMode) -> YGSize in
    let constrainedWidth = (widthMode == .undefined) ? YGValueUndefined.value : width
    let constrainedHeight = (heightMode == .undefined) ? YGValueUndefined.value : height
    let constrainedSize = YGSize(width: constrainedWidth, height: constrainedHeight)
    
    guard let node = node else {
        return .zero
    }
    
    let element = node.element
    let sizeThatFits = element.sizeThatFits(constrainedSize.cgSize)
    
    let ygSize = YGSize(
        width: node.sanitizeMeasurement(constrainedWidth, sizeThatFits.width.float, widthMode),
        height: node.sanitizeMeasurement(constrainedHeight, sizeThatFits.height.float, heightMode)
    )
    
//    TODO remove this debug later
        let v = (element as! YGLayoutView).view
    
    //    if v is UILabel {
    //        let l = v as! UILabel
    //        print("\(l.text) - \(ygSize)")
    //    }
    
        print("YGMeasureFunc - \(ygSize) - \(v.className)")
    
    return ygSize
}

extension YGNodeRef {
    fileprivate static let globalConfig: YGConfigRef? = {
        let config = YGConfigNew()
        YGConfigSetExperimentalFeatureEnabled(config, .webFlexBasis, true)
        YGConfigSetPointScaleFactor(config, Float(scaleFactor))
        
        return config
    }()
    
    internal init(element: YGLayoutElement) {
        self = YGNodeNewWithConfig(YGNodeRef.globalConfig)
        self.element = element
    }

    internal var layoutTop: CGFloat {
        return YGNodeLayoutGetTop(self).cgFloat
    }
    internal var layoutLeft: CGFloat {
        return YGNodeLayoutGetLeft(self).cgFloat
    }
    internal var layoutWidth: CGFloat {
        return YGNodeLayoutGetWidth(self).cgFloat
    }
    internal var layoutHeight: CGFloat {
        return YGNodeLayoutGetHeight(self).cgFloat
    }
    
    internal var element: YGLayoutElement {
        get {
            //TODO YGNodeGetContext(self).load(as: XLayoutElement.self)
            return YGNodeLayoutContext[hashValue]!
        }
        set {
            //TODO YGNodeSetContext(self, &element)
            YGNodeLayoutContext[hashValue] = newValue
        }
    }
    
    internal func removeElement() {
        YGNodeLayoutContext.removeValue(forKey: hashValue)
    }
    
    internal func insertChild(child: YGNodeRef, at index: Int) {
        YGNodeInsertChild(self, child, UInt32(index))
    }
    
    internal func insertChildren(subelements: [YGLayoutElement]) {
        for (index, subelement) in subelements.enumerated() {
            insertChild(child: subelement.node, at: index)
        }
    }
    
    internal func getChild(at index: Int) -> YGNodeRef {
        return YGNodeGetChild(self, UInt32(index))
    }
    
    internal func childCount() -> Int {
        return Int(YGNodeGetChildCount(self))
    }
    
    internal func removeChildren() {
        var childCount = YGNodeGetChildCount(self)
        while childCount > 0 {
            YGNodeRemoveChild(self, YGNodeGetChild(self, childCount - 1))
            childCount = YGNodeGetChildCount(self)
        }
    }
    
    internal func hasExactSameChildren(subelements: [YGLayoutElement]) -> Bool {
        var result = true
        
        if childCount() != subelements.count {
            result = false
        } else {
            for (index, subelement) in subelements.enumerated() {
                if getChild(at: index) != subelement.node {
                    result = false
                    break
                }
            }
        }
        
        return result
    }
    
    internal func existMeasureFunc() -> Bool {
        return YGNodeGetMeasureFunc(self) != nil
    }
    
    internal func setMeasureFunc() {
        YGNodeSetMeasureFunc(self, YGNodeMeasureFunc)
    }
    
    internal func removeMeasureFunc() {
        YGNodeSetMeasureFunc(self, nil)
    }
    
    fileprivate func sanitizeMeasurement(_ constrainedSize: Float, _ measuredSize: Float, _ measureMode: YGMeasureMode) -> Float {
        var result: Float
        
        switch measureMode {
        case .exactly:
            result = constrainedSize
        case .atMost:
            result = min(constrainedSize, measuredSize)
        default:
            result = measuredSize
        }
        
        return result
    }
    
    internal func calculateLayout(size: YGSize, direction: YGDirection) {
        YGNodeCalculateLayout(self, size.width, size.height, direction)
    }
}
<commit_msg>Remove debug<commit_after>//
//  YGNodeRef.swift
//  FluentYogaKit
//
//  Created by <NAME> on 5/29/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import yoga

// MARK: - YGNodeRef -

fileprivate var YGNodeLayoutContext: [Int: YGLayoutElement] = [:]

fileprivate let YGNodeMeasureFunc: YGMeasureFunc = { (node: YGNodeRef?, width: Float, widthMode: YGMeasureMode, height: Float, heightMode: YGMeasureMode) -> YGSize in
    let constrainedWidth = (widthMode == .undefined) ? YGValueUndefined.value : width
    let constrainedHeight = (heightMode == .undefined) ? YGValueUndefined.value : height
    let constrainedSize = YGSize(width: constrainedWidth, height: constrainedHeight)
    
    guard let node = node else {
        return .zero
    }
    
    let element = node.element
    let sizeThatFits = element.sizeThatFits(constrainedSize.cgSize)
    
    let ygSize = YGSize(
        width: node.sanitizeMeasurement(constrainedWidth, sizeThatFits.width.float, widthMode),
        height: node.sanitizeMeasurement(constrainedHeight, sizeThatFits.height.float, heightMode)
    )
    
////    TODO remove this debug later
//        let v = (element as! YGLayoutView).view
//    
//    //    if v is UILabel {
//    //        let l = v as! UILabel
//    //        print("\(l.text) - \(ygSize)")
//    //    }
//    
//        print("YGMeasureFunc - \(ygSize) - \(v.className)")
    
    return ygSize
}

extension YGNodeRef {
    fileprivate static let globalConfig: YGConfigRef? = {
        let config = YGConfigNew()
        YGConfigSetExperimentalFeatureEnabled(config, .webFlexBasis, true)
        YGConfigSetPointScaleFactor(config, Float(scaleFactor))
        
        return config
    }()
    
    internal init(element: YGLayoutElement) {
        self = YGNodeNewWithConfig(YGNodeRef.globalConfig)
        self.element = element
    }

    internal var layoutTop: CGFloat {
        return YGNodeLayoutGetTop(self).cgFloat
    }
    internal var layoutLeft: CGFloat {
        return YGNodeLayoutGetLeft(self).cgFloat
    }
    internal var layoutWidth: CGFloat {
        return YGNodeLayoutGetWidth(self).cgFloat
    }
    internal var layoutHeight: CGFloat {
        return YGNodeLayoutGetHeight(self).cgFloat
    }
    
    internal var element: YGLayoutElement {
        get {
            //TODO YGNodeGetContext(self).load(as: XLayoutElement.self)
            return YGNodeLayoutContext[hashValue]!
        }
        set {
            //TODO YGNodeSetContext(self, &element)
            YGNodeLayoutContext[hashValue] = newValue
        }
    }
    
    internal func removeElement() {
        YGNodeLayoutContext.removeValue(forKey: hashValue)
    }
    
    internal func insertChild(child: YGNodeRef, at index: Int) {
        YGNodeInsertChild(self, child, UInt32(index))
    }
    
    internal func insertChildren(subelements: [YGLayoutElement]) {
        for (index, subelement) in subelements.enumerated() {
            insertChild(child: subelement.node, at: index)
        }
    }
    
    internal func getChild(at index: Int) -> YGNodeRef {
        return YGNodeGetChild(self, UInt32(index))
    }
    
    internal func childCount() -> Int {
        return Int(YGNodeGetChildCount(self))
    }
    
    internal func removeChildren() {
        var childCount = YGNodeGetChildCount(self)
        while childCount > 0 {
            YGNodeRemoveChild(self, YGNodeGetChild(self, childCount - 1))
            childCount = YGNodeGetChildCount(self)
        }
    }
    
    internal func hasExactSameChildren(subelements: [YGLayoutElement]) -> Bool {
        var result = true
        
        if childCount() != subelements.count {
            result = false
        } else {
            for (index, subelement) in subelements.enumerated() {
                if getChild(at: index) != subelement.node {
                    result = false
                    break
                }
            }
        }
        
        return result
    }
    
    internal func existMeasureFunc() -> Bool {
        return YGNodeGetMeasureFunc(self) != nil
    }
    
    internal func setMeasureFunc() {
        YGNodeSetMeasureFunc(self, YGNodeMeasureFunc)
    }
    
    internal func removeMeasureFunc() {
        YGNodeSetMeasureFunc(self, nil)
    }
    
    fileprivate func sanitizeMeasurement(_ constrainedSize: Float, _ measuredSize: Float, _ measureMode: YGMeasureMode) -> Float {
        var result: Float
        
        switch measureMode {
        case .exactly:
            result = constrainedSize
        case .atMost:
            result = min(constrainedSize, measuredSize)
        default:
            result = measuredSize
        }
        
        return result
    }
    
    internal func calculateLayout(size: YGSize, direction: YGDirection) {
        YGNodeCalculateLayout(self, size.width, size.height, direction)
    }
}

{'fraction_non_alphanumeric': 0.08979507774688497, 'fraction_numerical': 0.0030892801977139327, 'mean_word_length': 2.2180251822398938, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6921816', 'n_tokens_mistral': 2890, 'n_tokens_neox': 2817, 'n_words': 629}