-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.c
54 lines (41 loc) · 1.11 KB
/
main.c
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
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
#include "rabin.h"
// 1MiB buffer
uint8_t buf[1024*1024];
size_t bytes;
int main(void) {
struct rabin_t *hash;
hash = rabin_init();
unsigned int chunks = 0;
while (!feof(stdin)) {
size_t len = fread(buf, 1, sizeof(buf), stdin);
uint8_t *ptr = &buf[0];
bytes += len;
while (1) {
int remaining = rabin_next_chunk(hash, ptr, len);
if (remaining < 0) {
break;
}
len -= remaining;
ptr += remaining;
printf("%d %016llx\n",
last_chunk.length,
(long long unsigned int)last_chunk.cut_fingerprint);
chunks++;
}
}
if (rabin_finalize(hash) != NULL) {
chunks++;
printf("%d %016llx\n",
last_chunk.length,
(long long unsigned int)last_chunk.cut_fingerprint);
}
unsigned int avg = 0;
if (chunks > 0)
avg = bytes / chunks;
printf("%d chunks, average chunk size %d\n", chunks, avg);
return 0;
}