+
+ // Generate the lookup tables
+ for (unsigned i = 0; i < DEHUF_TABLE_SIZE; ++i) {
+ tbl->lookup_table_codes[i] = DEHUF_SLOW_PATH;
+ tbl->lookup_table_length[i] = DEHUF_SLOW_PATH;
+ }
+
+ unsigned k = 0;
+ for (unsigned i = 0; i < 16; ++i) {
+ for (unsigned j = 0; j < tbl->num_codes[i]; ++j, ++k) {
+ const unsigned code = tbl->huffcode[k];
+ const unsigned length = tbl->huffsize[k];
+ if (length > DEHUF_TABLE_BITS) {
+ continue;
+ }
+ const unsigned prefix_min = code << (DEHUF_TABLE_BITS - length);
+ const unsigned prefix_max = ((code + 1) << (DEHUF_TABLE_BITS - length));
+
+ for (unsigned elem = prefix_min; elem < prefix_max; ++elem) {
+ assert(tbl->lookup_table_codes[elem] == DEHUF_SLOW_PATH);
+ assert(tbl->lookup_table_length[elem] == DEHUF_SLOW_PATH);
+ tbl->lookup_table_codes[elem] = k;
+ tbl->lookup_table_length[elem] = length;
+ }
+ }
+ }