MCPcopy Create free account
hub / github.com/apache/arrow / prefixed_random_byte_array

Function prefixed_random_byte_array

cpp/src/parquet/test_util.cc:140–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140void prefixed_random_byte_array(int n, uint32_t seed, uint8_t* buf, ByteArray* out,
141 int min_size, int max_size, double prefixed_probability) {
142 std::default_random_engine gen(seed);
143 std::uniform_int_distribution<int> dist_size(min_size, max_size);
144 std::uniform_int_distribution<int> dist_byte(0, 255);
145 std::bernoulli_distribution dist_has_prefix(prefixed_probability);
146 std::uniform_real_distribution<double> dist_prefix_length(0, 1);
147
148 for (int i = 0; i < n; ++i) {
149 int len = dist_size(gen);
150 out[i].len = len;
151 out[i].ptr = buf;
152
153 bool do_prefix = dist_has_prefix(gen) && i > 0;
154 int prefix_len = 0;
155 if (do_prefix) {
156 int max_prefix_len = std::min(len, static_cast<int>(out[i - 1].len));
157 prefix_len = static_cast<int>(std::ceil(max_prefix_len * dist_prefix_length(gen)));
158 }
159 for (int j = 0; j < prefix_len; ++j) {
160 buf[j] = out[i - 1].ptr[j];
161 }
162 for (int j = prefix_len; j < len; ++j) {
163 buf[j] = static_cast<uint8_t>(dist_byte(gen));
164 }
165 buf += len;
166 }
167}
168
169void prefixed_random_byte_array(int n, uint32_t seed, uint8_t* buf, int len, FLBA* out,
170 double prefixed_probability) {

Callers 2

GeneratePrefixedDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected