Ignore-this: f58ceb5e1068be132b0a67a851b096f4 This has two advantages: 1. TemplateHaskell is painfully slow. There, I said it. 2. TemplateHaskell doesn't yet support some extensions that can be usefull for this library. Specifically the MagicHash extension. darcs-hash:20090813023321-a4fee-0da13d0da6454f6ba3bd111ed6b80268d9e1b45c
28 lines
957 B
Haskell
28 lines
957 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 |