Created
December 12, 2018 11:03
-
-
Save HemantNegi/027f8aabd96107d32c66e96a41ad346f to your computer and use it in GitHub Desktop.
Data encoding by difference
This file contains 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
def delta_encode(array): | |
first = False | |
pre = None | |
diff = None | |
res = [] | |
for i in array: | |
if not first: | |
res.append(i) | |
first = True | |
pre = i | |
else: | |
diff = i - pre | |
if not -127 <= diff <= 127: | |
res.append(-128) | |
res.append(diff) | |
pre = i | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment