Exemplo n.º 1
0
 /* Adds the next symbol to the current histogram. When the current histogram
  * reaches the target size, decides on merging the block. */
 public static unsafe void BlockSplitterAddSymbol(BlockSplitterDistance *self, size_t symbol)
 {
     HistogramDistance.HistogramAdd(&self->histograms_[self->curr_histogram_ix_], symbol);
     ++self->block_size_;
     if (self->block_size_ == self->target_block_size_)
     {
         BlockSplitterFinishBlock(self, /* is_final = */ false);
     }
 }
Exemplo n.º 2
0
        private static unsafe void BrotliBuildHistogramsWithContext(
            Command *cmds, size_t num_commands,
            BlockSplit *literal_split, BlockSplit *insert_and_copy_split,
            BlockSplit *dist_split, byte *ringbuffer, size_t start_pos,
            size_t mask, byte prev_byte, byte prev_byte2,
            ContextType *context_modes, HistogramLiteral *literal_histograms,
            HistogramCommand *insert_and_copy_histograms,
            HistogramDistance *copy_dist_histograms)
        {
            size_t             pos = start_pos;
            BlockSplitIterator literal_it;
            BlockSplitIterator insert_and_copy_it;
            BlockSplitIterator dist_it;
            size_t             i;

            InitBlockSplitIterator(&literal_it, literal_split);
            InitBlockSplitIterator(&insert_and_copy_it, insert_and_copy_split);
            InitBlockSplitIterator(&dist_it, dist_split);
            for (i = 0; i < num_commands; ++i)
            {
                Command *cmd = &cmds[i];
                size_t   j;
                BlockSplitIteratorNext(&insert_and_copy_it);
                HistogramCommand.HistogramAdd(&insert_and_copy_histograms[insert_and_copy_it.type_],
                                              cmd->cmd_prefix_);
                for (j = cmd->insert_len_; j != 0; --j)
                {
                    size_t context;
                    BlockSplitIteratorNext(&literal_it);
                    context = context_modes != null ?
                              ((literal_it.type_ << BROTLI_LITERAL_CONTEXT_BITS) +
                               Context(prev_byte, prev_byte2, context_modes[literal_it.type_])) :
                              literal_it.type_;
                    HistogramLiteral.HistogramAdd(&literal_histograms[context],
                                                  ringbuffer[pos & mask]);
                    prev_byte2 = prev_byte;
                    prev_byte  = ringbuffer[pos & mask];
                    ++pos;
                }
                pos += CommandCopyLen(cmd);
                if (CommandCopyLen(cmd) != 0)
                {
                    prev_byte2 = ringbuffer[(pos - 2) & mask];
                    prev_byte  = ringbuffer[(pos - 1) & mask];
                    if (cmd->cmd_prefix_ >= 128)
                    {
                        size_t context;
                        BlockSplitIteratorNext(&dist_it);
                        context = (dist_it.type_ << BROTLI_DISTANCE_CONTEXT_BITS) +
                                  CommandDistanceContext(cmd);
                        HistogramDistance.HistogramAdd(&copy_dist_histograms[context],
                                                       cmd->dist_prefix_);
                    }
                }
            }
        }