[stdlib] Fix the public interface of partition

It should not take the predicate as inout!

Swift SVN r20193
This commit is contained in:
Dave Abrahams
2014-07-19 00:35:45 +00:00
parent 94d317cbda
commit ec8b29cdf1

View File

@@ -96,12 +96,21 @@ func _insertionSort<
/// [start..idx), pivot ,[idx..end)
public func partition<
C: MutableCollectionType where C.Index: RandomAccessIndexType
>(
inout elements: C,
range: Range<C.Index>,
var less: (C.Generator.Element, C.Generator.Element)->Bool
) -> C.Index {
return _partition(&elements, range, &less)
}
public func _partition<
C: MutableCollectionType where C.Index: RandomAccessIndexType
>(
inout elements: C,
range: Range<C.Index>,
inout less: (C.Generator.Element, C.Generator.Element)->Bool
) -> C.Index {
_precondition(
range.startIndex != range.endIndex, "Can't partition an empty range")
@@ -165,7 +174,7 @@ func _quickSortImpl<
}
// Partition and sort.
let part_idx : C.Index = partition(&elements, range, &less)
let part_idx : C.Index = _partition(&elements, range, &less)
_quickSortImpl(&elements, range.startIndex..<part_idx, &less);
_quickSortImpl(&elements, (part_idx.successor())..<range.endIndex, &less);
}