mirror of
https://github.com/google/brotli.git
synced 2024-11-28 22:21:05 +00:00
35e69fc7cf
* New feature: "Large Window Brotli" By setting special encoder/decoder flag it is now possible to extend LZ-window up to 30 bits; though produced stream will not be RFC7932 compliant. Added new dictionary generator - "DSH". It combines speed of "Sieve" and quality of "DM". Plus utilities to prepare train corpora (remove unique strings). Improved compression ratio: now two sub-blocks could be stitched: the last copy command could be extended to span the next sub-block. Fixed compression ineffectiveness caused by floating numbers rounding and wrong cost heuristic. Other C changes: - combined / moved `context.h` to `common` - moved transforms to `common` - unified some aspects of code formatting - added an abstraction for encoder (static) dictionary - moved default allocator/deallocator functions to `common` brotli CLI: - window size is auto-adjusted if not specified explicitly Java: - added "eager" decoding both to JNI wrapper and pure decoder - huge speed-up of `DictionaryData` initialization * Add dictionaryless compressed dictionary * Fix `sources.lst` * Fix `sources.lst` and add a note that `libtool` is also required. * Update setup.py * Fix `EagerStreamTest` * Fix BUILD file * Add missing `libdivsufsort` dependency * Fix "unused parameter" warning.
64 lines
1.6 KiB
C
64 lines
1.6 KiB
C
/* Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
Distributed under MIT license.
|
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
/* Functions to estimate the bit cost of Huffman trees. */
|
|
|
|
#ifndef BROTLI_ENC_BIT_COST_H_
|
|
#define BROTLI_ENC_BIT_COST_H_
|
|
|
|
#include "../common/platform.h"
|
|
#include <brotli/types.h>
|
|
#include "./fast_log.h"
|
|
#include "./histogram.h"
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
static BROTLI_INLINE double ShannonEntropy(
|
|
const uint32_t* population, size_t size, size_t* total) {
|
|
size_t sum = 0;
|
|
double retval = 0;
|
|
const uint32_t* population_end = population + size;
|
|
size_t p;
|
|
if (size & 1) {
|
|
goto odd_number_of_elements_left;
|
|
}
|
|
while (population < population_end) {
|
|
p = *population++;
|
|
sum += p;
|
|
retval -= (double)p * FastLog2(p);
|
|
odd_number_of_elements_left:
|
|
p = *population++;
|
|
sum += p;
|
|
retval -= (double)p * FastLog2(p);
|
|
}
|
|
if (sum) retval += (double)sum * FastLog2(sum);
|
|
*total = sum;
|
|
return retval;
|
|
}
|
|
|
|
static BROTLI_INLINE double BitsEntropy(
|
|
const uint32_t* population, size_t size) {
|
|
size_t sum;
|
|
double retval = ShannonEntropy(population, size, &sum);
|
|
if (retval < sum) {
|
|
/* At least one bit per literal is needed. */
|
|
retval = (double)sum;
|
|
}
|
|
return retval;
|
|
}
|
|
|
|
BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*);
|
|
BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*);
|
|
BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*);
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* BROTLI_ENC_BIT_COST_H_ */
|