NCBI C++ ToolKit
gena.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2 Copyright(c) 2019 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 
16 For more information please visit: http://bitmagic.io
17 */
18 
19 
20 
21 /// generate certain simple benchmark values
22 ///
23 template<typename VT>
24 void generate_vect_simpl0(VT& vect)
25 {
26 
27  VT v_tmp {0, 10, 31, 32, 62, 63,
28  (5 * bm::bits_in_array), (5 * bm::bits_in_array)+1,
30  bm::id_max48/2 + 10, bm::id_max48/2 + 16,
31  bm::id_max48-1
32  };
33 
34  std::swap(vect, v_tmp);
35 }
36 
37 /// sub-range vector generator
38 ///
39 /// @internal
40 template<typename VT, typename DISTR, typename MT_RAND>
41 void generate_vect48_range(VT& vect, unsigned long long range_base,
42  DISTR& dist, MT_RAND& mt_rand)
43 {
44  for (unsigned i = 0; i < 256; ++i)
45  {
46  bm::id64_t sub_base = range_base + (i * 65536);
47  if (i & 1) // alternate block patterns
48  {
49  for (unsigned j = 0; j < 65536/3; ++j)
50  {
51  bm::id64_t idx = (bm::id64_t)dist(mt_rand);
52  vect.push_back(sub_base + idx);
53  }
54  }
55  else
56  {
57  for (unsigned j = 0; j < 65536;)
58  {
59  unsigned to = j + ((unsigned)rand() % 256);
60  for (unsigned k = j; k < to && k < 65536; ++k, ++j)
61  vect.push_back(sub_base + k);
62  }
63  }
64  } // for
65 }
66 
67 /// generate test random vector in 48-bit range
68 ///
69 template<typename VT>
70 void generate_vect48(VT& vect)
71 {
72  std::random_device rd;
73  std::mt19937_64 mt_rand(rd());
74  std::uniform_int_distribution<int> dist(0, 65535);
75 
76 
77  // Range 0
78  //
79  bm::id64_t range_base = (bm::id64_t)dist(mt_rand);
80  generate_vect48_range(vect, range_base, dist, mt_rand);
81 
82  // Range 32-bit max
83  range_base = bm::id_max32-65536;
84  generate_vect48_range(vect, range_base, dist, mt_rand);
85 
86  // Range 48-bit / 2
87  range_base = bm::id_max48 / 2;
88  generate_vect48_range(vect, range_base, dist, mt_rand);
89 
90 // skip this range to save memory for some builds
91 #if defined(BMAVX2OPT)
92  // Range near 48-bit
93  range_base = bm::id_max48 - (65536 * 257);
94  generate_vect48_range(vect, range_base, dist, mt_rand);
95 #endif
96 
97  std::sort(vect.begin(), vect.end());
98  vect.erase(std::unique(vect.begin(), vect.end() ), vect.end());
99 }
100 
101 
102 
103 // generate pseudo-random bit-vector, mix of blocks
104 //
105 template<typename BV>
106 void generate_bvector(BV& bv, typename BV::size_type vector_max, bool optimize)
107 {
108  typename BV::size_type i, j;
109  for (i = 0; i < vector_max;)
110  {
111  // generate bit-blocks
112  for (j = 0; j < 65535*8; i += 10, j++)
113  {
114  bv.set(i);
115  }
116  if (i > vector_max)
117  break;
118  // generate GAP (compressed) blocks
119  for (j = 0; j < 65535; i += 120, j++)
120  {
121  unsigned len = (unsigned)rand() % 64;
122  bv.set_range(i, i + len);
123  bool all_one_range = bv.is_all_one_range(i, i + len);
124  assert(all_one_range);
125  i += len;
126  if (i > vector_max)
127  break;
128  }
129  }
130  if (optimize)
131  bv.optimize();
132 }
133 
134 template<typename VT, typename SIZE_TYPE>
136  VT &v2,
137  VT &v3,
138  SIZE_TYPE from,
139  SIZE_TYPE to)
140 {
141  SIZE_TYPE j;
142  for (j = from; j < to; j += 2)
143  v1.push_back(j);
144  for (j = from; j < to; j += 5)
145  v2.push_back(j);
146  for (j = from; j < to; j += 120)
147  v3.push_back(j);
148 }
149 
150 
151 template<typename BV>
152 void SimpleGapFillSets(BV& bv0,
153  BV& bv1,
154  typename BV::size_type min,
155  typename BV::size_type max,
156  unsigned fill_factor)
157 {
158  typename BV::bulk_insert_iterator bii1(bv1);
159  for (typename BV::size_type i = min; i < max; i += fill_factor)
160  {
161  bv0.set(i);
162  bii1 = i;
163  } // for i
164 }
165 
166 //
167 // Interval filling.
168 // 111........111111........111111..........11111111.......1111111...
169 //
170 
171 template<typename BVMINI, typename BV, typename SZT>
172 void FillSetsIntervals(BVMINI* bvect_min,
173  BV& bvect_full,
174  SZT min,
175  SZT max,
176  SZT fill_factor,
177  bool set_flag = true)
178 {
179  std::random_device rd;
180  std::mt19937_64 mt_rand(rd());
181 
182  while (fill_factor == 0)
183  {
184  fill_factor = (unsigned)rand() % 10;
185  }
186  bvect_full.init();
187 
188  cout << "Intervals filling. Factor="
189  << fill_factor << endl << endl;
190 
191  SZT i, j;
192  SZT factor = 70 * fill_factor;
193  std::uniform_int_distribution<unsigned> dist_f(1, unsigned(factor));
194  std::uniform_int_distribution<unsigned> dist_f10(1, unsigned(factor) * 10);
195  std::uniform_int_distribution<unsigned> dist_f10_max(1, unsigned(factor) * 10 * bm::gap_max_bits);
196 
197  for (i = min; i < max; ++i)
198  {
199  unsigned len;
200  SZT end;
201 
202  do
203  {
204  len = dist_f(mt_rand);//unsigned(rand() % factor);
205  end = i + len;
206 
207  } while (end >= max);
208  if (i < end)
209  {
210  bvect_full.set_range(i, end - 1, set_flag);
211  bool all_one_range = bvect_full.is_all_one_range(i, end - 1);
212  assert(all_one_range == set_flag);
213  }
214 
215  for (j = i; j < end; ++j)
216  {
217  if (set_flag)
218  {
219  if (bvect_min)
220  bvect_min->set_bit(j);
221  }
222  else
223  {
224  if (bvect_min)
225  bvect_min->clear_bit(j);
226  }
227  } // j
228  i = end;
229  len = dist_f10_max(mt_rand);//unsigned(rand() % (factor * 10 * bm::gap_max_bits));
230  if (len % 2)
231  {
232  len *= dist_f10(mt_rand);//unsigned(rand() % (factor * 10));
233  }
234 
235  i += len;
236  if ((len % 6) == 0)
237  {
238  for (unsigned k = 0; k < 1000 && i < max; k += 3, i += 3)
239  {
240  if (set_flag)
241  {
242  if (bvect_min)
243  bvect_min->set_bit(i);
244  bvect_full.set_bit_no_check(i);
245  }
246  else
247  {
248  if (bvect_min)
249  bvect_min->clear_bit(j);
250  bvect_full.clear_bit(j);
251  }
252  }
253  }
254  } // for i
255 }
256 
257 template<typename BV, typename SZT>
259  BV& bvect_full,
260  SZT min,
261  SZT max,
262  SZT fill_factor,
263  bool set_flag = true)
264 {
265  std::random_device rd;
266  std::mt19937_64 mt_rand(rd());
267 
268  std::uniform_int_distribution<unsigned> dist10(1, 10);
269 
270  while (fill_factor == 0)
271  {
272  fill_factor = dist10(mt_rand);
273  }
274  bvect_full.init();
275 
276  cout << "Intervals filling. Factor="
277  << fill_factor << endl << endl;
278 
279  SZT i;
280  SZT factor = 70 * fill_factor;
281 
282  std::uniform_int_distribution<unsigned> dist_f(1, unsigned(factor));
283  std::uniform_int_distribution<unsigned> dist_f10(1, unsigned(factor) * 10);
284  std::uniform_int_distribution<unsigned> dist_f10_max(1, unsigned(factor) * 10 * bm::gap_max_bits);
285 
286  for (i = min; i < max; ++i)
287  {
288  unsigned len;
289  SZT end;
290 
291  do
292  {
293  len = dist_f(mt_rand); //unsigned(rand() % factor);
294  end = i + len;
295 
296  } while (end >= max);
297  if (i < end)
298  {
299  bvect_full.set_range(i, end - 1, set_flag);
300  bool all_one_range = bvect_full.is_all_one_range(i, end - 1);
301  assert(all_one_range == set_flag);
302  }
303 
304  i = end;
305 
306  len = dist_f10_max(mt_rand);//unsigned(rand() % (factor * 10 * bm::gap_max_bits));
307  if (len % 2)
308  {
309  len *= dist_f10(mt_rand);//unsigned(rand() % (factor * 10));
310  }
311 
312  i += len;
313 
314  if ((len % 6) == 0)
315  {
316  for (unsigned k = 0; k < 1000 && i < max; k += 3, i += 3)
317  {
318  if (set_flag)
319  {
320  bvect_full.set_bit_no_check(i);
321  }
322  else
323  {
324  bvect_full.clear_bit(i);
325  }
326  }
327  }
328  } // for i
329 }
330 
331 
332 template<typename SZT>
333 SZT random_minmax(SZT min, SZT max)
334 {
335  SZT r = (unsigned(rand()) << 16u) | unsigned(rand());
336  if (bm::conditional<sizeof(SZT) == 8>::test())
337  {
338  SZT r2 = (unsigned(rand()) << 16u) | unsigned(rand());
339  r |= (r2 << 32);
340  }
341  return r % (max - min) + min;
342 }
343 
344 template <typename BVMINI, typename BV, typename SZT>
345 void FillSets(BVMINI* bvect_min,
346  BV* bvect_full,
347  SZT min,
348  SZT max,
349  SZT fill_factor)
350 {
351  SZT i;
352  SZT id;
353 
354  //Random filling
355  if (fill_factor == 0)
356  {
357  SZT n_id = (max - min) / 1000;
358  cout << "random filling : " << n_id << endl;
359  for (i = 0; i < n_id; i++)
360  {
361  id = random_minmax(min, max);
362  bvect_min->set_bit(id);
363  bvect_full->set_bit(id);
364  }
365  cout << endl;
366  }
367  else
368  {
369  cout << "fill_factor random filling : factor = "
370  << fill_factor << std::endl;
371 
372  for (i = 0; i < fill_factor; i++)
373  {
374  unsigned k = unsigned(rand()) % 10;
375  if (k == 0)
376  k += 2;
377 
378  //Calculate start
379  SZT start = min + (max - min) / (fill_factor * k);
380 
381  //Randomize start
382  start += random_minmax(1ULL, (max - min) / (fill_factor * 10));
383 
384  if (start > max)
385  {
386  start = min;
387  }
388 
389  //Calculate end
390  SZT end = start + (max - start) / (fill_factor * 2);
391 
392  //Randomize end
393  end -= random_minmax(1ULL, (max - start) / (fill_factor * 10));
394 
395  if (end > max)
396  {
397  end = max;
398  }
399 
400  typename BV::bulk_insert_iterator iit = bvect_full->inserter();
401  if (fill_factor > 1)
402  {
403  for (; start < end;)
404  {
405  unsigned r = unsigned(rand()) % 8;
406 
407  if (r > 7)
408  {
409  unsigned inc = unsigned(rand()) % 3;
410  ++inc;
411  SZT end2 = start + (unsigned)rand() % 1000;
412  if (end2 > end)
413  end2 = end;
414  while (start < end2)
415  {
416  bvect_min->set_bit(start);
417  iit = start;
418  start += inc;
419  }
420  continue;
421  }
422 
423  if (r)
424  {
425  bvect_min->set_bit(start);
426  iit = start;
427  ++start;
428  }
429  else
430  {
431  start += r;
432  bvect_min->set_bit(start);
433  iit = start;
434  }
435  }
436  }
437  else
438  {
439  unsigned c = unsigned(rand()) % 15;
440  if (c == 0)
441  ++c;
442  for (; start < end; ++start)
443  {
444  bvect_min->set_bit(start);
445  iit = start;
446  if (start % c)
447  {
448  start += c;
449  }
450  }
451  }
452  cout << endl;
453  }
454  }
455 }
456 
457 template <typename BVMINI, typename BV, typename SZT>
458 void FillSetClearIntervals(BVMINI* bvect_min,
459  BV* bvect_full,
460  SZT min,
461  SZT max,
462  SZT fill_factor)
463 {
464  FillSetsIntervals(bvect_min, *bvect_full, min, max, fill_factor, true);
465  FillSetsIntervals(bvect_min, *bvect_full, min, max, fill_factor, false);
466 }
467 
468 template <typename BVMINI, typename BV, typename SZT>
469 void FillSetsRandomOne(BVMINI* bvect_min,
470  BV* bvect_full,
471  SZT min,
472  SZT max)
473 {
474  SZT range = max - min;
475  SZT bit_idx = SZT(rand()) % range;
476  bvect_min->set_bit(bit_idx);
477  bvect_full->set_bit(bit_idx);
478  cout << "Bit_idx=" << bit_idx << endl;
479 }
480 
481 template <typename BVMINI, typename BV, typename SZT>
482 void FillSetsRandom(BVMINI* bvect_min,
483  BV* bvect_full,
484  SZT min,
485  SZT max,
486  SZT fill_factor)
487 {
488  bvect_full->init();
489  SZT diap = max - min;
490  SZT count;
491 
492  switch (fill_factor)
493  {
494  case 0:
495  count = diap / 1000;
496  break;
497  case 1:
498  count = diap / 100;
499  break;
500  default:
501  count = diap / 10;
502  break;
503 
504  }
505 
506  for (unsigned i = 0; i < count; ++i)
507  {
508  SZT bn = SZT(rand()) % count;
509  bn += min;
510  if (bn > max)
511  {
512  bn = max;
513  }
514  bvect_min->set_bit(bn);
515  bvect_full->set_bit_no_check(bn);
516  }
517  cout << "Ok" << endl;
518 
519 }
520 
521 template <typename BVMINI, typename BV, typename SZT>
522 void FillSetsRegular(BVMINI* bvect_min,
523  BV* bvect_full,
524  SZT /*min*/,
525  SZT max,
526  SZT /*fill_factor*/)
527 {
528  typename BV::bulk_insert_iterator iit = bvect_full->inserter();
529  SZT step = (unsigned)rand() % 4;
530  if (step < 2) ++step;
531  for (SZT i = 0; i < max; i+=step)
532  {
533  bvect_min->set_bit(i);
534  iit = i;
535  }
536  cout << "Ok" << endl;
537 }
538 /*
539 template<typename BVMINI, typename BV, typename VECT>
540 void FillSetsVect(BVMINI* bv_min, BV* bv, const VECT& vect)
541 {
542  for (auto it = vect.begin(); it != vect.end(); ++it)
543  {
544  auto v = *it;
545  bv->set(v);
546  }
547 }
548 */
549 //
550 // Quasi random filling with choosing randomizing method.
551 //
552 //
553 template <typename BVMINI, typename BV, typename SZT>
554 int FillSetsRandomMethod(BVMINI* bvect_min,
555  BV* bvect_full,
556  SZT min,
557  SZT max,
558  int optimize = 0,
559  int method = -1)
560 {
561  if (method == -1)
562  {
563  method = rand() % 7;
564  }
565  SZT factor;
566 //method = 0;
567  switch (method)
568  {
569 
570  case 0:
571  cout << "Random filling: method - FillSets - factor(0)" << endl;
572  FillSets(bvect_min, bvect_full, min, max, 0ull);
573  break;
574 
575  case 1:
576  cout << "Random filling: method - FillSets - factor(random)" << endl;
577  factor = (unsigned)rand()%3;
578  FillSets(bvect_min, bvect_full, min, max, factor?factor:1);
579  break;
580 
581  case 2:
582  cout << "Random filling: method - Set-Clear Intervals - factor(random)" << endl;
583  factor = (unsigned)rand()%10;
584  FillSetClearIntervals(bvect_min, bvect_full, min, max, factor);
585  break;
586  case 3:
587  cout << "Random filling: method - FillRandom - factor(random)" << endl;
588  factor = (unsigned)rand()%3;
589  FillSetsRandom(bvect_min, bvect_full, min, max, factor?factor:1);
590  break;
591  case 4:
592  cout << "Random set one bit" << endl;
593  FillSetsRandomOne(bvect_min, bvect_full, min, max);
594  break;
595  case 5:
596  cout << "Regular pattern filling" << endl;
597  FillSetsRegular(bvect_min, bvect_full, min, max, 2ull);
598  break;
599 /*
600  case 6:
601  {
602  cout << "Simple 48-bit wide vector" << endl;
603  std::vector<typename BV::size_type> vect0;
604  generate_vect_simpl0(vect0);
605  FillSetsVect(bvect_min, bvect_full, vect0);
606  }
607  break;
608  case 7:
609  {
610  cout << "Complex 48-bit wide vector" << endl;
611  std::vector<typename BV::size_type> vect0;
612  generate_vect48(vect0);
613  FillSetsVect(bvect_min, bvect_full, vect0);
614  }
615  break;
616 */
617  default:
618  cout << "Random filling: method - Set Intervals - factor(random)" << endl;
619  factor = (unsigned)rand()%10;
620  FillSetsIntervals(bvect_min, *bvect_full, min, max, factor);
621  break;
622 
623  } // switch
624 
625  if (optimize)
626  {
627  cout << "Vector optimization..." << flush;
629  bvect_full->optimize(tb);
630  cout << "OK" << endl;
631  }
632  return method;
633 }
634 
635 
636 
637 template<typename BV>
639  typename BV::size_type min,
640  typename BV::size_type max = 40000000,
641  unsigned fill_factor = 65536)
642 {
643  typename BV::bulk_insert_iterator iit(bv);
644  unsigned ff = fill_factor / 10;
645  for (typename BV::size_type i = min; i < max; i+= ff)
646  {
647  iit = i;
648  ff += ff / 2;
649  if (ff > fill_factor)
650  ff = fill_factor / 10;
651  }
652  iit.flush();
653 }
654 
655 
656 template<typename VECT>
657 void GenerateShiftTestCollection(VECT* target,
658  unsigned count,
659  unsigned long long vector_max,
660  bool optimize)
661 {
662  assert(target);
663  typename VECT::value_type bv_common; // sub-vector common for all collection
664  generate_sparse_bvector(bv_common, vector_max/10, vector_max, 250000);
665 
666  unsigned cnt1 = (count / 2);
667  unsigned i = 0;
668 
669  for (i = 0; i < cnt1; ++i)
670  {
671  std::unique_ptr<typename VECT::value_type> bv (new typename VECT::value_type);
672  generate_bvector(*bv, vector_max, optimize);
673  *bv |= bv_common;
674  if (optimize)
675  bv->optimize();
676  target->push_back(std::move(*bv));
677  } // for
678 
679  unsigned long long fill_factor = 10;
680  for (; i < count; ++i)
681  {
682  std::unique_ptr<typename VECT::value_type> bv (new typename VECT::value_type);
683  FillSetsIntervals(*bv, vector_max/ 10, vector_max, fill_factor);
684  *bv |= bv_common;
685 
686  target->push_back(std::move(*bv));
687  } // for
688 }
689 
690 
691 template<typename SV>
692 void GenerateSV(SV& sv, unsigned strategy = 0)
693 {
694  using value_type = typename SV::value_type;
695 
696  unsigned max_idx_value = 1000000;
697  switch (strategy)
698  {
699  case 0:
700  {
701  cout << "SV Ultra sparse generation" << endl;
702  for (unsigned i = 0; i < max_idx_value;)
703  {
704  value_type v = (unsigned)(rand() * rand()) % 650000;
706  {
707  sv[i] = v;
708  }
709  else
710  {
711  if (v & 1)
712  sv[i] = - v;
713  else
714  sv[i] = v;
715  }
716  i += 10000 + (unsigned)rand() % 65535;
717  }
718  break;
719  }
720  case 1:
721  {
722  cout << "SV Dense intervals generation 1" << endl;
723  for (unsigned i = 0; i < max_idx_value;)
724  {
725  value_type v = (unsigned)(rand() * rand()) % 650000;
726  for (unsigned j = 0; i < max_idx_value; ++i, ++j)
727  {
729  {
730  sv[i] = v + j;
731  }
732  else
733  {
734  sv[i] = int(j)-v;
735  }
736  if (j > 256)
737  break;
738  }
739  i += 20000 + (unsigned)rand() % 65535;
740  }
741  break;
742  }
743  case 2:
744  {
745  cout << "SV Dense intervals generation 2" << endl;
746  value_type v = (unsigned)(rand() * rand()) % 650000;
747  for (unsigned i = 0; i < max_idx_value/4; ++i)
748  {
749  sv[i] = v;
750  }
751 
752  for (unsigned i = 0; i < max_idx_value;)
753  {
754  v = unsigned(rand() * rand()) % 650000;
755  for (unsigned j = 0; i < max_idx_value; ++i, ++j)
756  {
758  sv[i] = v + i;
759  else
760  sv[i] = - int(unsigned(v) + i);
761  if (j > 256)
762  break;
763  }
764  i += 30000 + unsigned(rand()) % 65535;
765  }
766  break;
767  }
768  case 3:
769  {
770  cout << "SV random generation" << endl;
771  unsigned rand_max = (unsigned)rand() % 300000;
772  for (unsigned i = 0; i < rand_max; ++i)
773  {
774  value_type v = value_type(rand() * rand());
775  unsigned idx = unsigned(rand()) % max_idx_value;
777  sv[idx] = v;
778  else
779  sv[idx] = -v;
780 
781  if (i % 2 == 0)
782  {
783  sv.clear(idx, true);
784  }
785  }
786  break;
787  }
788  case 4:
789  {
790  cout << "SV empty generation" << endl;
791  unsigned idx = unsigned(rand()) % max_idx_value;
792  sv[idx] = 25557890;
793  sv.clear(idx, true);
794  }
795  break;
796  case 5:
797  {
798  cout << "SV uniform power 2 value generation" << endl;
799  value_type v = 8;//unsigned(rand()) % 64;
800  for (unsigned i = 0; i < max_idx_value; ++i)
801  {
802  sv[i] = 0-v;
803  }
804  }
805  break;
806  case 6:
807  {
808  cout << "SV uniform power 2+1 value generation" << endl;
809  value_type v = 16+1;
810  for (unsigned i = 0; i < max_idx_value; ++i)
811  {
813  sv[i] = v;
814  else
815  sv[i] = 0-v;
816 
817  }
818  }
819  break;
820  case 7:
821  {
822  cout << "SV linear growth/decline value generation" << endl;
823  for (unsigned i = 0; i < max_idx_value; ++i)
824  {
826  sv[i] = i;
827  else
828  sv[i] = -int(i);
829  }
830  }
831  break;
832  default:
833  break;
834  } // switch
835  sv.optimize();
836 }
837 
838 
839 // fill pseudo-random plato pattern into two vectors
840 //
841 template<class SV>
842 void FillSparseIntervals(std::vector<unsigned>& vect,
843  SV& svect,
844  typename SV::size_type min,
845  typename SV::size_type max,
846  unsigned fill_factor)
847 {
848  typename SV::size_type diap = max - min;
849  typename SV::size_type count;
850 
851  switch (fill_factor)
852  {
853  case 0:
854  count = diap / 1000;
855  break;
856  case 1:
857  count = diap / 100;
858  break;
859  default:
860  count = diap / 10;
861  break;
862 
863  }
864 
865  if (vect.size() < max)
866  vect.resize(max + 1);
867  if (svect.size() < max)
868  svect.resize(max + 1);
869 
870  unsigned val = 0;
871  for ( ;min < max; )
872  {
873  // hi-band interval
874  val = (unsigned)rand() % (65535 * 2);
875  unsigned i;
876  for (i = 0; i < count; ++i)
877  {
878  vect[min] = val;
879  svect.set(min, val);
880  ++min;
881  if (min > max)
882  break;
883  } // for i
884 
885  // gap with all zeroes
886  unsigned inc = (unsigned)rand() % 2048;
887  min += inc;
888  if (min > max)
889  break;
890 
891  // low band plato
892  val = (unsigned)rand() % 8;
893  for (i = 0; i < count; ++i)
894  {
895  vect[min] = val;
896  svect.set(min, val);
897  ++min;
898  if (min > max)
899  break;
900  } // for i
901 
902  } // for min
903 }
904 
905 template<typename SSV>
906 void GenerateTestStrCollection(SSV& str_coll, typename SSV::size_type max_coll)
907 {
908  string prefix = "az";
909  string str;
910  for (unsigned i = 0; i < max_coll; ++i)
911  {
912  str = prefix;
913  str.append(to_string(i));
914  str_coll.emplace_back(str);
915  // generate new prefix
916  {
917  prefix.clear();
918  unsigned prefix_len = (unsigned)rand() % 5;
919  for (unsigned j = 0; j < prefix_len; ++j)
920  {
921  char cch = char('a' + (unsigned)rand() % 26);
922  prefix.push_back(cch);
923  } // for j
924  }
925  } // for i
926 }
927 
928 
929 
930 template<typename CBCBuf>
931 void FillTestBuffer(CBCBuf& buf)
932 {
933  unsigned sz_factor = (unsigned)rand() % 10;
934  if (!sz_factor)
935  sz_factor = 1;
936  unsigned size = 65000 + (128000 / sz_factor);
937  buf.resize(size);
938  unsigned char* data = buf.data();
939  for (unsigned i = 0; i < size; ++i)
940  {
941  data[i] = (unsigned char)i;
942  }
943 }
944 
945 template<typename CBC>
947 {
948  unsigned sz = (unsigned)rand() % 10000;
949  unsigned key = 0;
950  unsigned key_factor = (unsigned)rand() % 128;
951  if (!key_factor)
952  key_factor = 1;
953  for (unsigned i = 0; i < sz; ++i)
954  {
955  {
956  typename CBC::buffer_type buf;
958  cbc.move_buffer(key, buf);
959  }
960  key += key_factor;
961  } // for
962  cbc.sync();
963 }
964 
965 
966 template<typename SV>
968  typename SV::size_type vector_max)
969 {
970  typename SV::back_insert_iterator bi(sv.get_back_inserter());
971 
972  unsigned v = 0;
973  for (typename SV::size_type i = 0; i < vector_max; ++i)
974  {
975  unsigned plato = (unsigned)rand() % 16;
976  for (unsigned j = 0; i < vector_max && j < plato; ++i, ++j)
977  {
978  *bi = v;
979  } // for j
980  if (++v > 100000)
981  v = 0;
982  unsigned nulls = (unsigned)rand() % 16;
983  if (nulls)
984  bi.add_null(nulls);
985  i += nulls;
986  } // for i
987 }
#define BM_DECLARE_TEMP_BLOCK(x)
Definition: bm.h:47
#define test(a, b, c, d, e)
Definition: numeric.c:170
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
void FillTestBuffer(CBCBuf &buf)
Definition: gena.h:931
void FillSetsIntervals(BVMINI *bvect_min, BV &bvect_full, SZT min, SZT max, SZT fill_factor, bool set_flag=true)
Definition: gena.h:172
void FillSetsRegular(BVMINI *bvect_min, BV *bvect_full, SZT, SZT max, SZT)
Definition: gena.h:522
void generate_vect48_range(VT &vect, unsigned long long range_base, DISTR &dist, MT_RAND &mt_rand)
sub-range vector generator
Definition: gena.h:41
int FillSetsRandomMethod(BVMINI *bvect_min, BV *bvect_full, SZT min, SZT max, int optimize=0, int method=-1)
Definition: gena.h:554
void GenerateShiftTestCollection(VECT *target, unsigned count, unsigned long long vector_max, bool optimize)
Definition: gena.h:657
void generate_bvector(BV &bv, typename BV::size_type vector_max, bool optimize)
Definition: gena.h:106
void generate_sparse_bvector(BV &bv, typename BV::size_type min, typename BV::size_type max=40000000, unsigned fill_factor=65536)
Definition: gena.h:638
void FillSetClearIntervals(BVMINI *bvect_min, BV *bvect_full, SZT min, SZT max, SZT fill_factor)
Definition: gena.h:458
void GenerateCompressedBufferCollection(CBC &cbc)
Definition: gena.h:946
void GenerateTestStrCollection(SSV &str_coll, typename SSV::size_type max_coll)
Definition: gena.h:906
void SimpleGapFillSets(BV &bv0, BV &bv1, typename BV::size_type min, typename BV::size_type max, unsigned fill_factor)
Definition: gena.h:152
void FillSetsRandom(BVMINI *bvect_min, BV *bvect_full, SZT min, SZT max, SZT fill_factor)
Definition: gena.h:482
void generate_vect_simpl0(VT &vect)
generate certain simple benchmark values
Definition: gena.h:24
void FillSparseIntervals(std::vector< unsigned > &vect, SV &svect, typename SV::size_type min, typename SV::size_type max, unsigned fill_factor)
Definition: gena.h:842
void FillSets(BVMINI *bvect_min, BV *bvect_full, SZT min, SZT max, SZT fill_factor)
Definition: gena.h:345
void generate_serialization_test_set(SV &sv, typename SV::size_type vector_max)
Definition: gena.h:967
void FillSetsRandomOne(BVMINI *bvect_min, BV *bvect_full, SZT min, SZT max)
Definition: gena.h:469
void generate_test_vectors(VT &v1, VT &v2, VT &v3, SIZE_TYPE from, SIZE_TYPE to)
Definition: gena.h:135
void GenerateSV(SV &sv, unsigned strategy=0)
Definition: gena.h:692
SZT random_minmax(SZT min, SZT max)
Definition: gena.h:333
void generate_vect48(VT &vect)
generate test random vector in 48-bit range
Definition: gena.h:70
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
const CVect2< U > & v2
Definition: globals.hpp:440
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
strategy
Block allocation strategies.
Definition: bmconst.h:146
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
char * buf
int i
int len
const unsigned id_max32
Definition: bmconst.h:50
const unsigned bits_in_array
Definition: bmconst.h:115
unsigned long long int id64_t
Definition: bmconst.h:35
const unsigned gap_max_bits
Definition: bmconst.h:81
range(_Ty, _Ty) -> range< _Ty >
constexpr auto sort(_Init &&init)
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T max(T x_, T y_)
T min(T x_, T y_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static const char * prefix[]
Definition: pcregrep.c:405
#define assert(x)
Definition: srv_diag.hpp:58
ad-hoc conditional expressions
Definition: bmutil.h:113
Modified on Tue Apr 16 20:08:37 2024 by modify_doxy.py rev. 669887