module Biobase.Primary.Hashed where
import Control.Exception.Base (assert)
import Data.Ix
import Data.Primitive.Types
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Vector.Unboxed as VU
import Data.PrimitiveArray
import Biobase.Primary
newtype HashedPrimary = HashedPrimary Int
deriving (Eq,Ord,Ix,Read,Show,Enum,Bounded)
deriving instance Prim HashedPrimary
deriving instance VGM.MVector VU.MVector HashedPrimary
deriving instance VG.Vector VU.Vector HashedPrimary
deriving instance VU.Unbox HashedPrimary
mkHashedPrimary :: (Nuc,Nuc) -> Primary -> HashedPrimary
mkHashedPrimary (l,u) ps' = assert (VU.all (\p -> l<=p && p<=u) ps) $ HashedPrimary idx where
idx = VU.sum $ VU.zipWith f ps (VU.enumFromStepN (VU.length ps 1) (1) (VU.length ps))
f p c = (unNuc p unNuc l) * (cnst^c)
cnst = unNuc u unNuc l + 1
ps = VU.fromList $ toList ps'