packages feed

text-compression 0.1.0.5 → 0.1.0.6

raw patch · 4 files changed

+52/−8 lines, 4 filesdep +bytestringdep +textPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: bytestring, text

API changes (from Hackage documentation)

+ Data.BWT: TextBWT :: BWT Word8 -> TextBWT
+ Data.BWT: bytestringFromBWT :: BWT Word8 -> ByteString
+ Data.BWT: bytestringToBWT :: ByteString -> BWT Word8
+ Data.BWT: newtype TextBWT
+ Data.BWT: textFromBWT :: TextBWT -> Text
+ Data.BWT: textToBWT :: Text -> TextBWT

Files

CHANGELOG.md view
@@ -24,3 +24,8 @@  * First version. * Removed requirement for avoiding input with the '$' character in both the toBWT and fromBWT functions (both toBWT and fromBWT functions are now polymorphic).++## 0.1.0.6 -- 2022-11-05++* First version.+* Added helper functions to ease conversion of ByteStrings and Text to and from the BWT type.
src/Data/BWT.hs view
@@ -15,6 +15,8 @@ -- The two functions that most users will utilize are 'toBWT' and 'fromBWT'. -- There are auxilary function(s) inside of @"Data.BWT.Internal"@. --+-- The helper functions for ByteString, 'bytestringToBWT' and 'bytestringFromBWT' and Text, 'textToBWT' and 'textFromBWT' should help for common use cases.+-- -- @"Data.BWT.Internal"@ also has the function 'createBWTMatrix', which can be useful as well, although not used by either 'toBWT' or 'fromBWT'.  @@ -25,12 +27,16 @@ import Control.Monad() import Control.Monad.ST as CMST import Control.Monad.State.Strict()+import Data.ByteString as BS (ByteString,pack,unpack) import Data.Foldable as DFold (toList) import Data.Sequence as DS import Data.STRef()+import Data.Text (Text)+import Data.Text.Encoding as DTE (decodeUtf8,encodeUtf8)+import Data.Word (Word8)  -{-toBWT function(s).-}+{-toBWT Function(s)-}  -- | Takes a String and returns the Burrows-Wheeler Transform (BWT). -- Implemented via a 'SuffixArray'.@@ -45,11 +51,27 @@     where       xss = DS.fromList xs -{--------------------}+-- | Helper function for converting a 'ByteString'+-- to a 'BWT' 'Word8'.+bytestringToBWT :: ByteString ->+                   BWT Word8+bytestringToBWT = toBWT . BS.unpack +-- newtype to ensure you only uncompress a BWT created+-- from textToBWT, since [Word8] -> Text is partial+newtype TextBWT = TextBWT (BWT Word8) -{-fromBWT function(s).-}+-- | Helper function for converting 'Text'+-- to a 'TextBWT'.+textToBWT :: Text ->+             TextBWT+textToBWT = TextBWT . bytestringToBWT . DTE.encodeUtf8 +{-------------------}+++{-fromBWT function(s)-}+ -- | Takes a BWT data type (please see @"Data.BWT.Internal"@) and inverts it back to the original string. --  -- This function utilizes the state monad (strict) in order@@ -67,4 +89,16 @@       zipped  = DS.zip bwt                        (DS.iterateN (DS.length bwt) (+1) 0) -{----------------------}+-- | Helper function for converting a 'BWT' 'Word8'+-- to a 'ByteString'.+bytestringFromBWT :: BWT Word8 ->+                     ByteString+bytestringFromBWT = BS.pack . fromBWT++-- | Helper function for converting 'TextBWT'+-- to a 'Text'+textFromBWT :: TextBWT -> Text+textFromBWT (TextBWT x) = DTE.decodeUtf8 $+                          bytestringFromBWT x++{---------------------}
src/Data/BWT/Internal.hs view
@@ -132,7 +132,10 @@ -- | Hierarchical sorting scheme that compares fst first then snd. -- Necessary for the setting up the BWT in order to correctly -- invert it using the [Magic](https://www.youtube.com/watch?v=QwSsppKrCj4) algorithm.-sortTB :: (Ord a1, Ord a2) => (a1, a2) -> (a1, a2) -> Ordering+sortTB :: (Ord a1, Ord a2) =>+          (a1, a2)         ->+          (a1, a2)         ->+          Ordering sortTB (c1,i1) (c2,i2) = compare c1 c2 <>                          compare i1 i2 
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.5+version:            0.1.0.6  -- A short (one-line) description of the package. synopsis:           A text compression library.@@ -74,10 +74,12 @@     -- other-extensions:      -- Other library packages from which modules are imported.-    build-depends:    base       ^>=4.16.3.0, +    build-depends:    base       ^>=4.16.3.0,+                      bytestring >= 0.11.3 && < 0.12,                       containers >= 0.6.5 && < 0.7,                       massiv     >= 1.0.2 && < 1.1,-                      mtl        >= 2.2.2 && < 2.3 +                      mtl        >= 2.2.2 && < 2.3,+                      text       >= 1.2.5 && < 1.3      -- Directories containing source files.     hs-source-dirs:   src