Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-07-04 12:48:25 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2017-07-04 14:09:45 +0300
commitda19077d3b927d26b197e9f09fe161c795cbe7e4 (patch)
treebdf77f090725a44f2dfe357c22637492a8c2fbef /coding/huffman.cpp
parentf8aeb3711100c875e718b952d8a42442030d02af (diff)
Review fixes.
Diffstat (limited to 'coding/huffman.cpp')
-rw-r--r--coding/huffman.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/coding/huffman.cpp b/coding/huffman.cpp
index 83d60039a3..aa92e8ad49 100644
--- a/coding/huffman.cpp
+++ b/coding/huffman.cpp
@@ -61,12 +61,6 @@ void HuffmanCoder::DeleteHuffmanTree(Node * root)
void HuffmanCoder::BuildHuffmanTree(Freqs const & freqs)
{
- // One would need more than 2^32 symbols to build a code that long.
- // On the other hand, 32 is short enough for our purposes, so do not
- // try to shrink the trees beyond this threshold.
-
- uint32_t const kMaxDepth = 32;
-
priority_queue<Node *, vector<Node *>, NodeComparator> pq;
for (auto const & e : freqs.GetTable())
pq.push(new Node(e.first, e.second, true /* isLeaf */));
@@ -89,24 +83,27 @@ void HuffmanCoder::BuildHuffmanTree(Freqs const & freqs)
auto ab = new Node(a->symbol, a->freq + b->freq, false /* isLeaf */);
ab->l = a;
ab->r = b;
- CHECK_LESS_OR_EQUAL(a->depth, kMaxDepth, ());
- CHECK_LESS_OR_EQUAL(b->depth, kMaxDepth, ());
pq.push(ab);
}
m_root = pq.top();
pq.pop();
- SetDepths(m_root, 0);
+ SetDepths(m_root, 0 /* depth */);
}
void HuffmanCoder::SetDepths(Node * root, uint32_t depth)
{
+ // One would need more than 2^32 symbols to build a code that long.
+ // On the other hand, 32 is short enough for our purposes, so do not
+ // try to shrink the trees beyond this threshold.
+ uint32_t const kMaxDepth = 32;
+
if (!root)
return;
+ CHECK_LESS_OR_EQUAL(depth, kMaxDepth, ());
root->depth = depth;
SetDepths(root->l, depth + 1);
SetDepths(root->r, depth + 1);
}
-
} // namespace coding