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

Use const generics to remove BitTree heap allocations #79

Merged
merged 1 commit into from
Mar 16, 2023

Commits on Nov 1, 2022

  1. Use const generics to remove BitTree heap allocations

    The single-argument that BitTree takes is 1 << NUM_BITS (2 ** NUM_BITS)
    for the number of bits required in the tree.
    
    This is due to restrictions on const generic expressions.
    The validity of this argument is checked at compile-time with a macro
    that confirms that the argument P passed is indeed 1 << N for
    some N using usize::trailing_zeros to calculate floor(log_2(P)).
    
    Thus, BitTree<const P: usize> is only valid for any P such that
    P = 2 ** floor(log_2(P)), where P is the length of the probability array
    of the BitTree. This maintains the invariant that P = 1 << N.
    chyyran committed Nov 1, 2022
    Configuration menu
    Copy the full SHA
    571be60 View commit details
    Browse the repository at this point in the history