huffman_encode_utils.[hc],cosmetics: rm struct member '_' suffix

This is a follow up to:
ee8e8c62 Fix member naming for VP8LHistogram

This better matches Google style and clears some clang-tidy warnings.

Change-Id: Ice1edbbd98172a916be6b6d3cdaff80fe05a6e37
This commit is contained in:
James Zern 2025-04-14 12:33:54 -07:00
parent f0689e48cb
commit 1ed4654dc0
2 changed files with 24 additions and 24 deletions

View File

@ -122,24 +122,24 @@ static void OptimizeHuffmanForRle(int length, uint8_t* const good_for_rle,
static int CompareHuffmanTrees(const void* ptr1, const void* ptr2) { static int CompareHuffmanTrees(const void* ptr1, const void* ptr2) {
const HuffmanTree* const t1 = (const HuffmanTree*)ptr1; const HuffmanTree* const t1 = (const HuffmanTree*)ptr1;
const HuffmanTree* const t2 = (const HuffmanTree*)ptr2; const HuffmanTree* const t2 = (const HuffmanTree*)ptr2;
if (t1->total_count_ > t2->total_count_) { if (t1->total_count > t2->total_count) {
return -1; return -1;
} else if (t1->total_count_ < t2->total_count_) { } else if (t1->total_count < t2->total_count) {
return 1; return 1;
} else { } else {
assert(t1->value_ != t2->value_); assert(t1->value != t2->value);
return (t1->value_ < t2->value_) ? -1 : 1; return (t1->value < t2->value) ? -1 : 1;
} }
} }
static void SetBitDepths(const HuffmanTree* const tree, static void SetBitDepths(const HuffmanTree* const tree,
const HuffmanTree* const pool, const HuffmanTree* const pool,
uint8_t* const bit_depths, int level) { uint8_t* const bit_depths, int level) {
if (tree->pool_index_left_ >= 0) { if (tree->pool_index_left >= 0) {
SetBitDepths(&pool[tree->pool_index_left_], pool, bit_depths, level + 1); SetBitDepths(&pool[tree->pool_index_left], pool, bit_depths, level + 1);
SetBitDepths(&pool[tree->pool_index_right_], pool, bit_depths, level + 1); SetBitDepths(&pool[tree->pool_index_right], pool, bit_depths, level + 1);
} else { } else {
bit_depths[tree->value_] = level; bit_depths[tree->value] = level;
} }
} }
@ -198,10 +198,10 @@ static void GenerateOptimalTree(const uint32_t* const histogram,
if (histogram[j] != 0) { if (histogram[j] != 0) {
const uint32_t count = const uint32_t count =
(histogram[j] < count_min) ? count_min : histogram[j]; (histogram[j] < count_min) ? count_min : histogram[j];
tree[idx].total_count_ = count; tree[idx].total_count = count;
tree[idx].value_ = j; tree[idx].value = j;
tree[idx].pool_index_left_ = -1; tree[idx].pool_index_left = -1;
tree[idx].pool_index_right_ = -1; tree[idx].pool_index_right = -1;
++idx; ++idx;
} }
} }
@ -215,29 +215,29 @@ static void GenerateOptimalTree(const uint32_t* const histogram,
uint32_t count; uint32_t count;
tree_pool[tree_pool_size++] = tree[tree_size - 1]; tree_pool[tree_pool_size++] = tree[tree_size - 1];
tree_pool[tree_pool_size++] = tree[tree_size - 2]; tree_pool[tree_pool_size++] = tree[tree_size - 2];
count = tree_pool[tree_pool_size - 1].total_count_ + count = tree_pool[tree_pool_size - 1].total_count +
tree_pool[tree_pool_size - 2].total_count_; tree_pool[tree_pool_size - 2].total_count;
tree_size -= 2; tree_size -= 2;
{ {
// Search for the insertion point. // Search for the insertion point.
int k; int k;
for (k = 0; k < tree_size; ++k) { for (k = 0; k < tree_size; ++k) {
if (tree[k].total_count_ <= count) { if (tree[k].total_count <= count) {
break; break;
} }
} }
memmove(tree + (k + 1), tree + k, (tree_size - k) * sizeof(*tree)); memmove(tree + (k + 1), tree + k, (tree_size - k) * sizeof(*tree));
tree[k].total_count_ = count; tree[k].total_count = count;
tree[k].value_ = -1; tree[k].value = -1;
tree[k].pool_index_left_ = tree_pool_size - 1; tree[k].pool_index_left = tree_pool_size - 1;
tree[k].pool_index_right_ = tree_pool_size - 2; tree[k].pool_index_right = tree_pool_size - 2;
tree_size = tree_size + 1; tree_size = tree_size + 1;
} }
} }
SetBitDepths(&tree[0], tree_pool, bit_depths, 0); SetBitDepths(&tree[0], tree_pool, bit_depths, 0);
} else if (tree_size == 1) { // Trivial case: only one element. } else if (tree_size == 1) { // Trivial case: only one element.
bit_depths[tree[0].value_] = 1; bit_depths[tree[0].value] = 1;
} }
{ {

View File

@ -35,10 +35,10 @@ typedef struct {
// Struct to represent the Huffman tree. // Struct to represent the Huffman tree.
typedef struct { typedef struct {
uint32_t total_count_; // Symbol frequency. uint32_t total_count; // Symbol frequency.
int value_; // Symbol value. int value; // Symbol value.
int pool_index_left_; // Index for the left sub-tree. int pool_index_left; // Index for the left sub-tree.
int pool_index_right_; // Index for the right sub-tree. int pool_index_right; // Index for the right sub-tree.
} HuffmanTree; } HuffmanTree;
// Turn the Huffman tree into a token sequence. // Turn the Huffman tree into a token sequence.