MCPcopy Create free account
hub / github.com/apache/impala / MakeRandomSequence

Function MakeRandomSequence

be/src/util/encoding-test-util.h:28–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26/// that can be represented on 'bit_width' size bits.
27template<typename RandomEngine>
28std::vector<int> MakeRandomSequence(RandomEngine& random_eng, int total_length,
29 int max_run_length, int bit_width) {
30 auto NextRunLength = [&]() {
31 std::uniform_int_distribution<int> uni_dist(1, max_run_length);
32 return uni_dist(random_eng);
33 };
34 auto IsNextRunRepeated = [&random_eng]() {
35 std::uniform_int_distribution<int> uni_dist(0, 1);
36 return uni_dist(random_eng) == 0;
37 };
38 auto NextVal = [bit_width](int val) {
39 if (bit_width == CHAR_BIT * sizeof(int)) return val + 1;
40 return (val + 1) % (1 << bit_width);
41 };
42
43 std::vector<int> ret;
44 int run_length = 0;
45 int val = 0;
46 int is_repeated = false;
47 while (ret.size() < total_length) {
48 if (run_length == 0) {
49 run_length = NextRunLength();
50 is_repeated = IsNextRunRepeated();
51 val = NextVal(val);
52 }
53 ret.push_back(val);
54 if (!is_repeated) val = NextVal(val);
55 --run_length;
56 }
57 return ret;
58}
59
60}

Callers 2

TEST_FFunction · 0.85
TESTFunction · 0.85

Calls 2

push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected