Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in NormalizeCount() #1

Open
richgel999 opened this issue Jan 6, 2022 · 0 comments
Open

bug in NormalizeCount() #1

richgel999 opened this issue Jan 6, 2022 · 0 comments

Comments

@richgel999
Copy link

Hi,

freqs[argmax] can be decremented below zero, causing encoding to fail. Here's one way to fix that:

 // A symbol must have freq at least 1
        for (int i = 0; i < num_symbols; i++) {
            if (freqs[i] == 0) {
                freqs[i] = 1;
                
                freqs[argmax]--;

                assert(freqs[argmax] >= 1);
                
                argmax = (int)std::distance(freqs.begin(), std::max_element(freqs.begin(), freqs.end()));
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant