mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] Fix the public interface of partition
It should not take the predicate as inout! Swift SVN r20193
This commit is contained in:
@@ -96,12 +96,21 @@ func _insertionSort<
|
|||||||
/// [start..idx), pivot ,[idx..end)
|
/// [start..idx), pivot ,[idx..end)
|
||||||
public func partition<
|
public func partition<
|
||||||
C: MutableCollectionType where C.Index: RandomAccessIndexType
|
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,
|
inout elements: C,
|
||||||
range: Range<C.Index>,
|
range: Range<C.Index>,
|
||||||
inout less: (C.Generator.Element, C.Generator.Element)->Bool
|
inout less: (C.Generator.Element, C.Generator.Element)->Bool
|
||||||
) -> C.Index {
|
) -> C.Index {
|
||||||
|
|
||||||
_precondition(
|
_precondition(
|
||||||
range.startIndex != range.endIndex, "Can't partition an empty range")
|
range.startIndex != range.endIndex, "Can't partition an empty range")
|
||||||
|
|
||||||
@@ -165,7 +174,7 @@ func _quickSortImpl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Partition and sort.
|
// 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, range.startIndex..<part_idx, &less);
|
||||||
_quickSortImpl(&elements, (part_idx.successor())..<range.endIndex, &less);
|
_quickSortImpl(&elements, (part_idx.successor())..<range.endIndex, &less);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user