Add the initial version of the static dictionary and transforms to Brotli.

This commit is contained in:
Zoltan Szabadka
2014-02-17 14:25:36 +01:00
parent cbd5cb55f4
commit 2733d6c0c2
9 changed files with 12645 additions and 30 deletions
+18
View File
@@ -24,6 +24,7 @@
#include "./block_splitter.h"
#include "./cluster.h"
#include "./context.h"
#include "./transform.h"
#include "./entropy_encode.h"
#include "./fast_log.h"
#include "./hash.h"
@@ -858,6 +859,7 @@ BrotliCompressor::BrotliCompressor()
dist_ringbuffer_[2] = 11;
dist_ringbuffer_[3] = 4;
storage_[0] = 0;
StoreDictionaryWordHashes();
}
BrotliCompressor::~BrotliCompressor() {
@@ -865,6 +867,22 @@ BrotliCompressor::~BrotliCompressor() {
delete[] storage_;
}
void BrotliCompressor::StoreDictionaryWordHashes() {
for (int t = kNumTransforms - 1; t >= 0; --t) {
for (int i = kMaxDictionaryWordLength; i >= 3; --i) {
const int num_words = 1 << kBrotliDictionarySizeBitsByLength[i];
for (int j = num_words - 1; j >= 0; --j) {
int word_id = t * num_words + j;
std::string word = GetTransformedDictionaryWord(i, word_id);
if (word.size() >= 3) {
hasher_->Store(reinterpret_cast<const uint8_t*>(&word[0]),
(-1) * ((i << 20) + word_id + 1));
}
}
}
}
}
void BrotliCompressor::WriteStreamHeader() {
// Encode window size.
if (window_bits_ == 16) {