Repository navigation
Expand file tree
/
Copy pathunit.c
More file actions
60 lines (54 loc) · 1.71 KB
/
Copy pathunit.c
File metadata and controls
60 lines (54 loc) · 1.71 KB
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
#include <stdio.h>
#include <stdlib.h>
#include "fastdelta.h"
int main() {
int N = 4096;
uint32_t * datain = malloc(N * sizeof(uint32_t));
uint32_t * buffer = malloc(N * sizeof(uint32_t));
uint32_t * recovdata = malloc(N * sizeof(uint32_t));
for (int length = 0; length <= N;) {
printf("length = %d \n", length);
for (uint32_t gap = 1; gap <= 387420489; gap *= 3) {
for (int k = 0; k < length; ++k)
datain[k] = gap * (k+1);
compute_deltas(datain, length, buffer, 0);
for (int k = 0; k < length; ++k) {
if(buffer[k] != gap) {
printf("bug. buffer[%d]=%d expected %d \n",k,buffer[k],gap);
return -1;
}
}
compute_prefix_sum(buffer, length, recovdata, 0);
for(int k = 0; k < length; ++k) {
if(datain[k] != recovdata[k]) {
printf("bug.\n");
return -1;
}
}
compute_deltas_inplace(datain, length, 0);
for (int k = 0; k < length; ++k) {
if(datain[k] != gap) {
printf("bug.");
return -1;
}
}
compute_prefix_sum_inplace(datain, length, 0);
for(int k = 0; k < length; ++k) {
if(datain[k] != recovdata[k]) {
printf("bug.\n");
return -1;
}
}
}
if (length < 128)
++length;
else {
length *= 2;
}
}
free(datain);
free(buffer);
free(recovdata);
printf("Code looks good.\n");
return 0;
}