| 513 | static double *zipf_table = nullptr; |
| 514 | |
| 515 | static void |
| 516 | build_zipf() |
| 517 | { |
| 518 | if (zipf_table) { |
| 519 | return; |
| 520 | } |
| 521 | zipf_table = static_cast<double *>(ats_malloc(ZIPF_SIZE * sizeof(double))); |
| 522 | for (int i = 0; i < ZIPF_SIZE; i++) { |
| 523 | zipf_table[i] = 1.0 / pow(i + 2, zipf_alpha); |
| 524 | } |
| 525 | for (int i = 1; i < ZIPF_SIZE; i++) { |
| 526 | zipf_table[i] = zipf_table[i - 1] + zipf_table[i]; |
| 527 | } |
| 528 | double x = zipf_table[ZIPF_SIZE - 1]; |
| 529 | for (int i = 0; i < ZIPF_SIZE; i++) { |
| 530 | zipf_table[i] = zipf_table[i] / x; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | static int |
| 535 | get_zipf(double v) |
no test coverage detected