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,
7 size_t n) {
8 const size_t limit = n / 8;
9 const bool* end = input + n;
10 for (size_t i = 0; i != limit; ++i) {
11 *packed_buffer = 0;
12 for (size_t b = 0; b != 8; ++b) {
13 *packed_buffer |= (*input) << b;
14 ++input;
15 }
16 ++packed_buffer;
17 }
18 size_t b = 0;
19 if (input != end) {
20 *packed_buffer = 0;
21 do {
22 *packed_buffer |= (*input) << b;
23 ++input;
24 ++b;
25 } while (input != end);
26 }
27}
28
29inline void UnpackBoolArray(bool* output, const unsigned char* packed_input,
30 size_t n) {
31 bool* end = output + n;
32 const size_t limit = n / 8;
33 for (size_t i = 0; i != limit; i++) {
34 for (size_t b = 0; b != 8; ++b) {
35 *output = (*packed_input >> b) & 0x1;
36 ++output;
37 }
38 ++packed_input;
39 }
40 size_t b = 0;
41 while (output != end) {
42 *output = (*packed_input >> b) & 0x1;
43 ++output;
44 ++b;
45 }
46}
47
48#endif
void UnpackBoolArray(bool *output, const unsigned char *packed_input, size_t n)
Definition BitPacking.h:29
void PackBoolArray(unsigned char *packed_buffer, const bool *input, size_t n)
Definition BitPacking.h:6