encoding/Data/Map/Static.hs
Daniel Wagner 3f8c3bbb26 whitespace: eol marker at end of all files
Ignore-this: 3b03abece3edb25c656f84db9cef7734

darcs-hash:20121017171258-76d51-76a4e9057c0a4c3c1370485f3dc072c18caafddf
2012-10-17 10:12:58 -07:00

29 lines
958 B
Haskell

module Data.Map.Static where
import Data.Static
import Data.Array.Static
import GHC.Exts
data StaticMap i e = StaticMap (StaticArray Int i) (StaticArray Int e)
lookup :: (StaticElement i,StaticElement e,Ord i) => i -> StaticMap i e -> Maybe e
lookup ind (StaticMap idx els) = lookup' 1
where
lookup' n = if n > snd (bounds idx)
then Nothing
else case compare ind (idx!n) of
LT -> lookup' (n * 2)
GT -> lookup' ((n * 2) + 1)
EQ -> Just $ els!n
member :: (StaticElement i,StaticElement e,Ord i) => i -> StaticMap i e -> Bool
member ind (StaticMap idx _) = lookup' 1
where
lookup' n = if n > snd (bounds idx)
then False
else case compare ind (idx!n) of
LT -> lookup' (n * 2)
GT -> lookup' ((n * 2) + 1)
EQ -> True