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