module Data.DAWG.VMap
( VMap (unVMap)
, empty
, lookup
, insert
, fromList
, toList
) where
import Prelude hiding (lookup)
import Control.Applicative ((<$>))
import Data.Binary (Binary, put, get)
import Data.Vector.Binary ()
import qualified Data.Map as M
import qualified Data.Vector.Unboxed as U
newtype VMap = VMap { unVMap :: U.Vector (Int, Int) }
deriving (Show, Eq, Ord)
instance Binary VMap where
put v = put (unVMap v)
get = VMap <$> get
empty :: VMap
empty = VMap U.empty
lookup :: Int -> VMap -> Maybe Int
lookup x = fmap snd . U.find ((==x) . fst) . unVMap
insert :: Int -> Int -> VMap -> VMap
insert x y
= VMap . U.fromList . M.toAscList
. M.insert x y
. M.fromList . U.toList . unVMap
fromList :: [(Int, Int)] -> VMap
fromList = VMap . U.fromList . M.toAscList . M.fromList
toList :: VMap -> [(Int, Int)]
toList = U.toList . unVMap