-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitarr_io.h
47 lines (39 loc) · 1.28 KB
/
bitarr_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
41
42
43
44
45
46
47
/*
* File format is specified as follows
* The header is 9 bytes long
* - magic number: 3 char (3 byte)
* - l: 1 uint8 (1 byte)
* - width: 1 uint8 (1 byte)
* - n: 1 uint32 (4 byte)
*
* The magic number is specified as "BIT"
*
* The length (i) of the data array is computed by ceil((l*n)/32),
* where 32 is the size of a computer word. Thus the data is read
* as the next unsigned int * i bytes
*
* ┌─────────┬───┬───┬────────────┬─────────────────
* │ BIT │ l │ w │ n │ ...
* └─────────┴───┴───┴────────────┴─────────────────
*
*/
#ifndef BITARR_IO_H_
#define BITARR_IO_H_
#include <string.h>
#include "bitarr.h"
static const char BIT_MAGIC_NUMBER[] = { 'B', 'I', 'T', '\0'};
/**
* @brief Save BitArray to disk
*
* @param bitarr Pointer to bitarr
* @param fp Filepath to save to
*/
void BitArray_save(BitArray* bitarr, FILE *fp);
/**
* @brief Opens bitarr saved to disk
*
* @param fp Filepath to bitarr saved on disk
* @return
*/
BitArray* BitArray_open(FILE *fp);
#endif // BITARR_IO_H_