Re: qsort_b in Swift
Quincey Morris
On Sep 15, 2017, at 21:18 , Gerriet M. Denkmann <g@...> wrote:
Yikes, this is masochistic! This is the prototype: public func qsort_b(_ __base: UnsafeMutableRawPointer!, _ __nel: Int, _ __width: Int, _ __compar: @escaping (UnsafeRawPointer?, UnsafeRawPointer?) -> Int32) So I think the code looks like this (syntax-checked in Xcode 9 but not tested): var sortedArray = [UInt32]() return a > b ? 1 : a < b ? -1 : 0 The “&sortedArray” relies on the compiler auto-bridging to the UnsafeMutableRawPointer. I don’t know if there’s an easier way to get the UInt32 values from the closure parameters, but perhaps “load” is the right way. Also, I may have the comparison test in the return backwards. |
|