func search()

in Sources/TSCBasic/DeltaAlgorithm.swift [97:125]


    func search(
        changes: Set<Change>,
        changeSets: [Set<Change>],
        predicate: (Set<Change>) throws -> Bool
    ) rethrows -> Set<Change>? {
        for (idx, currentSet) in changeSets.enumerated() {
            // If the test passes on this subset alone, recurse.
            if try predicate(currentSet) {
                return try delta(
                    changes: currentSet, changeSets: split(currentSet), predicate: predicate)
            }

            // Otherwise, if we have more than two sets, see if test passes on the complement.
            if changeSets.count > 2 {
                let compliment = changes.subtracting(currentSet)
                if try predicate(compliment) {
                    var complimentSets = [Set<Change>]()
                    let idxIndex = changeSets.index(changeSets.startIndex, offsetBy: idx)
                    complimentSets += changeSets[changeSets.startIndex..<idxIndex]
                    complimentSets += changeSets[changeSets.index(after: idxIndex)..<changeSets.endIndex]
                    return try delta(
                        changes: compliment,
                        changeSets: complimentSets,
                        predicate: predicate)
                }
            }
        }
        return nil
    }