<commit_before>//
//  Container.swift
//  Few
//
//  Created by <NAME> on 8/27/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation
import AppKit

public class Container: Element {
	private var children: [Element]

	private var containerView: NSView?
	
	public init(_ children: [Element]) {
		self.children = children
	}
	
	// MARK: Element

	public override func applyDiff(other: Element) {
		let otherContainer = other as Container
		var newChildren = Array<Element>()
		for (myChild, theirChild) in Zip2(children, otherContainer.children) {
			if myChild.canDiff(theirChild) {
				myChild.applyDiff(theirChild)
				newChildren.append(myChild)
			} else {
				myChild.derealize()

				let component: Component<Any>? = getComponent()
				curry(theirChild.realize) <^> component <*> containerView
				newChildren.append(theirChild)
			}
		}
		
		children = newChildren
		
		super.applyDiff(other)
	}

	public override func realize<S>(component: Component<S>, parentView: NSView) {
		let view = NSView(frame: frame)
		containerView = view
		
		for element in children {
			element.realize(component, parentView: view)
		}
		
		super.realize(component, parentView: parentView)
	}

	public override func derealize() {<commit_msg>Fixed the container diffing.<commit_after>//
//  Container.swift
//  Few
//
//  Created by <NAME> on 8/27/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation
import AppKit

public class Container: Element {
	private var children: [Element]

	private var containerView: NSView?
	
	public init(_ children: [Element]) {
		self.children = children
	}
	
	// MARK: Element

	public override func applyDiff(other: Element) {
		let otherContainer = other as Container
		var newChildren = Array<Element>()
		let myChildCount = children.count
		let theirChildCount = otherContainer.children.count
		for i in 0..<max(myChildCount, theirChildCount) {
			var myChild: Element?
			if i < myChildCount {
				myChild = children[i]
			}

			var theirChild: Element?
			if i < theirChildCount {
				theirChild = otherContainer.children[i]
			}

			if myChild != nil && theirChild != nil {
				if myChild!.canDiff(theirChild!) {
					myChild!.applyDiff(theirChild!)
					newChildren.append(myChild!)
				} else {
					myChild!.derealize()

					let component: Component<Any>? = getComponent()
					curry(theirChild!.realize) <^> component <*> containerView
					newChildren.append(theirChild!)
				}
			} else if let myChild = myChild {
				myChild.derealize()
			} else if let theirChild = theirChild {
				let component: Component<Any>? = getComponent()
				curry(theirChild.realize) <^> component <*> containerView
				newChildren.append(theirChild)
			}

			children = newChildren

			super.applyDiff(other)
		}
	}

	public override func realize<S>(component: Component<S>, parentView: NSView) {
		let view = NSView(frame: frame)
		containerView = view
		
		for element in children {
			element.realize(component, parentView: view)
		}
		
		super.realize(component, parentView: parentView)
	}

	public override func derealize() {
{'fraction_non_alphanumeric': 0.11064380459398253, 'fraction_numerical': 0.006470397929472662, 'mean_word_length': 3.580740740740741, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 22, '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': '3174314', 'n_tokens_mistral': 1134, 'n_tokens_neox': 929, 'n_words': 252}