This repository has been archived by the owner on Jun 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
coding_policy.c
65 lines (51 loc) · 2.24 KB
/
coding_policy.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
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include"pfordelta.h"
#include"coding_policy.h"
extern int block_size;
// The 'input' array size should be at least an upper multiple of 'block_size_'.
int compress_pfordelta(unsigned int *input, unsigned int *output, int num_input_elements, int block_size_) {
int num_whole_blocks = num_input_elements / block_size_;
int encoded_offset = 0;
int unencoded_offset = 0;
int left_to_encode;
int pad_until;
int i;
block_size = block_size_;
while (num_whole_blocks-- > 0) {
encoded_offset += pfor_compress(input + unencoded_offset, output + encoded_offset, block_size_);
unencoded_offset += block_size_;
}
left_to_encode = num_input_elements % block_size_;
if (left_to_encode != 0) {
// Encode leftover portion with a blockwise coder, and pad it to the blocksize.
// Assumption here is that the 'input' array size is at least an upper multiple of 'block_size_'.
pad_until = block_size_ * ((num_input_elements / block_size_) + 1);
for (i = num_input_elements; i < pad_until; ++i) {
input[i] = 0;
}
encoded_offset += pfor_compress(input + unencoded_offset, output + encoded_offset, block_size_);
unencoded_offset += block_size_;
}
return encoded_offset;
}
// The 'output' array size should be at least an upper multiple of 'block_size_'.
int decompress_pfordelta(unsigned int* input, unsigned int* output, int num_input_elements, int _block_size) {
int num_whole_blocks = num_input_elements / _block_size;
int encoded_offset = 0;
int unencoded_offset = 0;
int left_to_encode;
block_size = _block_size;
//printf("num_input_elements: %d\n", num_input_elements);
while (num_whole_blocks-- > 0) {
encoded_offset += pfor_decompress(input + encoded_offset, output + unencoded_offset, _block_size);
unencoded_offset += _block_size;
}
left_to_encode = num_input_elements % _block_size;
if (left_to_encode != 0) {
// Decode leftover portion with a blockwise coder, since it was padded to the blocksize.
// Assumption here is that the 'output' array size is at least an upper multiple of 'block_size_'.
encoded_offset += pfor_decompress(input + encoded_offset, output + unencoded_offset, _block_size);
unencoded_offset += _block_size;
}
return encoded_offset;
}