-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
Description
unordered-containers/Data/HashMap/Internal.hs
Lines 2292 to 2303 in 59ddae5
| -- | \(O(n)\) Lookup the value associated with the given key in this | |
| -- array. Returns 'Nothing' if the key wasn't found. | |
| indexOf :: Eq k => k -> A.Array (Leaf k v) -> Maybe Int | |
| indexOf k0 ary0 = go k0 ary0 0 (A.length ary0) | |
| where | |
| go !k !ary !i !n | |
| | i >= n = Nothing | |
| | otherwise = case A.index ary i of | |
| (L kx _) | |
| | k == kx -> Just i | |
| | otherwise -> go k ary (i+1) n | |
| {-# INLINABLE indexOf #-} |
It probably doesn't matter much, but it would be more efficient to return -1 when the key isn't found.