This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public extension Array { | |
func pmap<T>(transformer: @escaping (Element) -> T) -> [T] { | |
var result: [Int: [T]] = [:] | |
guard !self.isEmpty else { | |
return [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. QuickSort | |
public extension Array { | |
mutating func quickSort(_ compare: ((Element, Element) -> Bool)) { | |
for index in 0..<count { | |
var min = index | |
for subsequent in (index + 1)..<count { | |
if (!compare(self[min], self[subsequent])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List implementation using UnsafeMutablePointer. | |
final class InternalList<T> { | |
var count: Int | |
var size: Int | |
var ptr: UnsafeMutablePointer<T>? | |
init(count: Int, ptrs: UnsafeMutablePointer<T>? = nil) { | |
self.count = count | |
size = count |
NewerOlder