comparison mupdf-source/thirdparty/brotli/c/enc/cluster.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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"
10
11 #include <brotli/types.h>
12
13 #include "../common/platform.h"
14 #include "bit_cost.h" /* BrotliPopulationCost */
15 #include "fast_log.h"
16 #include "histogram.h"
17 #include "memory.h"
18
19 #if defined(__cplusplus) || defined(c_plusplus)
20 extern "C" {
21 #endif
22
23 static BROTLI_INLINE BROTLI_BOOL HistogramPairIsLess(
24 const HistogramPair* p1, const HistogramPair* p2) {
25 if (p1->cost_diff != p2->cost_diff) {
26 return TO_BROTLI_BOOL(p1->cost_diff > p2->cost_diff);
27 }
28 return TO_BROTLI_BOOL((p1->idx2 - p1->idx1) > (p2->idx2 - p2->idx1));
29 }
30
31 /* Returns entropy reduction of the context map when we combine two clusters. */
32 static BROTLI_INLINE double ClusterCostDiff(size_t size_a, size_t size_b) {
33 size_t size_c = size_a + size_b;
34 return (double)size_a * FastLog2(size_a) +
35 (double)size_b * FastLog2(size_b) -
36 (double)size_c * FastLog2(size_c);
37 }
38
39 #define CODE(X) X
40
41 #define FN(X) X ## Literal
42 #include "cluster_inc.h" /* NOLINT(build/include) */
43 #undef FN
44
45 #define FN(X) X ## Command
46 #include "cluster_inc.h" /* NOLINT(build/include) */
47 #undef FN
48
49 #define FN(X) X ## Distance
50 #include "cluster_inc.h" /* NOLINT(build/include) */
51 #undef FN
52
53 #undef CODE
54
55 #if defined(__cplusplus) || defined(c_plusplus)
56 } /* extern "C" */
57 #endif