RLE encodes NUM_OUT_VALUES number of bytes into the buffer. The length of runs are pseudo random between 1 and max_run_length.
| 59 | /// RLE encodes NUM_OUT_VALUES number of bytes into the buffer. |
| 60 | /// The length of runs are pseudo random between 1 and max_run_length. |
| 61 | int FillWithRle(vector<uint8_t>* buffer, int bit_width, int max_run_length) { |
| 62 | RleEncoder encoder(buffer->data(), buffer->size(), bit_width); |
| 63 | |
| 64 | uniform_int_distribution<int> uniform_dist(1, max_run_length); |
| 65 | minstd_rand rand_engine; |
| 66 | uint8_t val = 0; |
| 67 | int run_length = 0; |
| 68 | for (int i = 0; i < NUM_OUT_VALUES; ++i) { |
| 69 | if (!encoder.Put(val)) { |
| 70 | LOG(ERROR) << Substitute( |
| 71 | "Error during RLE encoding. bit_widths: $0 max_run_length: $1", |
| 72 | bit_width, max_run_length); |
| 73 | } |
| 74 | if (run_length == 0) { |
| 75 | run_length = uniform_dist(rand_engine); |
| 76 | val = (val + 1) % (1 << bit_width); |
| 77 | } |
| 78 | --run_length; |
| 79 | } |
| 80 | return encoder.Flush(); |
| 81 | } |
| 82 | |
| 83 | struct BenchmarkParams { |
| 84 | int bit_width; |
no test coverage detected