partition

func partition<C : MutableCollectionType where C.Index : RandomAccessIndexType, C.Generator.Element : Comparable>(inout: C, range: Range<C.Index>)

Re-order the given range of elements and return a pivot index p.

Postcondition: for all i in range.startIndex..<p, and j in p..<range.endIndex, less(elements[i], elements[j]) && !less(elements[j], elements[p]). Only returns range.endIndex when elements is empty. Requires: The less-than operator (func <) defined in the Comparable conformance is a strict weak ordering over elements.

Declaration

func partition<C : MutableCollectionType where C.Index : RandomAccessIndexType, C.Generator.Element : Comparable>(inout elements: C, range: Range<C.Index>) -> C.Index
func partition<C : MutableCollectionType where C.Index : RandomAccessIndexType>(inout: C, range: Range<C.Index>, isOrderedBefore: (C.Generator.Element, C.Generator.Element) -> Bool)

Re-order the given range of elements and return a pivot index p.

Postcondition: for all i in range.startIndex..<p, and j in p..<range.endIndex, less(elements[i], elements[j]) && !less(elements[j], elements[p]). Only returns range.endIndex when elements is empty. Requires: isOrderedBefore is a strict weak ordering over elements.

Declaration

func partition<C : MutableCollectionType where C.Index : RandomAccessIndexType>(inout elements: C, range: Range<C.Index>, isOrderedBefore: (C.Generator.Element, C.Generator.Element) -> Bool) -> C.Index