filter
let filterNew f (array: _[]) = | |
checkNonNull "array" array | |
let mutable i = 0 | |
while i < array.Length && not (f array.[i]) do | |
i <- i + 1 | |
if i <> array.Length then | |
let mutable element = array.[i] | |
let mutable count = 1 | |
let mutable res = Array.zeroCreateUnchecked (((array.Length-i) >>> 2) + 1) | |
res.[i] <- element | |
i <- i + 1 | |
while count < res.Length && i < array.Length do | |
element <- array.[i] | |
if f element then | |
res.[count] <- element | |
count <- count + 1 | |
i <- i + 1 | |
if i < array.Length then | |
let newRes = Array.zeroCreateUnchecked (res.Length+(array.Length-i)) | |
Array.Copy(res,newRes,res.Length) | |
res <- newRes | |
while i < array.Length do | |
element <- array.[i] | |
if f element then | |
res.[count] <- element | |
count <- count + 1 | |
i <- i + 1 | |
if res.Length <> array.Length then | |
Array.subUnchecked 0 count res | |
else | |
res | |
else empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
jackmott commentedAug 17, 2016