Created
October 5, 2017 09:35
-
-
Save kornelski/710db9d30a64db0807c5bfbdbdecf85e 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
static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) { | |
unsigned s1 = adler & 0xffff; | |
unsigned s2 = (adler >> 16) & 0xffff; | |
while(len > 0) { | |
/*at least 5550 sums can be done before the sums overflow, saving a lot of module divisions*/ | |
unsigned amount = len > 5550 ? 5550 : len; | |
len -= amount; | |
while(amount > 0) { | |
s1 += (*data++); | |
s2 += s1; | |
--amount; | |
} | |
s1 %= 65521; | |
s2 %= 65521; | |
} | |
return (s2 << 16) | s1; | |
} |
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
fn update_adler32(adler: u32, data: &[u8]) -> u32 { | |
let mut s1 = adler & 0xffff; | |
let mut s2 = (adler >> 16) & 0xffff; | |
/*at least 5550 sums can be done before the sums overflow, saving a lot of module divisions*/ | |
for chunk in data.chunks(5550) { | |
for b in chunk { | |
s1 += *b as u32; | |
s2 += s1; | |
} | |
s1 %= 65521; | |
s2 %= 65521; | |
} | |
return (s2 << 16) | s1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment