Created
March 8, 2018 09:54
-
-
Save samidarko/fe6eccfce6a366abc7d0df53e60e75e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = [25626, 25757, 24367, 24267, 16, 100, 2, 7277] | |
deltaEncoding :: (Ord a, Num a) => [a] -> [a] | |
deltaEncoding xs = head xs : fn (xs) | |
where fn (x:y:ys) = let n = y - x -- : fn (y:ys) | |
in if isSingleByte n | |
then n : fn (y:ys) | |
else -128 : n :fn (y:ys) | |
fn (x:[]) = [] | |
isSingleByte b = -127 <= b && b <= 127 | |
-- deltaEncoding l == [25626,-128,131,-128,-1390,-100,-128,-24251,84,-98,-128,7275] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment