-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathio.h
40 lines (30 loc) · 940 Bytes
/
io.h
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
word_t** load_pbm(FILE* file, size_t* n_elements) {
char header[2];
fread(header, 1, 2, file);
assert(header[0] == 'P' && header[1] == '4');
int dimension, n;
fscanf(file, "%d %d", &dimension, &n);
assert(dimension == BITS);
*n_elements = n;
word_t **hvs = (word_t **)malloc(n*sizeof(word_t *));
for (int i = 0; i < n; ++i) {
hvs[i] = empty();
fread(hvs[i], 1, BYTES, file);
}
return hvs;
}
void save_pbm(FILE* file, word_t** data, size_t n_elements) {
// white are off bits
fwrite("P4", 1, 2, file);
fprintf(file, "\n%d %zu\n", BITS, n_elements);
for (size_t i = 0; i < n_elements; ++i)
fwrite(data[i], 1, BYTES, file);
}
std::string to_string(uint64_t *x) {
char viz [DIMENSION + 1];
viz[DIMENSION] = '\0';
unpack_into(x, (bool*)viz);
for (size_t i = 0; i < DIMENSION; ++i)
viz[i] += '0';
return std::string(viz);
}