<commit_before>//  Copyright (c) 2015 <NAME>. All rights reserved.

public struct DisjointSet<T>: ArrayLiteralConvertible, ExtensibleCollectionType {
	public init<S: SequenceType where S.Generator.Element == T>(_ sequence: S) {
		sets = map(enumerate(sequence)) { (parent: $0, rank: 0, value: $1) }
	}


	/// The number of elements in the set.
	///
	/// This is distinct from the number of partitions in the set.
	public var count: Int {
		return sets.count
	}


	public mutating func findAllInPlace() -> Set<Int> {
		return Set(lazy(sets)
			.map { $0.0 }
			.map(findInPlace))
	}


	public mutating func unionInPlace(a: Int, _ b: Int) {
		let (r1, r2) = (findInPlace(a), findInPlace(b))
		let (n1, n2) = (sets[r1], sets[r2])
		if r1 != r2 {
			if n1.rank < n2.rank {
				sets[r1].parent = r2
			} else {
				sets[r2].parent = r1
				if n1.rank == n2.rank {
					++sets[r1].rank
				}
			}
		}
	}

	public mutating func findInPlace(a: Int) -> Int {
		let n = sets[a]
		if n.parent == a {
			return a
		} else {
			let parent = findInPlace(n.parent)
			sets[a].parent = parent
			return parent
		}
	}


	// MARK: ArrayLiteralConvertible

	public init(arrayLiteral elements: T...) {
		self.init(elements)
	}


	// MARK: CollectionType

	public let startIndex = 0

	public var endIndex: Int {
		return count
	}

	public subscript (index: Int) -> T {
		return sets[index].value
	}<commit_msg>Arrange the find methods in place.<commit_after>//  Copyright (c) 2015 <NAME>. All rights reserved.

public struct DisjointSet<T>: ArrayLiteralConvertible, ExtensibleCollectionType {
	public init<S: SequenceType where S.Generator.Element == T>(_ sequence: S) {
		sets = map(enumerate(sequence)) { (parent: $0, rank: 0, value: $1) }
	}


	/// The number of elements in the set.
	///
	/// This is distinct from the number of partitions in the set.
	public var count: Int {
		return sets.count
	}


	public mutating func unionInPlace(a: Int, _ b: Int) {
		let (r1, r2) = (findInPlace(a), findInPlace(b))
		let (n1, n2) = (sets[r1], sets[r2])
		if r1 != r2 {
			if n1.rank < n2.rank {
				sets[r1].parent = r2
			} else {
				sets[r2].parent = r1
				if n1.rank == n2.rank {
					++sets[r1].rank
				}
			}
		}
	}


	public mutating func findInPlace(a: Int) -> Int {
		let n = sets[a]
		if n.parent == a {
			return a
		} else {
			let parent = findInPlace(n.parent)
			sets[a].parent = parent
			return parent
		}
	}

	public mutating func findAllInPlace() -> Set<Int> {
		return Set(lazy(sets)
			.map { $0.0 }
			.map(findInPlace))
	}


	// MARK: ArrayLiteralConvertible

	public init(arrayLiteral elements: T...) {
		self.init(elements)
	}


	// MARK: CollectionType

	public let startIndex = 0

	public var endIndex: Int {
		return count
	}

	public subscript (index: Int) -> T {
		return sets[index].value
	}
{'fraction_non_alphanumeric': 0.13897820650232226, 'fraction_numerical': 0.01929260450160772, 'mean_word_length': 2.8942976356050067, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '639474', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1013, 'n_words': 291}