I do not use Unmanaged or UnsafePointer directly.
I have reduced the code to post here with error; - needed struct PearsonHash is on GitHub:
I get the malloc error after a add in func case4
the lines for OperationQueue
as same as in func case5
.
import Foundation
@available(macOS 10.15.4, *)
@main
public struct HashSequence {
public static func main () {
let instance = HashSequence()
instance.computeTest()
}
private func computeTest () {
let _ = collision(length: 4, hash: 0) // Laufzeit rund 5:03 Minuten
}
public func collision (length : Int, hash expected : UInt8) -> [[UInt8]] {
var result : [[UInt8]] = []
switch length {
case 4:
result = case4(hash: expected)
default : print ("NOT YET IMPLEMENTED")
}
return result
}
private func case4 (hash expected : UInt8) -> [[UInt8]] {
var result : [[UInt8]] = []
let operations2 = OperationQueue()
for b0 in 0...255 as ClosedRange<UInt8>{
let parallel = BlockOperation(block: {
for b1 in 0...255 as ClosedRange<UInt8>{
for b2 in 0...255 as ClosedRange<UInt8>{
for b3 in 0...255 as ClosedRange<UInt8>{
let data = [b0,b1,b2,b3]
if let _ = PearsonHash.isHash(input: data, expectedHash: expected) {
result.append(data)
}
}
}
}
})
operations2.addOperation(parallel)
}
operations2.waitUntilAllOperationsAreFinished()
return result
}
private func case5 (hash expected : UInt8) -> [[UInt8]]{
var result : [[UInt8]] = []
let operations = OperationQueue()
for b0 in 0...255 as ClosedRange<UInt8>{
let parallel = BlockOperation(block: {
for b1 in 0...255 as ClosedRange<UInt8>{
for b2 in 0...255 as ClosedRange<UInt8>{
for b3 in 0...255 as ClosedRange<UInt8>{
for b4 in 0...255 as ClosedRange<UInt8>{
let data = [b0,b1,b2,b3,b4]
if let _ = PearsonHash.isHash(input: data, expectedHash: expected) {
//result.append(data)
}
}
}
}
}
})
operations.addOperation(parallel)
}
operations.waitUntilAllOperationsAreFinished()
return result
}
}