-
Notifications
You must be signed in to change notification settings - Fork 38
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
Getting started on Huffman tables #441
Conversation
5781f2a
to
65b6bd8
Compare
65b6bd8
to
525603e
Compare
use std::rc::Rc; | ||
|
||
/// A newtype for `u8` used to count the length of a key in bits. | ||
#[derive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long list. Is there a convenient bag of traits which imply all of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's verbose, but I don't know of any such trait.
There used to be something called "int-like", I believe, in another crate, but that crate is now deprecated. I could write a macro, though.
// Convert tree into bit lengths | ||
let root = heap.pop().unwrap(); // We have checked above that there is at least one value. | ||
let mut bit_lengths = Vec::with_capacity(len); | ||
fn aux<T>(bit_lengths: &mut Vec<(T, BitLen)>, depth: u8, node: NodeContent<T>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth putting a FIXME/TODO and an assert here that the length generated is not >20 bits, since this is the earliest you can detect length limits are going to be violated and the code you'll have to change to do limits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the idea was to not make the 20 bits part of the spec?
Did I misunderstand #440 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a mechanism to check that we do not exceed a maximal length.
b2de953
to
8289734
Compare
20 bits is part of the spec; how you compute the number 0 ≤ x ≤ 20 is an
implementation detail.
…On Fri, Sep 13, 2019, 6:38 PM David Teller ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/binjs_io/src/context/huffman.rs
<#441 (comment)>:
> + // Take the two rarest nodes, merge them behind a prefix,
+ // turn them into a single node with combined number of
+ // instances. Repeat.
+ while heap.len() > 1 {
+ let left = heap.pop().unwrap();
+ let right = heap.pop().unwrap();
+ heap.push(Reverse(Node {
+ instances: left.0.instances + right.0.instances,
+ content: NodeContent::Internal(Rc::new((left.0.content, right.0.content))),
+ }));
+ }
+
+ // Convert tree into bit lengths
+ let root = heap.pop().unwrap(); // We have checked above that there is at least one value.
+ let mut bit_lengths = Vec::with_capacity(len);
+ fn aux<T>(bit_lengths: &mut Vec<(T, BitLen)>, depth: u8, node: NodeContent<T>) {
I thought the idea was to not make the 20 bits part of the spec?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#441?email_source=notifications&email_token=AAANOUDJT4VCG6XUPCX4QKDQJNNQDA5CNFSM4IVS5T2KYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCEUSZAY#discussion_r324113159>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAANOUE7DOCLSQ7LGXIN2YLQJNNQDANCNFSM4IVS5T2A>
.
|
8289734
to
0d900c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, one nit inline.
@@ -113,11 +112,20 @@ where | |||
{ | |||
/// Compute a `Keys` from a sequence of values. | |||
/// | |||
/// Optionally, `max_bit_len` may specify a largest acceptable bit length. | |||
/// If `Keys` may not be computed without exceeding this bit length, | |||
/// fail with `Err(problemantic_bit_length)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: problematic
No description provided.