| 1 | /* Copyright 2013 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | Distributed under MIT license. |
| 4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 | */ |
| 6 | |
| 7 | /* Functions for clustering similar histograms together. */ |
| 8 | |
| 9 | #include "cluster.h"cxx . . $ `<file>/c/enc/cluster.h`/ |
| 10 | |
| 11 | #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/ |
| 12 | #include "bit_cost.h"cxx . . $ `<file>/c/enc/bit_cost.h`/ /* BrotliPopulationCost */ |
| 13 | #include "fast_log.h"cxx . . $ `<file>/c/enc/fast_log.h`/ |
| 14 | #include "histogram.h"cxx . . $ `<file>/c/enc/histogram.h`/ |
| 15 | #include "memory.h"cxx . . $ `<file>/c/enc/memory.h`/ |
| 16 | |
| 17 | #if defined(__cplusplus) || defined(c_plusplus) |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! HistogramPairIsLesscxx . . $ HistogramPairIsLess(c97e898118c8f569).( |
| 22 | const HistogramPaircxx . . $ HistogramPair#* p1, const HistogramPaircxx . . $ HistogramPair#* p2) { |
| 23 | if (p1->cost_diffcxx . . $ HistogramPair#cost_diff. != p2->cost_diffcxx . . $ HistogramPair#cost_diff.) { |
| 24 | return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(p1->cost_diff > p2->cost_diff); |
| 25 | } |
| 26 | return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!((p1->idx2 - p1->idx1) > (p2->idx2 - p2->idx1)); |
| 27 | } |
| 28 | |
| 29 | /* Returns entropy reduction of the context map when we combine two clusters. */ |
| 30 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! double ClusterCostDiffcxx . . $ ClusterCostDiff(92fcfb2e12389ac6).(size_t size_a, size_t size_b) { |
| 31 | size_t size_c = size_a + size_b; |
| 32 | return (double)size_a * FastLog2cxx . . $ FastLog2(78051de35c49feff).(size_a) + |
| 33 | (double)size_b * FastLog2cxx . . $ FastLog2(78051de35c49feff).(size_b) - |
| 34 | (double)size_c * FastLog2cxx . . $ FastLog2(78051de35c49feff).(size_c); |
| 35 | } |
| 36 | |
| 37 | #define CODEcxx . . $ `c/enc/cluster.c:37:9`!(X) X |
| 38 | |
| 39 | #define FNcxx . . $ `c/enc/cluster.c:39:9`!(X) X ## Literal |
| 40 | #include "cluster_inc.h"cxx . . $ `<file>/c/enc/cluster_inc.h`/ /* NOLINT(build/include) */ |
| 41 | #undef FNcxx . . $ `c/enc/cluster.c:39:9`! |
| 42 | |
| 43 | #define FNcxx . . $ `c/enc/cluster.c:43:9`!(X) X ## Command |
| 44 | #include "cluster_inc.h"cxx . . $ `<file>/c/enc/cluster_inc.h`/ /* NOLINT(build/include) */ |
| 45 | #undef FNcxx . . $ `c/enc/cluster.c:43:9`! |
| 46 | |
| 47 | #define FNcxx . . $ `c/enc/cluster.c:47:9`!(X) X ## Distance |
| 48 | #include "cluster_inc.h"cxx . . $ `<file>/c/enc/cluster_inc.h`/ /* NOLINT(build/include) */ |
| 49 | #undef FNcxx . . $ `c/enc/cluster.c:47:9`! |
| 50 | |
| 51 | #undef CODEcxx . . $ `c/enc/cluster.c:37:9`! |
| 52 | |
| 53 | #if defined(__cplusplus) || defined(c_plusplus) |
| 54 | } /* extern "C" */ |
| 55 | #endif |