Commits

Eric Rochester committed b98562a

Added initial version of append.

  • Participants
  • Parent commits 3782c3f

Comments (0)

Files changed (1)

File src/Data/Sequitur.hs

 -- that includes it.
 feed :: Eq a => Compressor a -> a -> Compressor a
 feed compressor item =
-    c0 = append compressor 0 item
+    append compressor 0 item
 
 -- | This appends a symbol to a rule.
 append :: Eq a => Compressor a -> Int -> a -> Compressor a
-append compressor _ _ = compressor
+append compressor ruleKey item | ruleKey `M.notMember` crules =
+    Compressor (M.insert ruleKey ruleBody crules)
+               (1 + (ruleCount compressor))
+               (ruleUtility compressor)
+               (digramIndex compressor)
+    where crules   = rules compressor
+          ruleBody = S.singleton $ Literal item
+append compressor ruleKey item =
+    Compressor (M.insert ruleKey ruleBody crules)
+               (ruleCount compressor)
+               (ruleUtility compressor)
+               (digramIndex compressor)
+    where crules   = rules compressor
+          ruleBody = crules M.! ruleKey S.|> Literal item
 
 -- | This uses an existing rule.
 use :: Compressor a -> Int -> Compressor a