casacore
Loading...
Searching...
No Matches
BitPacking.h
Go to the documentation of this file.
1#ifndef CASACORE_TABLES_BITPACKING_H_
2#define CASACORE_TABLES_BITPACKING_H_
3
4#include <cstring>
5
6inline void PackBoolArray(unsigned char* packed_buffer, const bool* input, size_t n) {
7 const size_t limit = n / 8;
8 const bool* end = input + n;
9 for (size_t i = 0; i != limit; ++i) {
10 *packed_buffer = 0;
11 for (size_t b = 0; b != 8; ++b) {
12 *packed_buffer |= (*input) << b;
13 ++input;
14 }
15 ++packed_buffer;
16 }
17 size_t b = 0;
18 if (input != end) {
19 *packed_buffer = 0;
20 do {
21 *packed_buffer |= (*input) << b;
22 ++input;
23 ++b;
24 } while (input != end);
25 }
26}
27
28inline void UnpackBoolArray(bool* output, const unsigned char* packed_input, size_t n) {
29 bool* end = output + n;
30 const size_t limit = n / 8;
31 for (size_t i = 0; i != limit; i++) {
32 for (size_t b = 0; b != 8; ++b) {
33 *output = (*packed_input >> b) & 0x1;
34 ++output;
35 }
36 ++packed_input;
37 }
38 size_t b = 0;
39 while (output != end) {
40 *output = (*packed_input >> b) & 0x1;
41 ++output;
42 ++b;
43 }
44}
45
46#endif
void UnpackBoolArray(bool *output, const unsigned char *packed_input, size_t n)
Definition BitPacking.h:28
void PackBoolArray(unsigned char *packed_buffer, const bool *input, size_t n)
Definition BitPacking.h:6