packages feed

text-compression 0.1.0.14 → 0.1.0.15

raw patch · 4 files changed

+687/−284 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.FMIndex.Internal: emptySTFMIndexCounterB :: ST s (STFMIndexCounterB s Int)
- Data.FMIndex.Internal: emptySTFMIndexCounterT :: ST s (STFMIndexCounterT s Int)
- Data.FMIndex.Internal: emptySTFMIndexILB :: ST s (STFMIndexILB s a)
- Data.FMIndex.Internal: emptySTFMIndexILT :: ST s (STFMIndexILT s a)
- Data.FMIndex.Internal: emptySTFMIndexSeqB :: ST s (STFMIndexSeqB s a)
- Data.FMIndex.Internal: emptySTFMIndexSeqT :: ST s (STFMIndexSeqT s a)
- Data.FMIndex.Internal: loadSTFMIndexILB :: STMTFILB s (Maybe ByteString) -> Seq (Maybe ByteString) -> ST s ()
- Data.FMIndex.Internal: loadSTFMIndexILT :: STMTFILT s (Maybe Text) -> Seq (Maybe Text) -> ST s ()
- Data.FMIndex.Internal: seqToFMIndexB :: PBFMIndexSeqB -> ST s FMIndexSeqB
- Data.FMIndex.Internal: seqToFMIndexT :: PTFMIndexSeqT -> ST s FMIndexSeqT
- Data.FMIndex.Internal: type FMIndexSeqB = Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))
- Data.FMIndex.Internal: type FMIndexSeqT = Seq (Maybe Text, Seq (Int, Int, Maybe Text))
- Data.FMIndex.Internal: type PBFMIndexSeqB = Seq (Maybe ByteString)
- Data.FMIndex.Internal: type PTFMIndexSeqT = Seq (Maybe Text)
- Data.FMIndex.Internal: type STFMIndexCounterB s a = STRef s Int
- Data.FMIndex.Internal: type STFMIndexCounterT s a = STRef s Int
- Data.FMIndex.Internal: type STFMIndexILB s a = STRef s (Seq (Maybe ByteString))
- Data.FMIndex.Internal: type STFMIndexILT s a = STRef s (Seq (Maybe Text))
- Data.FMIndex.Internal: type STFMIndexSeqB s a = STRef s FMIndexSeqB
- Data.FMIndex.Internal: type STFMIndexSeqT s a = STRef s FMIndexSeqT
- Data.FMIndex.Internal: updateSTFMIndexCounterB :: STFMIndexCounterB s Int -> Int -> ST s ()
- Data.FMIndex.Internal: updateSTFMIndexCounterT :: STFMIndexCounterT s Int -> Int -> ST s ()
- Data.FMIndex.Internal: updateSTFMIndexSeqAB :: STFMIndexSeqB s (Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))) -> (Int, Int, Maybe ByteString) -> ST s ()
- Data.FMIndex.Internal: updateSTFMIndexSeqAT :: STFMIndexSeqT s (Seq (Maybe Text, Seq (Int, Int, Maybe Text))) -> (Int, Int, Maybe Text) -> ST s ()
- Data.FMIndex.Internal: updateSTFMIndexSeqBB :: STFMIndexSeqB s (Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))) -> Maybe ByteString -> ST s ()
- Data.FMIndex.Internal: updateSTFMIndexSeqBT :: STFMIndexSeqT s (Seq (Maybe Text, Seq (Int, Int, Maybe Text))) -> Maybe Text -> ST s ()
+ Data.FMIndex.Internal: CcB :: Seq (Int, Maybe ByteString) -> CcB
+ Data.FMIndex.Internal: CcT :: Seq (Int, Maybe Text) -> CcT
+ Data.FMIndex.Internal: OccCKB :: Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString)) -> OccCKB
+ Data.FMIndex.Internal: OccCKT :: Seq (Maybe Text, Seq (Int, Int, Maybe Text)) -> OccCKT
+ Data.FMIndex.Internal: emptySTCcCounterB :: ST s (STCcCounterB s Int)
+ Data.FMIndex.Internal: emptySTCcCounterT :: ST s (STCcCounterT s Int)
+ Data.FMIndex.Internal: emptySTCcILB :: ST s (STCcILB s a)
+ Data.FMIndex.Internal: emptySTCcILT :: ST s (STCcILT s a)
+ Data.FMIndex.Internal: emptySTCcSeqB :: ST s (STCcSeqB s a)
+ Data.FMIndex.Internal: emptySTCcSeqT :: ST s (STCcSeqT s a)
+ Data.FMIndex.Internal: emptySTOccCKCounterB :: ST s (STOccCKCounterB s Int)
+ Data.FMIndex.Internal: emptySTOccCKCounterT :: ST s (STOccCKCounterT s Int)
+ Data.FMIndex.Internal: emptySTOccCKILB :: ST s (STOccCKILB s a)
+ Data.FMIndex.Internal: emptySTOccCKILT :: ST s (STOccCKILT s a)
+ Data.FMIndex.Internal: emptySTOccCKSeqB :: ST s (STOccCKSeqB s a)
+ Data.FMIndex.Internal: emptySTOccCKSeqT :: ST s (STOccCKSeqT s a)
+ Data.FMIndex.Internal: instance GHC.Classes.Eq Data.FMIndex.Internal.CcB
+ Data.FMIndex.Internal: instance GHC.Classes.Eq Data.FMIndex.Internal.CcT
+ Data.FMIndex.Internal: instance GHC.Classes.Eq Data.FMIndex.Internal.OccCKB
+ Data.FMIndex.Internal: instance GHC.Classes.Eq Data.FMIndex.Internal.OccCKT
+ Data.FMIndex.Internal: instance GHC.Classes.Ord Data.FMIndex.Internal.CcB
+ Data.FMIndex.Internal: instance GHC.Classes.Ord Data.FMIndex.Internal.CcT
+ Data.FMIndex.Internal: instance GHC.Classes.Ord Data.FMIndex.Internal.OccCKB
+ Data.FMIndex.Internal: instance GHC.Classes.Ord Data.FMIndex.Internal.OccCKT
+ Data.FMIndex.Internal: instance GHC.Generics.Generic Data.FMIndex.Internal.CcB
+ Data.FMIndex.Internal: instance GHC.Generics.Generic Data.FMIndex.Internal.CcT
+ Data.FMIndex.Internal: instance GHC.Generics.Generic Data.FMIndex.Internal.OccCKB
+ Data.FMIndex.Internal: instance GHC.Generics.Generic Data.FMIndex.Internal.OccCKT
+ Data.FMIndex.Internal: instance GHC.Read.Read Data.FMIndex.Internal.CcB
+ Data.FMIndex.Internal: instance GHC.Read.Read Data.FMIndex.Internal.CcT
+ Data.FMIndex.Internal: instance GHC.Read.Read Data.FMIndex.Internal.OccCKB
+ Data.FMIndex.Internal: instance GHC.Read.Read Data.FMIndex.Internal.OccCKT
+ Data.FMIndex.Internal: instance GHC.Show.Show Data.FMIndex.Internal.CcB
+ Data.FMIndex.Internal: instance GHC.Show.Show Data.FMIndex.Internal.CcT
+ Data.FMIndex.Internal: instance GHC.Show.Show Data.FMIndex.Internal.OccCKB
+ Data.FMIndex.Internal: instance GHC.Show.Show Data.FMIndex.Internal.OccCKT
+ Data.FMIndex.Internal: loadSTCcILB :: STCcILB s (Maybe ByteString) -> Seq (Maybe ByteString) -> ST s ()
+ Data.FMIndex.Internal: loadSTCcILT :: STCcILT s (Maybe Text) -> Seq (Maybe Text) -> ST s ()
+ Data.FMIndex.Internal: loadSTOccCKILB :: STOccCKILB s (Maybe ByteString) -> Seq (Maybe ByteString) -> ST s ()
+ Data.FMIndex.Internal: loadSTOccCKILT :: STOccCKILT s (Maybe Text) -> Seq (Maybe Text) -> ST s ()
+ Data.FMIndex.Internal: newtype CcB
+ Data.FMIndex.Internal: newtype CcT
+ Data.FMIndex.Internal: newtype OccCKB
+ Data.FMIndex.Internal: newtype OccCKT
+ Data.FMIndex.Internal: seqToCcB :: PBCcSeqB -> ST s CcSeqB
+ Data.FMIndex.Internal: seqToCcT :: PTCcSeqT -> ST s CcSeqT
+ Data.FMIndex.Internal: seqToOccCKB :: PBOccCKSeqB -> ST s OccCKSeqB
+ Data.FMIndex.Internal: seqToOccCKT :: PTOccCKSeqT -> ST s OccCKSeqT
+ Data.FMIndex.Internal: type CcSeqB = Seq (Int, Maybe ByteString)
+ Data.FMIndex.Internal: type CcSeqT = Seq (Int, Maybe Text)
+ Data.FMIndex.Internal: type OccCKSeqB = Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))
+ Data.FMIndex.Internal: type OccCKSeqT = Seq (Maybe Text, Seq (Int, Int, Maybe Text))
+ Data.FMIndex.Internal: type PBCcSeqB = Seq (Maybe ByteString)
+ Data.FMIndex.Internal: type PBOccCKSeqB = Seq (Maybe ByteString)
+ Data.FMIndex.Internal: type PTCcSeqT = Seq (Maybe Text)
+ Data.FMIndex.Internal: type PTOccCKSeqT = Seq (Maybe Text)
+ Data.FMIndex.Internal: type STCcCounterB s a = STRef s Int
+ Data.FMIndex.Internal: type STCcCounterT s a = STRef s Int
+ Data.FMIndex.Internal: type STCcILB s a = STRef s (Seq (Maybe ByteString))
+ Data.FMIndex.Internal: type STCcILT s a = STRef s (Seq (Maybe Text))
+ Data.FMIndex.Internal: type STCcSeqB s a = STRef s CcSeqB
+ Data.FMIndex.Internal: type STCcSeqT s a = STRef s CcSeqT
+ Data.FMIndex.Internal: type STOccCKCounterB s a = STRef s Int
+ Data.FMIndex.Internal: type STOccCKCounterT s a = STRef s Int
+ Data.FMIndex.Internal: type STOccCKILB s a = STRef s (Seq (Maybe ByteString))
+ Data.FMIndex.Internal: type STOccCKILT s a = STRef s (Seq (Maybe Text))
+ Data.FMIndex.Internal: type STOccCKSeqB s a = STRef s OccCKSeqB
+ Data.FMIndex.Internal: type STOccCKSeqT s a = STRef s OccCKSeqT
+ Data.FMIndex.Internal: updateSTCcCounterB :: STCcCounterB s Int -> Int -> ST s ()
+ Data.FMIndex.Internal: updateSTCcCounterT :: STCcCounterT s Int -> Int -> ST s ()
+ Data.FMIndex.Internal: updateSTCcSeqB :: STCcSeqB s (Seq (Int, Maybe ByteString)) -> (Int, Maybe ByteString) -> ST s ()
+ Data.FMIndex.Internal: updateSTCcSeqT :: STCcSeqT s (Seq (Int, Maybe Text)) -> (Int, Maybe Text) -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKCounterB :: STOccCKCounterB s Int -> Int -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKCounterT :: STOccCKCounterT s Int -> Int -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKSeqAB :: STOccCKSeqB s (Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))) -> (Int, Int, Maybe ByteString) -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKSeqAT :: STOccCKSeqT s (Seq (Maybe Text, Seq (Int, Int, Maybe Text))) -> (Int, Int, Maybe Text) -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKSeqBB :: STOccCKSeqB s (Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString))) -> Maybe ByteString -> ST s ()
+ Data.FMIndex.Internal: updateSTOccCKSeqBT :: STOccCKSeqT s (Seq (Maybe Text, Seq (Int, Int, Maybe Text))) -> Maybe Text -> ST s ()
- Data.FMIndex: bytestringBWTToFMIndexB :: BWT Word8 -> FMIndexB
+ Data.FMIndex: bytestringBWTToFMIndexB :: BWTMatrix Word8 -> BWT Word8 -> FMIndexB
- Data.FMIndex: bytestringBWTToFMIndexT :: BWT Word8 -> FMIndexT
+ Data.FMIndex: bytestringBWTToFMIndexT :: BWTMatrix Word8 -> BWT Word8 -> FMIndexT
- Data.FMIndex: bytestringToFMIndexB :: Seq (Maybe ByteString) -> FMIndexB
+ Data.FMIndex: bytestringToFMIndexB :: BWTMatrix ByteString -> Seq (Maybe ByteString) -> FMIndexB
- Data.FMIndex: bytestringToFMIndexT :: Seq (Maybe ByteString) -> FMIndexT
+ Data.FMIndex: bytestringToFMIndexT :: BWTMatrix ByteString -> Seq (Maybe ByteString) -> FMIndexT
- Data.FMIndex: textBWTToFMIndexB :: TextBWT -> FMIndexB
+ Data.FMIndex: textBWTToFMIndexB :: BWTMatrix Word8 -> TextBWT -> FMIndexB
- Data.FMIndex: textBWTToFMIndexT :: TextBWT -> FMIndexT
+ Data.FMIndex: textBWTToFMIndexT :: BWTMatrix Word8 -> TextBWT -> FMIndexT
- Data.FMIndex: textToFMIndexB :: Seq (Maybe Text) -> FMIndexB
+ Data.FMIndex: textToFMIndexB :: BWTMatrix Text -> Seq (Maybe Text) -> FMIndexB
- Data.FMIndex: textToFMIndexT :: Seq (Maybe Text) -> FMIndexT
+ Data.FMIndex: textToFMIndexT :: BWTMatrix Text -> Seq (Maybe Text) -> FMIndexT
- Data.FMIndex.Internal: FMIndexB :: Seq (Maybe ByteString, Seq (Int, Int, Maybe ByteString)) -> FMIndexB
+ Data.FMIndex.Internal: FMIndexB :: (CcB, OccCKB) -> FMIndexB
- Data.FMIndex.Internal: FMIndexT :: Seq (Maybe Text, Seq (Int, Int, Maybe Text)) -> FMIndexT
+ Data.FMIndex.Internal: FMIndexT :: (CcT, OccCKT) -> FMIndexT

Files

CHANGELOG.md view
@@ -59,3 +59,7 @@ ## 0.1.0.14 -- 2022-11-23  * Adding example FM-index output.++## 0.1.0.15 -- 2022-11-23++* Adding C[c] table for FM-index, and reworked FM-index implementation to include the C[c] table.
src/Data/FMIndex.hs view
@@ -71,7 +71,7 @@ import Data.Char() import Data.Foldable() import Data.Maybe as DMaybe (isNothing,fromJust)-import Data.Sequence as DS (Seq(..))+import Data.Sequence as DS (Seq(..),ViewL(..),viewl) import Data.STRef() import Data.Text as DText import Data.Text.Encoding as DTE (decodeUtf8,encodeUtf8)@@ -85,33 +85,53 @@ -- to a 'FMIndexB' via a 'BWT' first. bytestringToBWTToFMIndexB :: ByteString ->                              FMIndexB-bytestringToBWTToFMIndexB = bytestringBWTToFMIndexB . bytestringToBWT+bytestringToBWTToFMIndexB xs = bytestringBWTToFMIndexB (createBWTMatrix $ BS.unpack xs)+                                                       (bytestringToBWT xs)  -- | Helper function for converting a 'ByteString' -- to a 'FMIndexT' via a 'BWT' first. bytestringToBWTToFMIndexT :: ByteString ->                              FMIndexT-bytestringToBWTToFMIndexT = bytestringBWTToFMIndexT . bytestringToBWT+bytestringToBWTToFMIndexT xs = bytestringBWTToFMIndexT (createBWTMatrix $ BS.unpack xs)+                                                       (bytestringToBWT xs)  -- | Helper function for converting a 'Text' -- to a 'FMIndexB' via a 'BWT' first. textToBWTToFMIndexB :: Text ->                        FMIndexB-textToBWTToFMIndexB = textBWTToFMIndexB . textToBWT+textToBWTToFMIndexB xs = textBWTToFMIndexB (createBWTMatrix $ BS.unpack $ DTE.encodeUtf8 xs)+                                           (textToBWT xs)  -- | Helper function for converting a 'Text' -- to a 'FMIndexT' via a 'BWT' first. textToBWTToFMIndexT :: Text ->                        FMIndexT-textToBWTToFMIndexT = textBWTToFMIndexT . textToBWT+textToBWTToFMIndexT xs = textBWTToFMIndexT (createBWTMatrix $ BS.unpack $ DTE.encodeUtf8 xs)+                                           (textToBWT xs)  -- | Take a 'BWT' of 'Word8's and generate the -- FM-index ('FMIndexB').-textBWTToFMIndexB :: TextBWT+textBWTToFMIndexB :: BWTMatrix Word8+                  -> TextBWT                   -> FMIndexB-textBWTToFMIndexB xs =-  FMIndexB (CMST.runST $ seqToFMIndexB xss)+textBWTToFMIndexB (BWTMatrix DS.Empty) _  = FMIndexB (CcB DS.Empty,OccCKB DS.Empty)+textBWTToFMIndexB bwm                  xs = do+  let occckb = CMST.runST $ seqToOccCKB xss+  let ccb    = CMST.runST $ seqToCcB bwmff+  FMIndexB (CcB ccb,OccCKB occckb)     where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just         $+                                BS.singleton $+                                fromJust x+                   ) bwmf       xss = fmap (\x -> if | isNothing x                            -> Nothing                            | otherwise@@ -124,27 +144,60 @@  -- | Take a 'BWT' of 'Word8's and generate the -- FM-index ('FMIndexB').-bytestringBWTToFMIndexB :: BWT Word8+bytestringBWTToFMIndexB :: BWTMatrix Word8+                        -> BWT Word8                         -> FMIndexB-bytestringBWTToFMIndexB xs =-  FMIndexB (CMST.runST $ seqToFMIndexB xss)+bytestringBWTToFMIndexB (BWTMatrix DS.Empty) _  = FMIndexB (CcB DS.Empty,OccCKB DS.Empty) +bytestringBWTToFMIndexB bwm                  xs = do+  let occckb = CMST.runST $ seqToOccCKB xss+  let ccb    = CMST.runST $ seqToCcB bwmff +  FMIndexB (CcB ccb,OccCKB occckb)     where-      xss = fmap (\x -> if | isNothing x-                           -> Nothing-                           | otherwise-                           -> Just         $-                              BS.singleton $-                              fromJust x-                 )-            ((\(BWT t) -> t) xs)+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just         $+                                BS.singleton $+                                fromJust x+                   ) bwmf+      xss   = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just         $+                                BS.singleton $+                                fromJust x+                   )+              ((\(BWT t) -> t) xs)  -- | Take a 'BWT' of 'Word8's and generate the -- FM-index ('FMIndexB').-textBWTToFMIndexT :: TextBWT+textBWTToFMIndexT :: BWTMatrix Word8+                  -> TextBWT                   -> FMIndexT-textBWTToFMIndexT xs =-  FMIndexT (CMST.runST $ seqToFMIndexT xss)+textBWTToFMIndexT (BWTMatrix DS.Empty) _  = FMIndexT (CcT DS.Empty,OccCKT DS.Empty)+textBWTToFMIndexT bwm                  xs = do+  let occckt = CMST.runST $ seqToOccCKT xss+  let cct    = CMST.runST $ seqToCcT bwmff+  FMIndexT (CcT cct,OccCKT occckt)     where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just           $+                                DTE.decodeUtf8 $+                                BS.singleton   $+                                fromJust x+                   ) bwmf       xss = fmap (\x -> if | isNothing x                            -> Nothing                            | otherwise@@ -158,11 +211,28 @@  -- | Take a 'BWT' of 'Word8's and generate the -- FM-index ('FMIndexT').-bytestringBWTToFMIndexT :: BWT Word8+bytestringBWTToFMIndexT :: BWTMatrix Word8+                        -> BWT Word8                         -> FMIndexT-bytestringBWTToFMIndexT xs =-  FMIndexT (CMST.runST $ seqToFMIndexT xss)+bytestringBWTToFMIndexT (BWTMatrix DS.Empty) _  = FMIndexT (CcT DS.Empty,OccCKT DS.Empty)+bytestringBWTToFMIndexT bwm                  xs = do+  let occckt = CMST.runST $ seqToOccCKT xss+  let cct    = CMST.runST $ seqToCcT bwmff+  FMIndexT (CcT cct,OccCKT occckt)     where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just           $+                                DTE.decodeUtf8 $+                                BS.singleton   $+                                fromJust x+                   ) bwmf       xss = fmap (\x -> if | isNothing x                            -> Nothing                            | otherwise@@ -174,42 +244,94 @@             ((\(BWT t) -> t) xs)  -- | Takes a 'Text' and returns the FM-index ('FMIndexB').-textToFMIndexB :: Seq (Maybe Text)+textToFMIndexB :: BWTMatrix Text+               -> Seq (Maybe Text)                -> FMIndexB-textToFMIndexB DS.Empty = FMIndexB DS.Empty-textToFMIndexB xs       =-  FMIndexB (CMST.runST $ seqToFMIndexB xss)+textToFMIndexB (BWTMatrix DS.Empty) _        = FMIndexB (CcB DS.Empty,OccCKB DS.Empty) +textToFMIndexB _                    DS.Empty = FMIndexB (CcB DS.Empty,OccCKB DS.Empty)+textToFMIndexB bwm                  xs       = do+  let occckb = CMST.runST $ seqToOccCKB xss+  let ccb    = CMST.runST $ seqToCcB bwmff+  FMIndexB (CcB ccb,OccCKB occckb)     where-      xss = fmap (\x -> if | isNothing x-                           -> Nothing-                           | otherwise-                           -> Just            $-                               DTE.encodeUtf8 $-                               fromJust x-                 )-            xs+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just           $+                                DTE.encodeUtf8 $+                                fromJust x+                   ) bwmf+      xss   = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just           $+                                DTE.encodeUtf8 $+                                fromJust x+                   )+              xs  -- | Takes a 'Seq' of 'ByteString's and returns the FM-index ('FMIndexB').-bytestringToFMIndexB :: Seq (Maybe ByteString)+bytestringToFMIndexB :: BWTMatrix ByteString+                     -> Seq (Maybe ByteString)                      -> FMIndexB-bytestringToFMIndexB DS.Empty = FMIndexB DS.Empty-bytestringToFMIndexB xs       =- FMIndexB (CMST.runST $ seqToFMIndexB xs)+bytestringToFMIndexB (BWTMatrix DS.Empty) _        = FMIndexB (CcB DS.Empty,OccCKB DS.Empty)+bytestringToFMIndexB _                    DS.Empty = FMIndexB (CcB DS.Empty,OccCKB DS.Empty)+bytestringToFMIndexB bwm                  xs       = do+  let occckb = CMST.runST $ seqToOccCKB xs+  let ccb    = CMST.runST $ seqToCcB bwmf+  FMIndexB (CcB ccb,OccCKB occckb)+    where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm  -- | Takes a 'Text' and returns the FM-index ('FMIndexT').-textToFMIndexT :: Seq (Maybe Text)+textToFMIndexT :: BWTMatrix Text+               -> Seq (Maybe Text)                -> FMIndexT-textToFMIndexT DS.Empty = FMIndexT DS.Empty-textToFMIndexT xs       =-  FMIndexT (CMST.runST $ seqToFMIndexT xs)+textToFMIndexT (BWTMatrix DS.Empty) _        = FMIndexT (CcT DS.Empty,OccCKT DS.Empty)+textToFMIndexT _                    DS.Empty = FMIndexT (CcT DS.Empty,OccCKT DS.Empty) +textToFMIndexT bwm                  xs       = do+  let occckt = CMST.runST $ seqToOccCKT xs+  let cct    = CMST.runST $ seqToCcT bwmf+  FMIndexT (CcT cct,OccCKT occckt)+    where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm  -- | Takes a 'ByteString' and returns the FM-index ('FMIndexT').-bytestringToFMIndexT :: Seq (Maybe ByteString)+bytestringToFMIndexT :: BWTMatrix ByteString+                     -> Seq (Maybe ByteString)                      -> FMIndexT-bytestringToFMIndexT DS.Empty = FMIndexT DS.Empty -bytestringToFMIndexT xs       =-  FMIndexT (CMST.runST $ seqToFMIndexT xss)+bytestringToFMIndexT (BWTMatrix DS.Empty) _        = FMIndexT (CcT DS.Empty,OccCKT DS.Empty) +bytestringToFMIndexT _                    DS.Empty = FMIndexT (CcT DS.Empty,OccCKT DS.Empty) +bytestringToFMIndexT bwm                  xs       = do+  let occckt = CMST.runST $ seqToOccCKT xss+  let cct    = CMST.runST $ seqToCcT bwmff+  FMIndexT (CcT cct,OccCKT occckt)     where+      bwmf  = fmap (\x -> case viewl x of+                            EmptyL       -> Nothing+                            (xh DS.:< _) -> xh+                   ) $+              (\(BWTMatrix m) -> m) bwm+      bwmff = fmap (\x -> if | isNothing x+                             -> Nothing+                             | otherwise+                             -> Just           $+                                DTE.decodeUtf8 $ +                                fromJust x+                   ) bwmf       xss = fmap (\x -> if | isNothing x                            -> Nothing                            | otherwise@@ -262,54 +384,59 @@ -- the 'BWT' of 'Text's. textBWTFromFMIndexT :: FMIndexT                     -> BWT Text-textBWTFromFMIndexT (FMIndexT DS.Empty) = BWT DS.Empty-textBWTFromFMIndexT xs                  =+textBWTFromFMIndexT (FMIndexT (CcT DS.Empty,_))    = BWT DS.Empty+textBWTFromFMIndexT (FMIndexT (_,OccCKT DS.Empty)) = BWT DS.Empty+textBWTFromFMIndexT xs                             =   BWT (seqFromFMIndexT xs)  -- | Takes a 'FMIndexT' and returns -- the 'BWT' of 'ByteString's. bytestringBWTFromFMIndexT :: FMIndexT                           -> BWT ByteString-bytestringBWTFromFMIndexT (FMIndexT DS.Empty) = BWT DS.Empty-bytestringBWTFromFMIndexT xs                  = do+bytestringBWTFromFMIndexT (FMIndexT (CcT DS.Empty,_))    = BWT DS.Empty+bytestringBWTFromFMIndexT (FMIndexT (_,OccCKT DS.Empty)) = BWT DS.Empty +bytestringBWTFromFMIndexT xs                             = do   let originalbwtb = seqFromFMIndexT xs   BWT (fmap (\x -> if | isNothing x                       -> Nothing                       | otherwise                       -> Just           $                          DTE.encodeUtf8 $-                        fromJust x+                         fromJust x             ) originalbwtb)  -- | Takes a 'FMIndexB' and returns -- the 'BWT' of 'Text's. textBWTFromFMIndexB :: FMIndexB                     -> BWT Text-textBWTFromFMIndexB (FMIndexB DS.Empty) = BWT DS.Empty-textBWTFromFMIndexB xs                  = do+textBWTFromFMIndexB (FMIndexB (CcB DS.Empty,_))    = BWT DS.Empty+textBWTFromFMIndexB (FMIndexB (_,OccCKB DS.Empty)) = BWT DS.Empty+textBWTFromFMIndexB xs                             = do   let originalbwtt = seqFromFMIndexB xs   BWT (fmap (\x -> if | isNothing x                       -> Nothing                       | otherwise                       -> Just           $                          DTE.decodeUtf8 $-                        fromJust x+                         fromJust x             ) originalbwtt)  -- | Take a 'FMIndexB' and returns -- the 'BWT' of 'ByteString's. bytestringBWTFromFMIndexB :: FMIndexB                           -> BWT ByteString-bytestringBWTFromFMIndexB (FMIndexB DS.Empty) = BWT DS.Empty-bytestringBWTFromFMIndexB xs              =+bytestringBWTFromFMIndexB (FMIndexB (CcB DS.Empty,_))    = BWT DS.Empty+bytestringBWTFromFMIndexB (FMIndexB (_,OccCKB DS.Empty)) = BWT DS.Empty +bytestringBWTFromFMIndexB xs                             =   BWT (seqFromFMIndexB xs)  -- | Takes a 'FMIndexB' and returns -- the original 'Seq' of 'Text's. textFromFMIndexB :: FMIndexB                  -> Seq (Maybe Text)-textFromFMIndexB (FMIndexB DS.Empty) = DS.Empty-textFromFMIndexB xs                  = do+textFromFMIndexB (FMIndexB (CcB DS.Empty,_))    = DS.Empty+textFromFMIndexB (FMIndexB (_,OccCKB DS.Empty)) = DS.Empty+textFromFMIndexB xs                             = do   let originalt = seqFromFMIndexB xs   fmap (\x -> if | isNothing x                  -> Nothing@@ -323,24 +450,27 @@ -- the original 'Seq' of 'ByteString's. bytestringFromFMIndexB :: FMIndexB                        -> Seq (Maybe ByteString)-bytestringFromFMIndexB (FMIndexB DS.Empty) = DS.Empty-bytestringFromFMIndexB xs                  =+bytestringFromFMIndexB (FMIndexB (CcB DS.Empty,_))    = DS.Empty+bytestringFromFMIndexB (FMIndexB (_,OccCKB DS.Empty)) = DS.Empty +bytestringFromFMIndexB xs                             =   seqFromFMIndexB xs  -- | Takes a 'FMIndexT' and returns -- the original 'Seq' of 'Text's. textFromFMIndexT :: FMIndexT                  -> Seq (Maybe Text)-textFromFMIndexT (FMIndexT DS.Empty) = DS.Empty-textFromFMIndexT xs                  =+textFromFMIndexT (FMIndexT (CcT DS.Empty,_))    = DS.Empty+textFromFMIndexT (FMIndexT (_,OccCKT DS.Empty)) = DS.Empty+textFromFMIndexT xs                             =   seqFromFMIndexT xs  -- | Takes a 'FMIndexT' and returns -- the original 'Seq' of 'ByteString's. bytestringFromFMIndexT :: FMIndexT                        -> Seq (Maybe ByteString)-bytestringFromFMIndexT (FMIndexT DS.Empty) = DS.Empty-bytestringFromFMIndexT xs                  = do+bytestringFromFMIndexT (FMIndexT (CcT DS.Empty,_))    = DS.Empty+bytestringFromFMIndexT (FMIndexT (_,OccCKT DS.Empty)) = DS.Empty+bytestringFromFMIndexT xs                             = do   let originalb = seqFromFMIndexT xs   fmap (\x -> if | isNothing x                  -> Nothing
src/Data/FMIndex/Internal.hs view
@@ -32,7 +32,7 @@ -- -- Various data structures and custom data types to describe the -- [Full-text Minute-space index (FM-index)](https://en.wikipedia.org/wiki/FM-index)--- and the Inverse FM-index implementations, namely 'seqToFMIndexB', 'seqToFMIndexT', 'seqFromFMIndexB', and 'seqFromFMIndexT'.+-- and the Inverse FM-index implementations, namely 'seqToOccCKB', 'seqToOccCKT', 'seqToCcB', 'seqToCcT', 'seqFromFMIndexB', and 'seqFromFMIndexT'. -- -- The FM-index implementations rely heavily upon 'Seq' provided by the [containers](https://hackage.haskell.org/package/containers), -- 'STRef' and associated functions in the [stref](https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-STRef.html) library,@@ -42,9 +42,52 @@ -- -- The below example is taken from [this](https://en.wikipedia.org/wiki/FM-index) wikipedia page. ----- FM-index output of the Burrows-Wheeler transform of the input "abracadabra" -> "ard$rcaaaabb"+-- Given the following input, "abracadabra": --+-- and --+-- Given the following Burrows-Wheeler matrix (BWM) of the input "abracadabra":+--+-- +----+---+---------------------------------------+---++-- | I  | F |                                       | L |+-- +====+===+===+===+===+===+===+===+===+===+===+===+===++-- | 1  | $ | a | b | r | a | c | a | d | a | b | r | a |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 2  | a | $ | a | b | r | a | c | a | d | a | b | r |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 3  | a | b | r | a | $ | a | b | r | a | c | a | d |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 4  | a | b | r | a | c | a | d | a | b | r | a | $ |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 5  | a | c | a | d | a | b | r | a | $ | a | b | r |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 6  | a | d | a | b | r | a | $ | a | b | r | a | c |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 7  | b | r | a | $ | a | b | r | a | c | a | d | a |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 8  | b | r | a | c | a | d | a | b | r | a | $ | a |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 9  | c | a | d | a | b | r | a | $ | a | b | r | a |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 10 | d | a | b | r | a | $ | a | b | r | a | c | a |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 11 | r | a | $ | a | b | r | a | c | a | d | a | b |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++-- | 12 | r | a | c | a | d | a | b | r | a | $ | a | b |+-- +----+---+---+---+---+---+---+---+---+---+---+---+---++--+-- The FM-index output of the Burrows-Wheeler transform of the input is:+--+-- C[c] of "ard$rcaaaabb"+--+-- +------+---+---+---+---+---+----++-- | c    | $ | a | b | c | d | r  |+-- +------+---+---+---+---+---+----++-- | C[c] | 0 | 1 | 6 | 8 | 9 | 10 |+-- +------+---+---+---+---+---+----++--+-- and+-- -- Occ(c,k) of "ard$rcaaaabb" -- -- +---+---+---+---+---+---+---+---+---+---+----+----+----+@@ -91,282 +134,502 @@ {-Base level types.-}  -- | Basic FMIndex ('ByteString') data type.-newtype FMIndexB = FMIndexB (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))+newtype FMIndexB = FMIndexB (CcB,OccCKB)   deriving (Eq,Ord,Show,Read,Generic)  -- | Basic FMIndex ('Text') data type.-newtype FMIndexT = FMIndexT (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))+newtype FMIndexT = FMIndexT (CcT,OccCKT)   deriving (Eq,Ord,Show,Read,Generic) +-- | Basic OccCKB ('ByteString') data type.+newtype OccCKB = OccCKB (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))+  deriving (Eq,Ord,Show,Read,Generic)++-- | Basic OccCKT ('Text') data type.+newtype OccCKT = OccCKT (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))+  deriving (Eq,Ord,Show,Read,Generic)++-- | Basic C[c] table ('ByteString') data type.+newtype CcB = CcB (Seq (Int,Maybe ByteString))+  deriving (Eq,Ord,Show,Read,Generic)++-- | Basic C[c] table ('Text') data type.+newtype CcT = CcT (Seq (Int,Maybe Text))+  deriving (Eq,Ord,Show,Read,Generic)+ {-------------------}  -{-toFMIndex (ByteString) functions.-}+{-toOccCK (ByteString) functions.-} --- | Abstract 'PBFMIndexSeqB' type utilizing a 'Seq'.-type PBFMIndexSeqB = Seq (Maybe ByteString)+-- | Abstract 'PBOccCKSeqB' type utilizing a 'Seq'.+type PBOccCKSeqB = Seq (Maybe ByteString) --- | Abstract 'FMIndexSeqB' type utilizing a 'Seq'.+-- | Abstract 'OccCKSeqB' type utilizing a 'Seq'. -- (c,(indexofinputcurrentelement,Occ(c,k),inputcurrentelement))-type FMIndexSeqB = Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString))+type OccCKSeqB = Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)) --- | Abstract data type representing a 'FMIndexSeqB' in the (strict) ST monad.-type STFMIndexSeqB s a = STRef s FMIndexSeqB+-- | Abstract data type representing a 'OccCKSeqB' in the (strict) ST monad.+type STOccCKSeqB s a = STRef s OccCKSeqB --- | State function to update 'FMIndexSeqB'--- with each step of the FMIndex.-updateSTFMIndexSeqAB :: STFMIndexSeqB s (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))-                     -> (Int,Int,Maybe ByteString)-                     -> ST s ()-updateSTFMIndexSeqAB s e = do+-- | State function to update 'OccCKSeqB'+-- with each step of the OccCK.+updateSTOccCKSeqAB :: STOccCKSeqB s (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))+                   -> (Int,Int,Maybe ByteString)+                   -> ST s ()+updateSTOccCKSeqAB s e = do   s2 <- readSTRef s   case viewr s2 of     EmptyR           -> pure ()     (s2h DS.:> s2fm) -> writeSTRef s (s2h DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e)) --- | State function to update 'FMIndexSeqB'--- with each step of the FMIndex.-updateSTFMIndexSeqBB :: STFMIndexSeqB s (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))-                     -> Maybe ByteString-                     -> ST s ()-updateSTFMIndexSeqBB s e = do+-- | State function to update 'OccCKSeqB'+-- with each step of the OccCK.+updateSTOccCKSeqBB :: STOccCKSeqB s (Seq (Maybe ByteString,Seq (Int,Int,Maybe ByteString)))+                   -> Maybe ByteString+                   -> ST s ()+updateSTOccCKSeqBB s e = do   s2 <- readSTRef s   writeSTRef s (s2 DS.|> (e,DS.empty)) --- | State function to create empty 'STFMIndexSeqB' type.-emptySTFMIndexSeqB :: ST s (STFMIndexSeqB s a)-emptySTFMIndexSeqB = newSTRef DS.empty+-- | State function to create empty 'STOccCKSeqB' type.+emptySTOccCKSeqB :: ST s (STOccCKSeqB s a)+emptySTOccCKSeqB = newSTRef DS.empty --- | Abstract 'STFMIndexILB' and associated state type.-type STFMIndexILB s a = STRef s (Seq (Maybe ByteString))+-- | Abstract 'STOccCKILB' and associated state type.+type STOccCKILB s a = STRef s (Seq (Maybe ByteString)) --- | State function to load list into 'STFMIndexILB'.-loadSTFMIndexILB :: STMTFILB s (Maybe ByteString)-                 -> Seq (Maybe ByteString)-                 -> ST s ()-loadSTFMIndexILB s e = writeSTRef s e+-- | State function to load list into 'STOccCKILB'.+loadSTOccCKILB :: STOccCKILB s (Maybe ByteString)+               -> Seq (Maybe ByteString)+               -> ST s ()+loadSTOccCKILB s e = writeSTRef s e --- | State function to create empty 'STFMIndexILB' type.-emptySTFMIndexILB :: ST s (STFMIndexILB s a)-emptySTFMIndexILB = newSTRef DS.empty+-- | State function to create empty 'STOccCKILB' type.+emptySTOccCKILB :: ST s (STOccCKILB s a)+emptySTOccCKILB = newSTRef DS.empty --- | Abstract 'STFMIndexCounterB' and associated state type.-type STFMIndexCounterB s a = STRef s Int+-- | Abstract 'STOccCKCounterB' and associated state type.+type STOccCKCounterB s a = STRef s Int --- | State function to update 'STFMIndexCounterB'.-updateSTFMIndexCounterB :: STFMIndexCounterB s Int+-- | State function to update 'STOccCKCounterB'.+updateSTOccCKCounterB :: STOccCKCounterB s Int                         -> Int                         -> ST s ()-updateSTFMIndexCounterB s e = writeSTRef s e+updateSTOccCKCounterB s e = writeSTRef s e --- | State function to create empty 'STFMIndexCounterB' type.-emptySTFMIndexCounterB :: ST s (STFMIndexCounterB s Int)-emptySTFMIndexCounterB = newSTRef 0 +-- | State function to create empty 'STOccCKCounterB' type.+emptySTOccCKCounterB :: ST s (STOccCKCounterB s Int)+emptySTOccCKCounterB = newSTRef 0   -- | Strict state monad function.-seqToFMIndexB :: PBFMIndexSeqB-              -> ST s FMIndexSeqB-seqToFMIndexB DS.Empty      = do-  bfmiseqstackempty  <- emptySTFMIndexSeqB-  bfmiseqstackemptyr <- readSTRef bfmiseqstackempty-  return bfmiseqstackemptyr-seqToFMIndexB xs            = do-  bfmiseqstack     <- emptySTFMIndexSeqB -  bfmiinitiallist  <- emptySTFMIndexILB-  bfmicounterstack <- emptySTFMIndexCounterB+seqToOccCKB :: PBOccCKSeqB+            -> ST s OccCKSeqB+seqToOccCKB DS.Empty      = do+  boccckseqstackempty  <- emptySTOccCKSeqB+  boccckseqstackemptyr <- readSTRef boccckseqstackempty+  return boccckseqstackemptyr+seqToOccCKB xs            = do+  boccckseqstack     <- emptySTOccCKSeqB +  boccckinitiallist  <- emptySTOccCKILB+  boccckcounterstack <- emptySTOccCKCounterB   let il = nubSeq' xs-  loadSTFMIndexILB bfmiinitiallist-                   il-  cbfmiinitiallist <- readSTRef bfmiinitiallist-  iFMIndexB cbfmiinitiallist-            xs-            bfmiseqstack-            bfmicounterstack-  bfmiseqstackr <- readSTRef bfmiseqstack-  return bfmiseqstackr+  loadSTOccCKILB boccckinitiallist+                 il+  cboccckinitiallist <- readSTRef boccckinitiallist+  iOccCKB cboccckinitiallist+          xs+          boccckseqstack+          boccckcounterstack+  boccckseqstackr <- readSTRef boccckseqstack+  return boccckseqstackr     where-      iFMIndexB DS.Empty      _      _      _      = pure ()-      iFMIndexB (y DS.:<| ys) zs     bfmiss bfmics = do-        bfmiis <- emptySTFMIndexCounterB-        updateSTFMIndexCounterB bfmiis-                                1-        updateSTFMIndexSeqBB bfmiss-                             y-        iiFMIndexB y-                   zs-                   bfmiss-                   bfmiis-                   bfmics                           -        iFMIndexB ys-                  zs-                  bfmiss-                  bfmics-      iiFMIndexB _  DS.Empty      _      _      bfmics = do-        updateSTFMIndexCounterB bfmics-                                0+      iOccCKB DS.Empty      _      _        _        = pure ()+      iOccCKB (y DS.:<| ys) zs     boccckss boccckcs = do+        boccckis <- emptySTOccCKCounterB+        updateSTOccCKCounterB boccckis+                              1+        updateSTOccCKSeqBB boccckss+                           y+        iiOccCKB y+                 zs+                 boccckss+                 boccckis+                 boccckcs                           +        iOccCKB ys+                zs+                boccckss+                boccckcs+      iiOccCKB _  DS.Empty      _        _        boccckcs = do+        updateSTOccCKCounterB boccckcs+                              0         pure ()-      iiFMIndexB as (b DS.:<| bs) bfmiss bfmiis bfmics = do-        cbfmiis <- readSTRef bfmiis-        cbfmics <- readSTRef bfmics+      iiOccCKB as (b DS.:<| bs) boccckss boccckis boccckcs = do+        cboccckis <- readSTRef boccckis+        cboccckcs <- readSTRef boccckcs         if | as == b-           -> do updateSTFMIndexSeqAB bfmiss-                                      (cbfmiis,cbfmics + 1,b)-                 updateSTFMIndexCounterB bfmics-                                         (cbfmics + 1)-                 updateSTFMIndexCounterB bfmiis-                                         (cbfmiis + 1)-                 iiFMIndexB as-                            bs-                            bfmiss-                            bfmiis-                            bfmics    +           -> do updateSTOccCKSeqAB boccckss+                                    (cboccckis,cboccckcs + 1,b)+                 updateSTOccCKCounterB boccckcs+                                       (cboccckcs + 1)+                 updateSTOccCKCounterB boccckis+                                       (cboccckis + 1)+                 iiOccCKB as+                          bs+                          boccckss+                          boccckis+                          boccckcs                | otherwise-           -> do updateSTFMIndexSeqAB bfmiss-                                      (cbfmiis,cbfmics,b)-                 updateSTFMIndexCounterB bfmiis-                                         (cbfmiis + 1)-                 iiFMIndexB as-                            bs-                            bfmiss-                            bfmiis-                            bfmics+           -> do updateSTOccCKSeqAB boccckss+                                    (cboccckis,cboccckcs,b)+                 updateSTOccCKCounterB boccckis+                                       (cboccckis + 1)+                 iiOccCKB as+                          bs+                          boccckss+                          boccckis+                          boccckcs -{-----------------------------------}+{---------------------------------}  -{-toFMIndex (Text) functions.-}+{-toOccCK (Text) functions.-} --- | Abstract 'PTFMIndexSeqT' type utilizing a 'Seq'.-type PTFMIndexSeqT = Seq (Maybe Text)+-- | Abstract 'PTOccCKSeqT' type utilizing a 'Seq'.+type PTOccCKSeqT = Seq (Maybe Text) --- | Abstract 'FMIndexSeqT' type utilizing a 'Seq'.+-- | Abstract 'OccCKSeqT' type utilizing a 'Seq'. -- (c,(indexofinputcurrentelement,Occ(c,k),inputcurrentelement))-type FMIndexSeqT = Seq (Maybe Text,Seq (Int,Int,Maybe Text))+type OccCKSeqT = Seq (Maybe Text,Seq (Int,Int,Maybe Text)) --- | Abstract data type representing a 'FMIndexSeqT' in the (strict) ST monad.-type STFMIndexSeqT s a = STRef s FMIndexSeqT+-- | Abstract data type representing a 'OccCKSeqT' in the (strict) ST monad.+type STOccCKSeqT s a = STRef s OccCKSeqT --- | State function to update 'FMIndexSeqT'--- with each step of the FMIndex.-updateSTFMIndexSeqAT :: STFMIndexSeqT s (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))-                     -> (Int,Int,Maybe Text)-                     -> ST s ()-updateSTFMIndexSeqAT s e = do+-- | State function to update 'OccCKSeqT'+-- with each step of the OccCK.+updateSTOccCKSeqAT :: STOccCKSeqT s (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))+                   -> (Int,Int,Maybe Text)+                   -> ST s ()+updateSTOccCKSeqAT s e = do   s2 <- readSTRef s   case viewr s2 of     EmptyR           -> pure ()     (s2h DS.:> s2fm) -> writeSTRef s (s2h DS.|> (((\(a,_) -> a) s2fm),((\(_,b) -> b) s2fm) DS.|> e)) --- | State function to update 'FMIndexSeqT'--- with each step of the FMIndex.-updateSTFMIndexSeqBT :: STFMIndexSeqT s (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))-                     -> Maybe Text-                     -> ST s ()-updateSTFMIndexSeqBT s e = do+-- | State function to update 'OccCKSeqT'+-- with each step of the OccCK.+updateSTOccCKSeqBT :: STOccCKSeqT s (Seq (Maybe Text,Seq (Int,Int,Maybe Text)))+                   -> Maybe Text+                   -> ST s ()+updateSTOccCKSeqBT s e = do   s2 <- readSTRef s   writeSTRef s (s2 DS.|> (e,DS.empty)) --- | State function to create empty 'STFMIndexSeqT' type.-emptySTFMIndexSeqT :: ST s (STFMIndexSeqT s a)-emptySTFMIndexSeqT = newSTRef DS.empty+-- | State function to create empty 'STOccCKSeqT' type.+emptySTOccCKSeqT :: ST s (STOccCKSeqT s a)+emptySTOccCKSeqT = newSTRef DS.empty --- | Abstract 'STFMIndexILT' and associated state type.-type STFMIndexILT s a = STRef s (Seq (Maybe Text))+-- | Abstract 'STOccCKILT' and associated state type.+type STOccCKILT s a = STRef s (Seq (Maybe Text)) --- | State function to load list into 'STFMIndexILT'.-loadSTFMIndexILT :: STMTFILT s (Maybe Text)-                 -> Seq (Maybe Text)-                 -> ST s ()-loadSTFMIndexILT s e = writeSTRef s e+-- | State function to load list into 'STOccCKILT'.+loadSTOccCKILT :: STOccCKILT s (Maybe Text)+               -> Seq (Maybe Text)+               -> ST s ()+loadSTOccCKILT s e = writeSTRef s e --- | State function to create empty 'STFMIndexILT' type.-emptySTFMIndexILT :: ST s (STFMIndexILT s a)-emptySTFMIndexILT = newSTRef DS.empty+-- | State function to create empty 'STOccCKILT' type.+emptySTOccCKILT :: ST s (STOccCKILT s a)+emptySTOccCKILT = newSTRef DS.empty --- | Abstract 'STFMIndexCounterT' and associated state type.-type STFMIndexCounterT s a = STRef s Int+-- | Abstract 'STOccCKCounterT' and associated state type.+type STOccCKCounterT s a = STRef s Int --- | State function to update 'STFMIndexCounterT'.-updateSTFMIndexCounterT :: STFMIndexCounterT s Int-                        -> Int-                        -> ST s ()-updateSTFMIndexCounterT s e = writeSTRef s e+-- | State function to update 'STOccCKCounterT'.+updateSTOccCKCounterT :: STOccCKCounterT s Int+                      -> Int+                      -> ST s ()+updateSTOccCKCounterT s e = writeSTRef s e --- | State function to create empty 'STFMIndexCounterT' type.-emptySTFMIndexCounterT :: ST s (STFMIndexCounterT s Int)-emptySTFMIndexCounterT = newSTRef 0+-- | State function to create empty 'STOccCKCounterT' type.+emptySTOccCKCounterT :: ST s (STOccCKCounterT s Int)+emptySTOccCKCounterT = newSTRef 0  -- | Strict state monad function.-seqToFMIndexT :: PTFMIndexSeqT-              -> ST s FMIndexSeqT-seqToFMIndexT DS.Empty      = do-  tfmiseqstackempty  <- emptySTFMIndexSeqT-  tfmiseqstackemptyr <- readSTRef tfmiseqstackempty-  return tfmiseqstackemptyr-seqToFMIndexT xs            = do-  tfmiseqstack     <- emptySTFMIndexSeqT-  tfmiinitiallist  <- emptySTFMIndexILT-  tfmicounterstack <- emptySTFMIndexCounterT+seqToOccCKT :: PTOccCKSeqT+            -> ST s OccCKSeqT+seqToOccCKT DS.Empty      = do+  toccckseqstackempty  <- emptySTOccCKSeqT+  toccckseqstackemptyr <- readSTRef toccckseqstackempty+  return toccckseqstackemptyr+seqToOccCKT xs            = do+  toccckseqstack     <- emptySTOccCKSeqT+  toccckinitiallist  <- emptySTOccCKILT+  toccckcounterstack <- emptySTOccCKCounterT   let il = nubSeq' xs-  loadSTFMIndexILT tfmiinitiallist-                   il-  ctfmiinitiallist <- readSTRef tfmiinitiallist-  iFMIndexT ctfmiinitiallist-            xs-            tfmiseqstack-            tfmicounterstack-  tfmiseqstackr <- readSTRef tfmiseqstack-  return tfmiseqstackr+  loadSTOccCKILT toccckinitiallist+                 il+  ctoccckinitiallist <- readSTRef toccckinitiallist+  iOccCKT ctoccckinitiallist+          xs+          toccckseqstack+          toccckcounterstack+  toccckseqstackr <- readSTRef toccckseqstack+  return toccckseqstackr     where-      iFMIndexT DS.Empty      _      _      _      = pure ()-      iFMIndexT (y DS.:<| ys) zs     tfmiss tfmics = do-        tfmiis <- emptySTFMIndexCounterT-        updateSTFMIndexCounterT tfmiis-                                1-        updateSTFMIndexSeqBT tfmiss-                             y-        iiFMIndexT y-                   zs-                   tfmiss-                   tfmiis-                   tfmics-        iFMIndexT ys-                  zs-                  tfmiss-                  tfmics-      iiFMIndexT _  DS.Empty      _      _      tfmics = do-        updateSTFMIndexCounterT tfmics-                                0+      iOccCKT DS.Empty      _      _        _        = pure ()+      iOccCKT (y DS.:<| ys) zs     toccckss toccckcs = do+        toccckis <- emptySTOccCKCounterT+        updateSTOccCKCounterT toccckis+                              1+        updateSTOccCKSeqBT toccckss+                           y+        iiOccCKT y+                 zs+                 toccckss+                 toccckis+                 toccckcs+        iOccCKT ys+                zs+                toccckss+                toccckcs+      iiOccCKT _  DS.Empty      _        _        toccckcs = do+        updateSTOccCKCounterT toccckcs+                              0         pure ()-      iiFMIndexT as (b DS.:<| bs) tfmiss tfmiis tfmics = do-        ctfmiis <- readSTRef tfmiis-        ctfmics <- readSTRef tfmics+      iiOccCKT as (b DS.:<| bs) toccckss toccckis toccckcs = do+        ctoccckis <- readSTRef toccckis+        ctoccckcs <- readSTRef toccckcs         if | as == b-           -> do updateSTFMIndexSeqAT tfmiss-                                      (ctfmiis,ctfmics + 1,b)-                 updateSTFMIndexCounterT tfmics-                                         (ctfmics + 1)-                 updateSTFMIndexCounterT tfmiis-                                         (ctfmiis + 1)-                 iiFMIndexT as-                            bs-                            tfmiss-                            tfmiis-                            tfmics+           -> do updateSTOccCKSeqAT toccckss+                                    (ctoccckis,ctoccckcs + 1,b)+                 updateSTOccCKCounterT toccckcs+                                       (ctoccckcs + 1)+                 updateSTOccCKCounterT toccckis+                                       (ctoccckis + 1)+                 iiOccCKT as+                          bs+                          toccckss+                          toccckis+                          toccckcs            | otherwise-           -> do updateSTFMIndexSeqAT tfmiss-                                      (ctfmiis,ctfmics,b)-                 updateSTFMIndexCounterT tfmiis-                                         (ctfmiis + 1)-                 iiFMIndexT as-                            bs-                            tfmiss-                            tfmiis-                            tfmics+           -> do updateSTOccCKSeqAT toccckss+                                    (ctoccckis,ctoccckcs,b)+                 updateSTOccCKCounterT toccckis+                                       (ctoccckis + 1)+                 iiOccCKT as+                          bs+                          toccckss+                          toccckis+                          toccckcs -{-----------------------------}+{---------------------------}  +{-To Cc (ByteString) functions.-}++-- | Abstract 'PBCcSeqB' type utilizing a 'Seq'.+type PBCcSeqB = Seq (Maybe ByteString)++-- | Abstract 'CcSeqB' type utilizing a 'Seq'.+-- (C[c],c)+type CcSeqB = Seq (Int,Maybe ByteString)++-- | Abstract data type representing a 'CcSeqB' in the (strict) ST monad.+type STCcSeqB s a = STRef s CcSeqB++-- | State function to update 'CcSeqB'+-- with each step of the C[c].+updateSTCcSeqB :: STCcSeqB s (Seq (Int,Maybe ByteString))+               -> (Int,Maybe ByteString)+               -> ST s ()+updateSTCcSeqB s e = do+  s2 <- readSTRef s+  writeSTRef s (s2 DS.|> e)++-- | State function to create empty 'STCcSeqT' type.+emptySTCcSeqB :: ST s (STCcSeqB s a)+emptySTCcSeqB = newSTRef DS.empty++-- | Abstract 'STCcILB' and associated state type.+type STCcILB s a = STRef s (Seq (Maybe ByteString))++-- | State function to load list into 'STCcILB'.+loadSTCcILB :: STCcILB s (Maybe ByteString)+            -> Seq (Maybe ByteString)+            -> ST s ()+loadSTCcILB s e = writeSTRef s e++-- | State function to create empty 'STCcILB' type.+emptySTCcILB :: ST s (STCcILB s a)+emptySTCcILB = newSTRef DS.empty++-- | Abstract 'STCcCounterB' and associated state type.+type STCcCounterB s a = STRef s Int++-- | State function to update 'STCcCounterB'.+updateSTCcCounterB :: STCcCounterB s Int+                   -> Int+                   -> ST s ()+updateSTCcCounterB s e = writeSTRef s e++-- | State function to create empty 'STCcCounterT' type.+emptySTCcCounterB :: ST s (STCcCounterB s Int)+emptySTCcCounterB = newSTRef 0++-- | Strict state monad function.+seqToCcB :: PBCcSeqB+         -> ST s CcSeqB+seqToCcB DS.Empty      = do+  bccseqstackempty  <- emptySTCcSeqB+  bccseqstackemptyr <- readSTRef bccseqstackempty+  return bccseqstackemptyr+seqToCcB xs            = do+  bccseqstack     <- emptySTCcSeqB+  bccinitiallist  <- emptySTCcILB+  bcccounterstack <- emptySTCcCounterB+  let il = nubSeq' xs+  loadSTCcILB bccinitiallist+              il+  cbccinitiallist <- readSTRef bccinitiallist+  iCcB cbccinitiallist+       xs+       bccseqstack+       bcccounterstack+  bccseqstackr <- readSTRef bccseqstack+  return bccseqstackr+    where+      iCcB DS.Empty      _      _        _  = pure ()+      iCcB (y DS.:<| ys) zs     bccss bcccs = do+        updateSTCcCounterB bcccs+                           0+        iiCcB y+              zs+              bccss+              bcccs+        iCcB ys+             zs+             bccss+             bcccs+      iiCcB _  DS.Empty      _     _     = pure ()+      iiCcB as (b DS.:<| bs) bccss bcccs = do+        cbcccs <- readSTRef bcccs+        if | as == b+           -> updateSTCcSeqB bccss+                             (cbcccs,as) +           | otherwise+           -> do updateSTCcCounterB bcccs+                                    (cbcccs + 1)+                 iiCcB as+                       bs+                       bccss +                       bcccs++{-------------------------------}+++{-To Cc (Text) functions.-}++-- | Abstract 'PTCcSeqT' type utilizing a 'Seq'.+type PTCcSeqT = Seq (Maybe Text)++-- | Abstract 'CcSeqT' type utilizing a 'Seq'.+-- (C[c],c)+type CcSeqT = Seq (Int,Maybe Text)++-- | Abstract data type representing a 'CcSeqT' in the (strict) ST monad.+type STCcSeqT s a = STRef s CcSeqT++-- | State function to update 'CcSeqT'+-- with each step of the C[c].+updateSTCcSeqT :: STCcSeqT s (Seq (Int,Maybe Text))+               -> (Int,Maybe Text)+               -> ST s ()+updateSTCcSeqT s e = do+  s2 <- readSTRef s+  writeSTRef s (s2 DS.|> e)++-- | State function to create empty 'STCcSeqT' type.+emptySTCcSeqT :: ST s (STCcSeqT s a)+emptySTCcSeqT = newSTRef DS.empty++-- | Abstract 'STCcILT' and associated state type.+type STCcILT s a = STRef s (Seq (Maybe Text))++-- | State function to load list into 'STCcILT'.+loadSTCcILT :: STCcILT s (Maybe Text)+            -> Seq (Maybe Text)+            -> ST s ()+loadSTCcILT s e = writeSTRef s e++-- | State function to create empty 'STCcILT' type.+emptySTCcILT :: ST s (STCcILT s a)+emptySTCcILT = newSTRef DS.empty++-- | Abstract 'STCcCounterT' and associated state type.+type STCcCounterT s a = STRef s Int++-- | State function to update 'STCcCounterT'.+updateSTCcCounterT :: STCcCounterT s Int+                   -> Int+                   -> ST s ()+updateSTCcCounterT s e = writeSTRef s e++-- | State function to create empty 'STCcCounterT' type.+emptySTCcCounterT :: ST s (STCcCounterT s Int)+emptySTCcCounterT = newSTRef 0++-- | Strict state monad function.+seqToCcT :: PTCcSeqT+         -> ST s CcSeqT+seqToCcT DS.Empty      = do+  tccseqstackempty  <- emptySTCcSeqT+  tccseqstackemptyr <- readSTRef tccseqstackempty+  return tccseqstackemptyr+seqToCcT xs            = do+  tccseqstack     <- emptySTCcSeqT+  tccinitiallist  <- emptySTCcILT+  tcccounterstack <- emptySTCcCounterT+  let il = nubSeq' xs+  loadSTCcILT tccinitiallist+              il+  ctccinitiallist <- readSTRef tccinitiallist+  iCcT ctccinitiallist+       xs+       tccseqstack+       tcccounterstack+  tccseqstackr <- readSTRef tccseqstack+  return tccseqstackr+    where+      iCcT DS.Empty      _      _        _  = pure ()+      iCcT (y DS.:<| ys) zs     tccss tcccs = do+        updateSTCcCounterT tcccs+                           0+        iiCcT y+              zs+              tccss+              tcccs+        iCcT ys+             zs+             tccss+             tcccs+      iiCcT _  DS.Empty      _     _     = pure ()+      iiCcT as (b DS.:<| bs) tccss tcccs = do+        ctcccs <- readSTRef tcccs+        if | as == b+           -> updateSTCcSeqT tccss+                             (ctcccs,as)+           | otherwise+           -> do updateSTCcCounterT tcccs+                                    (ctcccs + 1)+                 iiCcT as+                       bs+                       tccss+                       tcccs++{-------------------------}++ {-fromFMIndex (ByteString) functions.-}  -- | Abstract 'FFMIndexSeqB' type utilizing a 'Seq'.@@ -375,9 +638,12 @@ -- | Simple Inverse FMIndex function.  seqFromFMIndexB :: FMIndexB                 -> FFMIndexSeqB-seqFromFMIndexB (FMIndexB DS.Empty) = DS.Empty-seqFromFMIndexB xs                  = do-  let xss = (\(FMIndexB b) -> b) xs+seqFromFMIndexB (FMIndexB (CcB DS.Empty,_))    = DS.Empty+seqFromFMIndexB (FMIndexB (_,OccCKB DS.Empty)) = DS.Empty+seqFromFMIndexB xs                             = do+  let xss = (\(OccCKB b) -> b) $+            (\(_,b) -> b)      $+            (\(FMIndexB b) -> b) xs   iFFMIndexB xss     where       iFFMIndexB DS.Empty         = DS.Empty @@ -395,9 +661,12 @@ -- | Simple Inverse FMIndex function. seqFromFMIndexT :: FMIndexT                 -> FFMIndexSeqT-seqFromFMIndexT (FMIndexT DS.Empty) = DS.Empty-seqFromFMIndexT xs                  = do-  let xss = (\(FMIndexT t) -> t) xs+seqFromFMIndexT (FMIndexT (CcT DS.Empty,_))    = DS.Empty+seqFromFMIndexT (FMIndexT (_,OccCKT DS.Empty)) = DS.Empty+seqFromFMIndexT xs                             = do+  let xss = (\(OccCKT t) -> t) $+            (\(_,b) -> b)      $+            (\(FMIndexT t) -> t) xs   iFFMIndexT xss     where       iFFMIndexT DS.Empty         = DS.Empty
text-compression.cabal view
@@ -20,7 +20,7 @@ -- PVP summary:     +-+------- breaking API changes --                  | | +----- non-breaking API additions --                  | | | +--- code changes with no API change-version:            0.1.0.14+version:            0.1.0.15  -- A short (one-line) description of the package. synopsis:           A text compression library.