aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-05-26 10:03:56 -0500
committerGitHub2020-05-26 10:03:56 -0500
commit85068258a8708361977dfe2cbc320492c0ec8b96 (patch)
tree667dfeb3453ab4eb70410ad989bda2b509dbd5c4
parent22749b2fc8d2547b8a9a1dd70a6be1068e80dd78 (diff)
Update huffman.cpp
-rw-r--r--src/huffman.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/huffman.cpp b/src/huffman.cpp
index 1644284..1992f1c 100644
--- a/src/huffman.cpp
+++ b/src/huffman.cpp
@@ -18,7 +18,7 @@ namespace huffman {
void encode_tree(node * n, vector<bool> & v) {
if (n->c) {
v.push_back(1);
- for (int i = 0; i < 8; ++i) v.push_back(1 & (n->c >> i));
+ for (int i = 0; i < 7; ++i) v.push_back(1 & (n->c >> i));
}
else {
v.push_back(0);
@@ -32,7 +32,7 @@ namespace huffman {
int idx = 0;
void decode_tree(node * n, vector<bool> & v) {
if (v[idx++] == 1) {
- for (int i = 0; i < 8; ++i) if (v[idx++]) n->c |= (1 << i);
+ for (int i = 0; i < 7; ++i) if (v[idx++]) n->c |= (1 << i);
}
else {
if (v[idx++] == 1) n->l = new node(0, 0), decode_tree(n->l, v);
@@ -42,7 +42,7 @@ namespace huffman {
void generate(vector<int> f) {
priority_queue<node *, vector<node *>, comp> pq;
- for (int c = 1; c < 128; ++c) {
+ for (int c = 1; c < 128; ++c) if (f[c]) {
node * n = new node(c, f[c]);
pq.push(n);
}
@@ -81,4 +81,4 @@ namespace huffman {
solve(root, v, ret);
return ret;
}
-} \ No newline at end of file
+}