-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Grammar-based compression algorithms SEQUITUR -- -- Please see the README on GitHub at -- https://github.com/msakai/haskell-sequitur#readme @package sequitur @version 0.1.0.0 -- | SEQUITUR is a linear-time, online algorithm for producing a -- context-free grammar from an input sequence. The resulting grammar is -- a compact representation of original sequence and can be used for data -- compression. -- -- Example: -- -- -- -- SEQUITUR consumes input symbols one-by-one and append each -- symbol at the end of the grammar's start production (S in the -- above example), then substitutes repeating patterns in the given -- sequence with new rules. SEQUITUR maintains two invariants: -- -- -- -- References: -- -- module Language.Grammar.Sequitur -- | A grammar is a mappping from non-terminal (left-hand side of the rule) -- to sequnce of symbols (right hand side of the rule). -- -- Non-terminal is represented as a RuleId. type Grammar a = IntMap [Symbol a] -- | A non-terminal symbol is represented by an Int. -- -- The number 0 is reserved for the start symbol of the grammar. type RuleId = Int -- | A symbol is either a terminal symbol (from user-specified type) or a -- non-terminal symbol which we represent using RuleId type. data Symbol a NonTerminal :: !RuleId -> Symbol a Terminal :: !a -> Symbol a -- | Construct a grammer from a given sequence of symbols using -- SEQUITUR. encode :: (Eq a, Hashable a) => [a] -> Grammar a -- | Reconstruct a input sequence from a grammar. -- -- This is a left-inverse of encode. -- -- This function is implemented as -- --
--   decode = toList . decodeToSeq
--   
-- -- and provided just for convenience. For serious usage, use -- decodeToSeq or decodeLazy. decode :: HasCallStack => Grammar a -> [a] -- | A variant of decode but you can consume from the beginning -- before constructing entire sequence. decodeLazy :: HasCallStack => Grammar a -> [a] -- | A variant of decode with possibly better performance. decodeToSeq :: HasCallStack => Grammar a -> Seq a -- | Monoid-based folding over the decoded sequence. -- -- This function is equivalent to the following definition, is more -- efficent due to the utilization of sharing.b -- --
--   decodeToMonoid f = mconcat . map f . decode
--   
decodeToMonoid :: (Monoid m, HasCallStack) => (a -> m) -> Grammar a -> m -- | Builder denotes a internal state of the SEQUITUR -- algorithm. data Builder s a -- | Create a new Builder. newBuilder :: PrimMonad m => m (Builder (PrimState m) a) -- | Add a new symbol to the end of grammar's start production, and perform -- normalization to keep the invariants of SEQUITUR algorithm. add :: (PrimMonad m, Eq a, Hashable a) => Builder (PrimState m) a -> a -> m () -- | Retrieve a grammar (as a persistent data structure) from -- Builder's internal state. build :: PrimMonad m => Builder (PrimState m) a -> m (Grammar a) instance GHC.Generics.Generic (Language.Grammar.Sequitur.Symbol a) instance GHC.Show.Show a => GHC.Show.Show (Language.Grammar.Sequitur.Symbol a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Language.Grammar.Sequitur.Symbol a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Language.Grammar.Sequitur.Symbol a) instance GHC.Generics.Generic (Language.Grammar.Sequitur.Node s a) instance GHC.Classes.Eq (Language.Grammar.Sequitur.Rule s a) instance Data.Hashable.Class.Hashable (Language.Grammar.Sequitur.Rule s a) instance GHC.Classes.Eq (Language.Grammar.Sequitur.Node s a) instance Data.Hashable.Class.Hashable a => Data.Hashable.Class.Hashable (Language.Grammar.Sequitur.Symbol a)