|
![](/i/fill.gif) |
> find :: (Ord y) => (x -> y) -> y -> IArray x -> (Int,Int) -> Maybe x
> find field target array (base,size)
> | size < 0 = error "invalid subrange size"
> | size == 0 = Nothing
> | size == 1 = if field (array ! base) == target then Just (array !
> base) else Nothing
> | otherwise =
> let size2 = size `div` 2
> in find field target array (base, size2) `mappend` find field target
> array (base + size2, size - size2)
I don't know Haskell, but my best guess at understanding this code looks
like you're always recursing into both sides, without actually doing the
comparison of the center element to the target element. So you're not
saving any time, and you would get faster results with a linear search.
But maybe I just don't understand the language well enough to see the
comparison.
- Slime
Post a reply to this message
|
![](/i/fill.gif) |