    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 :: forall i e.
    (StaticElement i, StaticElement e, Ord i) =>
    i -> StaticMap i e -> Maybe e
    lookup i
    ind (StaticMap StaticArray Int i
    idx StaticArray Int e
    els) = Int -> Maybe e
    lookup' Int
    1
        where
          lookup' :: Int -> Maybe e
    lookup' Int
    n = if Int
    n Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > (Int, Int) -> Int
    forall a b. (a, b) -> b
    snd (StaticArray Int i -> (Int, Int)
    forall i e. Ix i => StaticArray i e -> (i, i)
    bounds StaticArray Int i
    idx)
                      then Maybe e
    forall a. Maybe a
    Nothing
                      else case i -> i -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare i
    ind (StaticArray Int i
    idxStaticArray Int i -> Int -> i
    forall e i. (StaticElement e, Ix i) => StaticArray i e -> i -> e
    !Int
    n) of
                             Ordering
    LT -> Int -> Maybe e
    lookup' (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    2)
                             Ordering
    GT -> Int -> Maybe e
    lookup' ((Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    2) Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1)
                             Ordering
    EQ -> e -> Maybe e
    forall a. a -> Maybe a
    Just (e -> Maybe e) -> e -> Maybe e
    forall a b. (a -> b) -> a -> b
    $ StaticArray Int e
    elsStaticArray Int e -> Int -> e
    forall e i. (StaticElement e, Ix i) => StaticArray i e -> i -> e
    !Int
    n

    member :: (StaticElement i,StaticElement e,Ord i) => i -> StaticMap i e -> Bool
    member :: forall i e.
    (StaticElement i, StaticElement e, Ord i) =>
    i -> StaticMap i e -> Bool
    member i
    ind (StaticMap StaticArray Int i
    idx StaticArray Int e
    _) = Int -> Bool
    lookup' Int
    1
        where
          lookup' :: Int -> Bool
    lookup' Int
    n = if Int
    n Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > (Int, Int) -> Int
    forall a b. (a, b) -> b
    snd (StaticArray Int i -> (Int, Int)
    forall i e. Ix i => StaticArray i e -> (i, i)
    bounds StaticArray Int i
    idx)
                      then Bool
    False
                      else case i -> i -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare i
    ind (StaticArray Int i
    idxStaticArray Int i -> Int -> i
    forall e i. (StaticElement e, Ix i) => StaticArray i e -> i -> e
    !Int
    n) of
                             Ordering
    LT -> Int -> Bool
    lookup' (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    2)
                             Ordering
    GT -> Int -> Bool
    lookup' ((Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    2) Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1)
                             Ordering
    EQ -> Bool
    True