From: Ramakrishnan Muthukrishnan Date: Tue, 29 Dec 2015 07:29:14 +0000 (+0530) Subject: refactor genInstructions X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/about/provisioning?a=commitdiff_plain;h=103df7121b5fe5e2f459234b03d14fc5af9df215;p=hs-rsync.git refactor genInstructions --- diff --git a/src/Lib.hs b/src/Lib.hs index 4a6ded1..01eb180 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -43,8 +43,6 @@ data Instruction = RChar Word8 genInstructions :: [Signature] -> Integer -> BL.ByteString -> [Instruction] genInstructions f0sigs blockSize fnew = - -- create two hash tables one with adler32 as key and list of block numbers as values - -- another with md4sum as key and block numbers as values. evalState (go fnew) 0 where go :: BL.ByteString -> State Word32 [Instruction] @@ -52,23 +50,17 @@ genInstructions f0sigs blockSize fnew = | otherwise = let (blk, blks) = BL.splitAt (fromIntegral blockSize) fnew adlerSum = weakSig blk + matches = M.lookup adlerSum f0AdlerTable >> + M.lookup (blockSig blk) f0MD4Table in - case M.lookup adlerSum f0AdlerTable of + case matches of + Just idxs -> do + is <- go blks + return $ RBlk (head idxs) : is Nothing -> do put adlerSum is <- go (BL.tail (blk `mappend` blks)) return $ RChar (BL.head blk) : is - Just _ -> - let md4sum = blockSig blk - in - case M.lookup md4sum f0MD4Table of - Just i -> do - is <- go blks - return $ RBlk (head i) : is - Nothing -> do - put adlerSum - is <- go (BL.tail (blk `mappend` blks)) - return $ RChar (BL.head blk) : is f0AdlerTable = toAdlerMap f0sigs f0MD4Table = toMD4Map f0sigs