File: Static.hs

package info (click to toggle)
haskell-encoding 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,392 kB
  • sloc: haskell: 4,372; ansic: 11; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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