<commit_before>//
//  Created by <NAME> on 02.05.17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

final class NodesSequenceDisplayAdapter<Index: Hashable> {
    
    private let itemNode: (Index, Bool)-> RootNode
    
    private var cache = [Index: RootNode]()
    
    
    init(itemNode: @escaping (Index, Bool)-> RootNode) {
        self.itemNode = itemNode
    }
    
    func estimatedSize(for index: Index, size: CGSize) -> CGSize {
        if size.width < 1 && size.height < 1 {
            return CGSize()
        }
        
        let node = itemNode(index, true)
        node.layout(for: size)
        return node.frame.size
    }
    
    func size(for index: Index, size: CGSize) -> CGSize {
        let node = itemNode(index, false)
        
        
        let didLayoutForWidth = (size.width > 0 && isAlmostEqual(left:  node.frame.width, right: size.width)) || isAlmostEqual(left: size.width, right: 0)
        let didLayoutForHeight = (size.height > 0 && isAlmostEqual(left:  node.frame.height, right: size.height)) || isAlmostEqual(left: size.height, right: 0)
        
        if !(didLayoutForWidth && didLayoutForHeight) {
            node.layout(for: size)
        }
        
        cache[index] = node
        return node.frame.size
    }
    
    func willDisplay(view: UIView, for index: Index) {
        if let v = view as? NodeItemView {
            v.rootNode = cache[index]
            cache[index] = nil
        }
    }<commit_msg>display adaptor fix<commit_after>//
//  Created by <NAME> on 02.05.17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

final class NodesSequenceDisplayAdapter<Index: Hashable> {
    
    private let itemNode: (Index, Bool)-> RootNode
    
    private var cache = [Index: RootNode]()
    
    
    init(itemNode: @escaping (Index, Bool)-> RootNode) {
        self.itemNode = itemNode
    }
    
    func estimatedSize(for index: Index, size: CGSize) -> CGSize {
        if size.width < 1 && size.height < 1 {
            return CGSize()
        }
        
        let node = itemNode(index, true)
        node.layout(for: size)
        return node.frame.size
    }
    
    func size(for index: Index, size: CGSize) -> CGSize {
        let node = itemNode(index, false)
        
        
        let didLayoutForWidth = (size.width > 0 && isAlmostEqual(left:  node.frame.width, right: size.width)) || isAlmostEqual(left: size.width, right: 0)
        let didLayoutForHeight = (size.height > 0 && isAlmostEqual(left:  node.frame.height, right: size.height)) || isAlmostEqual(left: size.height, right: 0)
        
        if !(didLayoutForWidth && didLayoutForHeight) {
            node.layout(for: size)
        }
        
        cache[index] = node
        return node.frame.size
    }
    
    func willDisplay(view: UIView, for index: Index) {
        if let v = view as? NodeItemView {
            v.rootNode = cache[index]
        }
    }
{'fraction_non_alphanumeric': 0.11524163568773234, 'fraction_numerical': 0.010814464346062858, 'mean_word_length': 2.0641821946169774, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3823654', 'n_tokens_mistral': 946, 'n_tokens_neox': 894, 'n_words': 238}