/* Greedy block splitter for one block category (literal, command or distance).
*/ typedefstruct FN(BlockSplitter) { /* Alphabet size of particular block category. */
size_t alphabet_size_; /* We collect at least this many symbols for each block. */
size_t min_block_size_; /* We merge histograms A and B if entropy(A+B)<entropy(A)+entropy(B)+split_threshold_, whereAisthecurrenthistogramandBisthehistogramofthelastorthe
second last block type. */ double split_threshold_;
size_t num_blocks_;
BlockSplit* split_; /* not owned */
HistogramType* histograms_; /* not owned */
size_t* histograms_size_; /* not owned */
/* Temporary storage for BlockSplitterFinishBlock. */
HistogramType combined_histo[2];
/* The number of symbols that we want to collect before deciding on whether
or not to merge the block with a previous one or emit a new block. */
size_t target_block_size_; /* The number of symbols in the current histogram. */
size_t block_size_; /* Offset of the current histogram. */
size_t curr_histogram_ix_; /* Offset of the histograms of the previous two block types. */
size_t last_histogram_ix_[2]; /* Entropy of the previous two block types. */ double last_entropy_[2]; /* The number of times we merged the current block with the last one. */
size_t merge_last_count_;
} FN(BlockSplitter);
staticvoid FN(InitBlockSplitter)(
MemoryManager* m, FN(BlockSplitter)* self, size_t alphabet_size,
size_t min_block_size, double split_threshold, size_t num_symbols,
BlockSplit* split, HistogramType** histograms, size_t* histograms_size) {
size_t max_num_blocks = num_symbols / min_block_size + 1; /* We have to allocate one more histogram than the maximum number of block
types for the current histogram when the meta-block is too big. */
size_t max_num_types =
BROTLI_MIN(size_t, max_num_blocks, BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + 1);
self->alphabet_size_ = alphabet_size;
self->min_block_size_ = min_block_size;
self->split_threshold_ = split_threshold;
self->num_blocks_ = 0;
self->split_ = split;
self->histograms_size_ = histograms_size;
self->target_block_size_ = min_block_size;
self->block_size_ = 0;
self->curr_histogram_ix_ = 0;
self->merge_last_count_ = 0;
BROTLI_ENSURE_CAPACITY(m, uint8_t,
split->types, split->types_alloc_size, max_num_blocks);
BROTLI_ENSURE_CAPACITY(m, uint32_t,
split->lengths, split->lengths_alloc_size, max_num_blocks); if (BROTLI_IS_OOM(m)) return;
self->split_->num_blocks = max_num_blocks;
BROTLI_DCHECK(*histograms == 0);
*histograms_size = max_num_types;
*histograms = BROTLI_ALLOC(m, HistogramType, *histograms_size);
self->histograms_ = *histograms; if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(*histograms)) return; /* Clear only current histogram. */
FN(HistogramClear)(&self->histograms_[0]);
self->last_histogram_ix_[0] = self->last_histogram_ix_[1] = 0;
}
/* Does either of three things: (1)emitsthecurrentblockwithanewblocktype; (2)emitsthecurrentblockwiththetypeofthesecondlastblock;
(3) merges the current block with the last block. */ staticvoid FN(BlockSplitterFinishBlock)(
FN(BlockSplitter)* self, BROTLI_BOOL is_final) {
BlockSplit* split = self->split_; double* last_entropy = self->last_entropy_;
HistogramType* histograms = self->histograms_;
self->block_size_ =
BROTLI_MAX(size_t, self->block_size_, self->min_block_size_); if (self->num_blocks_ == 0) { /* Create first block. */
split->lengths[0] = (uint32_t)self->block_size_;
split->types[0] = 0;
last_entropy[0] =
BrotliBitsEntropy(histograms[0].data_, self->alphabet_size_);
last_entropy[1] = last_entropy[0];
++self->num_blocks_;
++split->num_types;
++self->curr_histogram_ix_; if (self->curr_histogram_ix_ < *self->histograms_size_)
FN(HistogramClear)(&histograms[self->curr_histogram_ix_]);
self->block_size_ = 0;
} elseif (self->block_size_ > 0) { double entropy = BrotliBitsEntropy(
histograms[self->curr_histogram_ix_].data_, self->alphabet_size_); double combined_entropy[2]; double diff[2];
size_t j; for (j = 0; j < 2; ++j) {
size_t last_histogram_ix = self->last_histogram_ix_[j];
self->combined_histo[j] = histograms[self->curr_histogram_ix_];
FN(HistogramAddHistogram)(&self->combined_histo[j],
&histograms[last_histogram_ix]);
combined_entropy[j] = BrotliBitsEntropy(
&self->combined_histo[j].data_[0], self->alphabet_size_);
diff[j] = combined_entropy[j] - entropy - last_entropy[j];
}
/* Adds the next symbol to the current histogram. When the current histogram
reaches the target size, decides on merging the block. */ staticvoid FN(BlockSplitterAddSymbol)(FN(BlockSplitter)* self, size_t symbol) {
FN(HistogramAdd)(&self->histograms_[self->curr_histogram_ix_], symbol);
++self->block_size_; if (self->block_size_ == self->target_block_size_) {
FN(BlockSplitterFinishBlock)(self, /* is_final = */ BROTLI_FALSE);
}
}
#undef HistogramType
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.