-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add iter_u32_digits , iter_u64_digits, to_u64_digits to both BigInt and BigUint #158
Conversation
I'm wondering if adding |
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.
Hi, thanks for the PR, and sorry for the late review.
I'm wondering if adding
iter_u32_digits
/iter_u64_digits
toBigInt
is a good idea.
I think it's fine to keep API parity between BigInt
and BigUint
for most things.
Co-authored-by: Josh Stone <cuviper@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
Should |
I think it's OK that these methods return just the iterator, because that makes chaining easier, and |
I fixed the latest set of requested changes. |
Can you add
(I was going to just do it, but it seems your branch isn't open to maintainer pushes.) |
Done |
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.
One more bikesheddy thought -- maybe we should drop the iter_
/Iter
prefixes? e.g. u32_digits -> U32Digits
. I was considering the str
iterators for prior art with bytes() -> Bytes
and chars() -> Chars
, or the maps have keys -> Keys
, etc. I think it's uncommon to use iter
/Iter
in the names unless that's all there is to it (Iter
/IterMut
/IntoIter
).
@@ -2255,6 +2266,230 @@ pub(crate) fn to_str_radix_reversed(u: &BigUint, radix: u32) -> Vec<u8> { | |||
res | |||
} | |||
|
|||
/// An iterator of `u32` digits representation of the `BigUint` ordered least | |||
/// significant digit first. |
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 suggest:
/// An iterator of the `u32` digits representation of a `BigUint` or `BigInt`,
/// ordered least significant digit first.
Also, we should reexport this struct in the root, because this module is not public.
(Ditto for IterU64Digits
.)
impl ExactSizeIterator for IterU64Digits<'_> { | ||
#[inline] | ||
fn len(&self) -> usize { | ||
self.it.len() |
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: this is identical to the cfg(u64_digit)
version, so we could just have a unified version.
/// assert_eq!(BigUint::from(1125u32).to_u64_digits(), vec![1125]); | ||
/// assert_eq!(BigUint::from(4294967295u32).to_u64_digits(), vec![4294967295]); | ||
/// assert_eq!(BigUint::from(4294967296u64).to_u64_digits(), vec![4294967296]); | ||
/// assert_eq!(BigUint::from(112500000000u64).to_u64_digits(), vec![112500000000]); |
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.
We should add a multi-digit example, like BigUint::from(1u128 << 64)
.
(ditto for iter_u64_digits
, and the BigInt
counterparts.)
192: Add iter_u32_digits , iter_u64_digits, to_u64_digits to both BigInt and BigUint r=cuviper a=cuviper This is a rebase of #158, and I also addressed my last review comments there. I did rename the iterators to `U32Digits` and `U64Digits`, but I left the `iter_` prefix on the methods so they're not confused with the similar `to_` methods. Co-authored-by: Vincent Rouillé <vincent@speedy37.fr> Co-authored-by: Vincent Rouillé <v.rouille@clikengo.com> Co-authored-by: Vincent Rouillé <vincent@speedy37.fr> Co-authored-by: Josh Stone <cuviper@gmail.com>
Completed in #192. |
This adds:
iter_u32_digits
,iter_u64_digits
,to_u64_digits
to bothBigInt
andBigUint