Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb04c03

Browse files
committed
Arithmetic{Compress,Decompress}.cpp: Simplified code to modify frequency table directly instead of temporary vector.
1 parent 343ea80 commit cb04c03

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

‎cpp/ArithmeticCompress.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ int main(int argc, char *argv[]) {
3636

3737
// Read input file once to compute symbol frequencies
3838
std::ifstream in(inputFile, std::ios::binary);
39-
std::vector<uint32_t> temp(256, 0);
40-
temp.push_back(1); // EOF symbol gets a frequency of 1
41-
SimpleFrequencyTable freqs(temp);
39+
SimpleFrequencyTable freqs(std::vector<uint32_t>(257, 0));
40+
freqs.increment(256); // EOF symbol gets a frequency of 1
4241
while (true) {
4342
int b = in.get();
4443
if (b == EOF)

‎cpp/ArithmeticDecompress.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ int main(int argc, char *argv[]) {
3838
BitInputStream bin(in);
3939
try {
4040

41-
std::vector<uint32_t> temp;
42-
for (int i = 0; i < 256; i++) {
41+
SimpleFrequencyTable freqs(std::vector<uint32_t>(257, 0));
42+
for (uint32_t i = 0; i < 256; i++) {
4343
uint32_t freq = 0;
4444
for (int j = 0; j < 32; j++)
4545
freq = (freq << 1) | bin.readNoEof(); // Big endian
46-
temp.push_back(freq);
46+
freqs.set(i, freq);
4747
}
48-
temp.push_back(1); // EOF symbol
49-
SimpleFrequencyTable freqs(temp);
48+
freqs.increment(256); // EOF symbol
5049

5150
ArithmeticDecoder dec(32, bin);
5251
while (true) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /