-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(trie): add sparse trie Display impl #14544
base: main
Are you sure you want to change the base?
Conversation
2f3046f
to
ccee058
Compare
crates/trie/sparse/src/trie.rs
Outdated
/// Turns a [`Nibbles`] into a [`String`] by converting each nibble to its hex representation. | ||
fn encode_nibbles(nibbles: &Nibbles) -> String { | ||
let mut output = String::with_capacity(nibbles.len().div_ceil(2)); | ||
for nibble in nibbles.as_slice() { | ||
let hex = format!("{nibble:01x}"); | ||
output.push_str(&hex); | ||
} | ||
output | ||
} |
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.
hmm won't this be confusing because 10
can be interpreted as both 0100
and a
maybe just do hex::encode(nibbles.pack())
?
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.
doing hex::encode(nibbles.pack())
incorrectly encodes paths with odd length (we get an extra 0
at the end). I'm also expecting paths to be interpreted as hex, so I'm not sure why 10
should be interpreted as a
?
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.
just pop the char at the end if len % 2 != 0, idk what you mean with the second sentence
fcc5538
to
f1b5b28
Compare
crates/trie/sparse/src/trie.rs
Outdated
let mut output = String::with_capacity(nibbles.len().div_ceil(2)); | ||
for nibble in nibbles.as_slice() { | ||
let hex = format!("{nibble:01x}"); | ||
output.push_str(&hex); |
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.
push(char::from_digit(*nibble as u32, 16).unwrap())
crates/trie/sparse/src/trie.rs
Outdated
/// Turns a [`Nibbles`] into a [`String`] by converting each nibble to its hex representation. | ||
fn encode_nibbles(nibbles: &Nibbles) -> String { | ||
let mut output = String::with_capacity(nibbles.len().div_ceil(2)); | ||
for nibble in nibbles.as_slice() { | ||
let hex = format!("{nibble:01x}"); | ||
output.push_str(&hex); | ||
} | ||
output | ||
} |
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.
just pop the char at the end if len % 2 != 0, idk what you mean with the second sentence
Co-authored-by: DaniPopes <[email protected]>
757b772
to
be68954
Compare
Adds a display impl and tests it, uses indents by level when printing alternate form