use murmurhash instead of sha1 for deltification blocks; suggested by ori
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
diff --git a/lib/deltify.c b/lib/deltify.c
index 0285cfc..f2d7dcd 100644
--- a/lib/deltify.c
+++ b/lib/deltify.c
@@ -26,11 +26,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sha1.h>
#include "got_error.h"
#include "got_lib_deltify.h"
+#include "murmurhash2.h"
#ifndef MIN
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
@@ -87,17 +87,10 @@ static uint32_t geartab[256] = {
0xf1f6e72c, 0x5551128a, 0x83af87e2, 0x6f0342ba,
};
-static uint64_t
+static uint32_t
hashblk(const unsigned char *p, off_t n)
{
- unsigned char buf[SHA1_DIGEST_LENGTH];
- uint64_t h;
- SHA1_CTX ctx;
- SHA1Init(&ctx);
- SHA1Update(&ctx, p, n);
- SHA1Final(buf, &ctx);
- memcpy(&h, buf, sizeof(h));
- return be64toh(h);
+ return murmurhash2(p, n, 0x1d7c5ac3);
}
static const struct got_error *
@@ -247,7 +240,7 @@ lookupblk(struct got_delta_block **block, struct got_delta_table *dt,
unsigned char *p, off_t len, FILE *basefile, off_t basefile_offset0)
{
int i;
- uint64_t h;
+ uint32_t h;
uint8_t buf[GOT_DELTIFY_MAXCHUNK];
size_t r;
@@ -278,7 +271,7 @@ lookupblk_mem(struct got_delta_block **block, struct got_delta_table *dt,
unsigned char *p, off_t len, uint8_t *basedata, off_t basefile_offset0)
{
int i;
- uint64_t h;
+ uint32_t h;
uint8_t *b;
*block = NULL;
@@ -360,7 +353,7 @@ got_deltify_init(struct got_delta_table **dt, FILE *f, off_t fileoffset,
off_t filesize)
{
const struct got_error *err = NULL;
- uint64_t h;
+ uint32_t h;
const off_t offset0 = fileoffset;
*dt = calloc(1, sizeof(**dt));
diff --git a/regress/deltify/Makefile b/regress/deltify/Makefile
index b903bbe..3685d58 100644
--- a/regress/deltify/Makefile
+++ b/regress/deltify/Makefile
@@ -1,7 +1,7 @@
.PATH:${.CURDIR}/../../lib
PROG = deltify_test
-SRCS = deltify.c error.c opentemp.c sha1.c deltify_test.c
+SRCS = deltify.c error.c opentemp.c sha1.c deltify_test.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lz