| 776 | } |
| 777 | |
| 778 | void finalize() |
| 779 | { |
| 780 | if (params.num_buckets_cutoff) |
| 781 | { |
| 782 | for (auto & elem : table) |
| 783 | { |
| 784 | Histogram & histogram = elem.getMapped(); |
| 785 | |
| 786 | if (histogram.buckets.size() < params.num_buckets_cutoff) |
| 787 | { |
| 788 | histogram.buckets.clear(); |
| 789 | histogram.total = 0; |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | if (params.frequency_cutoff) |
| 795 | { |
| 796 | for (auto & elem : table) |
| 797 | { |
| 798 | Histogram & histogram = elem.getMapped(); |
| 799 | if (!histogram.total) |
| 800 | continue; |
| 801 | |
| 802 | if (histogram.total + histogram.count_end < params.frequency_cutoff) |
| 803 | { |
| 804 | histogram.buckets.clear(); |
| 805 | histogram.total = 0; |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | Histogram::Buckets new_buckets; |
| 810 | UInt64 erased_count = 0; |
| 811 | |
| 812 | for (const auto & bucket : histogram.buckets) |
| 813 | { |
| 814 | if (bucket.second >= params.frequency_cutoff) |
| 815 | new_buckets.emplace(bucket); |
| 816 | else |
| 817 | erased_count += bucket.second; |
| 818 | } |
| 819 | |
| 820 | histogram.buckets.swap(new_buckets); |
| 821 | histogram.total -= erased_count; |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | if (params.frequency_add) |
| 827 | { |
| 828 | for (auto & elem : table) |
| 829 | { |
| 830 | Histogram & histogram = elem.getMapped(); |
| 831 | if (!histogram.total) |
| 832 | continue; |
| 833 | |
| 834 | for (auto & bucket : histogram.buckets) |
| 835 | bucket.second += params.frequency_add; |