aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2021-03-30 11:20:19 +0100
committerGitHub <noreply@github.com>2021-03-30 11:20:19 +0100
commit2c14accfd0c1018a26bc4943f8bdee50859d0409 (patch)
tree841b6c839f0162eeb011e93b1c60a2be8a3f63a3
parent439e2c92426c59f84d51bfb594e9ac86d496c708 (diff)
parentf4d0f74dbbe0cc1dca7a5c40fea8e3f683cf5b38 (diff)
Merge pull request #879 from Kelimion/partial_hash_updates
Allow seeding CRC32, CRC64 & Adler32 with previous partial hash.
-rw-r--r--core/hash/crc.odin8
-rw-r--r--core/hash/hash.odin4
2 files changed, 6 insertions, 6 deletions
diff --git a/core/hash/crc.odin b/core/hash/crc.odin
index 008310408..bb31669d0 100644
--- a/core/hash/crc.odin
+++ b/core/hash/crc.odin
@@ -1,14 +1,14 @@
package hash
-crc32 :: proc(data: []byte) -> u32 #no_bounds_check {
- result := ~u32(0);
+crc32 :: proc(data: []byte, seed := u32(0)) -> u32 #no_bounds_check {
+ result := ~u32(seed);
for b in data {
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
}
return ~result;
}
-crc64 :: proc(data: []byte) -> u64 #no_bounds_check {
- result := ~u64(0);
+crc64 :: proc(data: []byte, seed := u32(0)) -> u64 #no_bounds_check {
+ result := ~u64(seed);
for b in data {
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
}
diff --git a/core/hash/hash.odin b/core/hash/hash.odin
index 391fc09f7..5bd2f6e10 100644
--- a/core/hash/hash.odin
+++ b/core/hash/hash.odin
@@ -2,9 +2,9 @@ package hash
import "core:mem"
-adler32 :: proc(data: []byte) -> u32 {
+adler32 :: proc(data: []byte, seed := u32(1)) -> u32 {
ADLER_CONST :: 65521;
- a, b: u32 = 1, 0;
+ a, b: u32 = seed & 0xFFFF, seed >> 16;
for x in data {
a = (a + u32(x)) % ADLER_CONST;
b = (b + a) % ADLER_CONST;