Skip to content

Instantly share code, notes, and snippets.

@samidarko
Created March 8, 2018 09:54
Show Gist options
  • Save samidarko/fe6eccfce6a366abc7d0df53e60e75e5 to your computer and use it in GitHub Desktop.
Save samidarko/fe6eccfce6a366abc7d0df53e60e75e5 to your computer and use it in GitHub Desktop.
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