| 653 | |
| 654 | |
| 655 | void finalize() |
| 656 | { |
| 657 | if (params.num_buckets_cutoff) |
| 658 | { |
| 659 | for (auto & elem : table) |
| 660 | { |
| 661 | Histogram & histogram = elem.getMapped(); |
| 662 | |
| 663 | if (histogram.buckets.size() < params.num_buckets_cutoff) |
| 664 | { |
| 665 | histogram.buckets.clear(); |
| 666 | histogram.total = 0; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if (params.frequency_cutoff) |
| 672 | { |
| 673 | for (auto & elem : table) |
| 674 | { |
| 675 | Histogram & histogram = elem.getMapped(); |
| 676 | if (!histogram.total) |
| 677 | continue; |
| 678 | |
| 679 | if (histogram.total + histogram.count_end < params.frequency_cutoff) |
| 680 | { |
| 681 | histogram.buckets.clear(); |
| 682 | histogram.total = 0; |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | Histogram::Buckets new_buckets; |
| 687 | UInt64 erased_count = 0; |
| 688 | |
| 689 | for (const auto & bucket : histogram.buckets) |
| 690 | { |
| 691 | if (bucket.second >= params.frequency_cutoff) |
| 692 | new_buckets.emplace(bucket); |
| 693 | else |
| 694 | erased_count += bucket.second; |
| 695 | } |
| 696 | |
| 697 | histogram.buckets.swap(new_buckets); |
| 698 | histogram.total -= erased_count; |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | if (params.frequency_add) |
| 704 | { |
| 705 | for (auto & elem : table) |
| 706 | { |
| 707 | Histogram & histogram = elem.getMapped(); |
| 708 | if (!histogram.total) |
| 709 | continue; |
| 710 | |
| 711 | for (auto & bucket : histogram.buckets) |
| 712 | bucket.second += params.frequency_add; |