Coverage Report

Created: 2026-02-09 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2o/deps/brotli/c/enc/bit_cost.h
Line
Count
Source
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 to estimate the bit cost of Huffman trees. */
8
9
#ifndef BROTLI_ENC_BIT_COST_H_
10
#define BROTLI_ENC_BIT_COST_H_
11
12
#include <brotli/types.h>
13
#include "./fast_log.h"
14
#include "./histogram.h"
15
#include "./port.h"
16
17
#if defined(__cplusplus) || defined(c_plusplus)
18
extern "C" {
19
#endif
20
21
static BROTLI_INLINE double ShannonEntropy(const uint32_t *population,
22
0
                                           size_t size, size_t *total) {
23
0
  size_t sum = 0;
24
0
  double retval = 0;
25
0
  const uint32_t *population_end = population + size;
26
0
  size_t p;
27
0
  if (size & 1) {
28
0
    goto odd_number_of_elements_left;
29
0
  }
30
0
  while (population < population_end) {
31
0
    p = *population++;
32
0
    sum += p;
33
0
    retval -= (double)p * FastLog2(p);
34
0
 odd_number_of_elements_left:
35
0
    p = *population++;
36
0
    sum += p;
37
0
    retval -= (double)p * FastLog2(p);
38
0
  }
39
0
  if (sum) retval += (double)sum * FastLog2(sum);
40
0
  *total = sum;
41
0
  return retval;
42
0
}
Unexecuted instantiation: bit_cost.c:ShannonEntropy
Unexecuted instantiation: block_splitter.c:ShannonEntropy
Unexecuted instantiation: cluster.c:ShannonEntropy
Unexecuted instantiation: compress_fragment_two_pass.c:ShannonEntropy
Unexecuted instantiation: encode.c:ShannonEntropy
Unexecuted instantiation: metablock.c:ShannonEntropy
43
44
static BROTLI_INLINE double BitsEntropy(
45
0
    const uint32_t *population, size_t size) {
46
0
  size_t sum;
47
0
  double retval = ShannonEntropy(population, size, &sum);
48
0
  if (retval < sum) {
49
    /* At least one bit per literal is needed. */
50
0
    retval = (double)sum;
51
0
  }
52
0
  return retval;
53
0
}
Unexecuted instantiation: bit_cost.c:BitsEntropy
Unexecuted instantiation: block_splitter.c:BitsEntropy
Unexecuted instantiation: cluster.c:BitsEntropy
Unexecuted instantiation: compress_fragment_two_pass.c:BitsEntropy
Unexecuted instantiation: encode.c:BitsEntropy
Unexecuted instantiation: metablock.c:BitsEntropy
54
55
BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*);
56
BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*);
57
BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*);
58
59
#if defined(__cplusplus) || defined(c_plusplus)
60
}  /* extern "C" */
61
#endif
62
63
#endif  /* BROTLI_ENC_BIT_COST_H_ */